<commit_before>'use babel'

/* @flow */

import Path from 'path'
import type { Message, MessageLegacy } from '../types'

export function getChunks(filePath: string, projectPath: string): Array<string> {
  const toReturn = []
  const chunks = filePath.split(Path.sep)
  while (chunks.length) {
    const currentPath = chunks.join(Path.sep)
    toReturn.push(currentPath)
    if (currentPath === projectPath) {
      break
    }
    chunks.pop()
  }
  return toReturn
}

export function getChunksByProjects(filePath: string, projectPaths: Array<string>): Array<string> {
  if (projectPaths.length < 3) {
    if (filePath.indexOf(projectPaths[0]) === 0) {
      return getChunks(filePath, projectPaths[0])
    }
    if (filePath.indexOf(projectPaths[1]) === 0) {
      return getChunks(filePath, projectPaths[1])
    }
    if (filePath.indexOf(projectPaths[2]) === 0) {
      return getChunks(filePath, projectPaths[2])
    }
    return [filePath]
  }
  for (let i = 0, length = projectPaths.length, projectPath; i < length; ++i) {
    projectPath = projectPaths[i]
    if (filePath.indexOf(projectPath) === 0) {
      return getChunks(filePath, projectPath)
    }
  }
  return [filePath]
}

export function mergeChange(change: Object, filePath: string, severity: string): void {
  if (!change[filePath]) {
    change[filePath] = new Set()
  }
  change[filePath].add(severity)
}

export function calculateDecorations(decorateOnTreeView: 'Files and Directories' | 'Files', messages: Array<Message | MessageLegacy>): Object {
  const toReturn = {}
  const projectPaths: Array<string> = atom.project.getPaths()
  for (let i = 0, length = messages.length, message; i < length; ++i) {
    message = messages[i]
    const filePath = message.version === 1 ? message.filePath : message.location.file
    if (!filePath) {
      // For compatibility purpose only
      continue
    }
    const chunks = decorateOnTreeView === 'Files' ? [filePath] : getChunksByProjects(filePath, projectPaths)
    if (chunks.length > 0) {
      mergeChange(toReturn, chunks[0], message.severity)
    }
    if (chunks.length > 1) {
      mergeChange(toReturn, chunks[1], message.severity)
    }
    if (chunks.length > 2) {
      mergeChange(toReturn, chunks[2], message.severity)
    }
    if (chunks.length > 3) {
      mergeChange(toReturn, chunks[3], message.severity)
    }
    if (chunks.length === 4) {
      continue
    }
    for (let _i = 4, _length = chunks.length, _filePath; _i < _length; ++i) {
      _filePath = chunks[_i]
      mergeChange(toReturn, _filePath, message.severity)
    }
  }
  for (const filePath in toReturn) {
    if (!toReturn.hasOwnProperty(filePath)) {
      continue
    }
    toReturn[filePath] = Array.from(toReturn[filePath])
  }
  return toReturn
}<commit_msg>:bug: Fix a critical typo<commit_after>'use babel'

/* @flow */

import Path from 'path'
import type { Message, MessageLegacy } from '../types'

export function getChunks(filePath: string, projectPath: string): Array<string> {
  const toReturn = []
  const chunks = filePath.split(Path.sep)
  while (chunks.length) {
    const currentPath = chunks.join(Path.sep)
    toReturn.push(currentPath)
    if (currentPath === projectPath) {
      break
    }
    chunks.pop()
  }
  return toReturn
}

export function getChunksByProjects(filePath: string, projectPaths: Array<string>): Array<string> {
  if (projectPaths.length < 3) {
    if (filePath.indexOf(projectPaths[0]) === 0) {
      return getChunks(filePath, projectPaths[0])
    }
    if (filePath.indexOf(projectPaths[1]) === 0) {
      return getChunks(filePath, projectPaths[1])
    }
    if (filePath.indexOf(projectPaths[2]) === 0) {
      return getChunks(filePath, projectPaths[2])
    }
    return [filePath]
  }
  for (let i = 0, length = projectPaths.length, projectPath; i < length; ++i) {
    projectPath = projectPaths[i]
    if (filePath.indexOf(projectPath) === 0) {
      return getChunks(filePath, projectPath)
    }
  }
  return [filePath]
}

export function mergeChange(change: Object, filePath: string, severity: string): void {
  if (!change[filePath]) {
    change[filePath] = new Set()
  }
  change[filePath].add(severity)
}

export function calculateDecorations(decorateOnTreeView: 'Files and Directories' | 'Files', messages: Array<Message | MessageLegacy>): Object {
  const toReturn = {}
  const projectPaths: Array<string> = atom.project.getPaths()
  for (let i = 0, length = messages.length, message; i < length; ++i) {
    message = messages[i]
    const filePath = message.version === 1 ? message.filePath : message.location.file
    if (!filePath) {
      // For compatibility purpose only
      continue
    }
    const chunks = decorateOnTreeView === 'Files' ? [filePath] : getChunksByProjects(filePath, projectPaths)
    if (chunks.length > 0) {
      mergeChange(toReturn, chunks[0], message.severity)
    }
    if (chunks.length > 1) {
      mergeChange(toReturn, chunks[1], message.severity)
    }
    if (chunks.length > 2) {
      mergeChange(toReturn, chunks[2], message.severity)
    }
    if (chunks.length > 3) {
      mergeChange(toReturn, chunks[3], message.severity)
    }
    if (chunks.length === 4) {
      continue
    }
    for (let _i = 4, _length = chunks.length, _filePath; _i < _length; ++_i) {
      _filePath = chunks[_i]
      mergeChange(toReturn, _filePath, message.severity)
    }
  }
  for (const filePath in toReturn) {
    if (!toReturn.hasOwnProperty(filePath)) {
      continue
    }
    toReturn[filePath] = Array.from(toReturn[filePath])
  }
  return toReturn
}
{'fraction_non_alphanumeric': 0.13258872275265718, 'fraction_numerical': 0.008647090614303729, 'mean_word_length': 3.459437751004016, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5290953', 'n_tokens_mistral': 1838, 'n_tokens_neox': 1798, 'n_words': 418}