<commit_before>const path = require("path")
const fs = require("fs-plus")

const FILENAME_WITH_LOCATION_REGEX = /[-\w/\.]+(:\d+){0,2}/g

function hasCommonJSPackageSemantics(scopeName) {
  // why use `startsWith` is to make `source.js.jsx` true.
  return scopeName.startsWith("source.js") || scopeName.startsWith("source.coffee")
}

function getBaseName(file) {
  return path.basename(file, path.extname(file))
}

function getExtensionsForScope(scopeName) {
  const grammar = atom.grammars.grammarForScopeName(scopeName)
  return grammar.fileTypes || []
}

function uniq(list) {
  return list.reduce((acc, cur) => (acc.indexOf(cur) === -1 ? acc.concat(cur) : acc), [])
}

module.exports = {
  activate(state) {
    this.disposable = atom.commands.add("atom-text-editor", {
      "open-this:here": () => this.open(),
      "open-this:split-down": () => this.open({split: "down"}),
      "open-this:split-right": () => this.open({split: "right"}),
    })
  },

  deactivate() {
    this.disposable.dispose()
  },

  getFiles(file) {
    let extensions = []
    const editor = atom.workspace.getActiveTextEditor()

    const extname = path.extname(editor.getURI())
    if (extname) extensions.push(extname.substr(1))

    extensions.push(...getExtensionsForScope(editor.getGrammar().scopeName))
    const files = extensions.map(ext => `${file}.${ext}`)
    return uniq([...files, file])
  },

  // Return first existing filePath in following order.
  //  - File with same extension to current file's
  //  - File with extensions... from current Grammar.fileTypes
  //  - File have same basename
  detectFilePath(filePath) {
    // Search existing file from file list.
    const file = this.getFiles(filePath).find(f => fs.isFileSync(f))
    if (file) return file

    // Search file have same basename.
    const baseName = getBaseName(filePath)
    return fs.listSync(path.dirname(filePath)).find(f => getBaseName(f) === baseName && fs.isFileSync(f))
  },

  getFilePath(editor, fileName) {
    const dirName = path.dirname(editor.getURI())
    const {scopeName} = editor.getGrammar()

    const baseFilePath = path.resolve(dirName, fileName)
    if (fs.isDirectorySync(baseFilePath) && hasCommonJSPackageSemantics(scopeName)) {
      const extensions = [".js", ".coffee", ".jsx"]
      const indexFilePath = extensions
        .map(ext => path.join(baseFilePath, `index${ext}`))
        .find(indexFilePath => fs.isFileSync(indexFilePath))
      if (indexFilePath) return indexFilePath
    }
<commit_msg>getExtensionsForScope was necessary in old days but no longer<commit_after>const path = require("path")
const fs = require("fs-plus")

const FILENAME_WITH_LOCATION_REGEX = /[-\w/\.]+(:\d+){0,2}/g

function hasCommonJSPackageSemantics(scopeName) {
  // why use `startsWith` is to make `source.js.jsx` true.
  return scopeName.startsWith("source.js") || scopeName.startsWith("source.coffee")
}

function getBaseName(file) {
  return path.basename(file, path.extname(file))
}

function uniq(list) {
  return list.reduce((acc, cur) => (acc.indexOf(cur) === -1 ? acc.concat(cur) : acc), [])
}

module.exports = {
  activate(state) {
    this.disposable = atom.commands.add("atom-text-editor", {
      "open-this:here": () => this.open(),
      "open-this:split-down": () => this.open({split: "down"}),
      "open-this:split-right": () => this.open({split: "right"}),
    })
  },

  deactivate() {
    this.disposable.dispose()
  },

  getFiles(file) {
    let extensions = []
    const editor = atom.workspace.getActiveTextEditor()

    const extname = path.extname(editor.getURI())
    if (extname) extensions.push(extname.substr(1))

    extensions.push(...editor.getGrammar().fileTypes)
    const files = extensions.map(ext => `${file}.${ext}`)
    return uniq([...files, file])
  },

  // Return first existing filePath in following order.
  //  - File with same extension to current file's
  //  - File with extensions... from current Grammar.fileTypes
  //  - File have same basename
  detectFilePath(filePath) {
    // Search existing file from file list.
    const file = this.getFiles(filePath).find(f => fs.isFileSync(f))
    if (file) return file

    // Search file have same basename.
    const baseName = getBaseName(filePath)
    return fs.listSync(path.dirname(filePath)).find(f => getBaseName(f) === baseName && fs.isFileSync(f))
  },

  getFilePath(editor, fileName) {
    const dirName = path.dirname(editor.getURI())
    const {scopeName} = editor.getGrammar()

    const baseFilePath = path.resolve(dirName, fileName)
    if (fs.isDirectorySync(baseFilePath) && hasCommonJSPackageSemantics(scopeName)) {
      const extensions = [".js", ".coffee", ".jsx"]
      const indexFilePath = extensions
        .map(ext => path.join(baseFilePath, `index${ext}`))
        .find(indexFilePath => fs.isFileSync(indexFilePath))
      if (indexFilePath) return indexFilePath
    }

{'fraction_non_alphanumeric': 0.15875613747954173, 'fraction_numerical': 0.0016366612111292963, 'mean_word_length': 3.7054860442733397, 'pattern_counts': {'":': 6, '<': 3, '<?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': '4955478', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1563, 'n_words': 323}