<commit_before>'use babel'

/* @flow */

import FS from 'fs'
import {spawn} from 'child_process'
import promisify from 'sb-promisify'
import debounce from 'sb-debounce'
import type {Grammar} from 'atom'

export const readFile = promisify(FS.readFile)
export const realPath = promisify(FS.realpath)
export function fileExists(filePath: string): Promise<boolean> {
  return new Promise(function(resolve) {
    // $FlowIgnore: Flow doesn't recognize FS.R_OK
    FS.access(filePath, FS.R_OK, function(error) {
      resolve(error === null)
    })
  })
}

export function ensureUninstalled(name: string) {
  if (atom.packages.isPackageLoaded(name)) {
    atom.packages.deactivatePackage(name)

    const apm = atom.packages.getApmPath()
    spawn(apm, ['uninstall', '--hard', name])
    atom.notifications.addSuccess('[Flint] Automatic package removal', {detail: `The package ${name} was no longer required and has been removed automatically`})
  }
}

export function getGrammarByName(scopeName: string): ?Grammar {
  const grammars = atom.grammars.getGrammars()
  for (const grammar of grammars) {
    if (grammar.scopeName === scopeName) {
      return grammar
    }
  }
  return null
}

export function showError(message, detail = null) {
  if (message instanceof Error) {
    detail = message.stack
    message = message.message
  }
  atom.notifications.addError(`[Flint] ${message}`, {
    detail: detail,
    dismissable: true
  })
}<commit_msg>:art: Minor fixes for helpers<commit_after>'use babel'

/* @flow */

import FS from 'fs'
import {spawn} from 'child_process'
import promisify from 'sb-promisify'
import debounce from 'sb-debounce'
import type {Grammar} from 'atom'

export const readFile = promisify(FS.readFile)
export const realPath = promisify(FS.realpath)
export function exists(filePath: string): Promise<boolean> {
  return new Promise(function(resolve) {
    // $FlowIgnore: Flow doesn't recognize FS.R_OK
    FS.access(filePath, FS.R_OK, function(error) {
      resolve(error === null)
    })
  })
}

export function ensureUninstalled(name: string) {
  if (atom.packages.isPackageLoaded(name)) {
    atom.packages.deactivatePackage(name)

    const apm = atom.packages.getApmPath()
    spawn(apm, ['uninstall', '--hard', name])
    atom.notifications.addSuccess('[Flint] Automatic package removal', {detail: `The package ${name} was no longer required and has been removed automatically`})
  }
}

export function getGrammarByName(scopeName: string): ?Grammar {
  const grammars = atom.grammars.getGrammars()
  for (const grammar of grammars) {
    if (grammar.scopeName === scopeName) {
      return grammar
    }
  }
  return null
}

export function showError(message: string | Error, detail: ?string = null) {
  if (message instanceof Error) {
    detail = message.stack
    message = message.message
  }
  atom.notifications.addError(`[Flint] ${message}`, {
    detail: detail,
    dismissable: true
  })
}
{'fraction_non_alphanumeric': 0.12222601570501877, 'fraction_numerical': 0.0, 'mean_word_length': 4.222816399286987, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5581039', 'n_tokens_mistral': 948, 'n_tokens_neox': 927, 'n_words': 247}