<commit_before>'use babel';

import atomEnv from 'atom';
import semver from 'semver';
import escapeStringRegexp from 'escape-string-regexp';

import { canRangeBeIgnored } from "./helpers";

/**
 * Linter helper class
 */
export class Linter {

  /**
   * Constructor of the Linter class
   * @constructor
   */
  constructor() {
    this.info = false;
  }

  /**
   * Find the range to select for a specific package name
   * @param {Object} dependency Dependency
   * @param {String} content Content of the current package.json
   * @param {TextEditor} textEditor Atom TextEditor
   * @return {Range} Range of the dependency text in the package.json file
   */
  getDependencyRange(dependency, content, textEditor) {
    try {
      const depRegex = new RegExp(`"${escapeStringRegexp(dependency.name)}" *: *"${escapeStringRegexp(dependency.version)}"`, 'ig')
      const startIdx = content.search(depRegex);
      const textBuffer = textEditor.getBuffer();

      if (startIdx < 0) {
        return [];
      }
      const match = content.substring(startIdx).match(depRegex);
      return new atomEnv.Range(textBuffer.positionForCharacterIndex(startIdx), textBuffer.positionForCharacterIndex(match ? match[0].length + startIdx : startIdx));

    } catch (ex) {
      return [];
    }
  }


  getVersionPrefix(version) {
    return /^[^0-9]*/.exec(version)[0];
  }

  /**
   * Generate the Linter message for the specific dependency
   * @param {Object} dependency Dependency
   * @param {String} content Content of the current package.json
   * @param {TextEditor} textEditor Atom TextEditor
   * @return {Promise} Message to the linter with the information relative to the dependency
   */
  reportDependency(dependency, content, textEditor) {
    const latest = dependency.availableVersions[dependency.availableVersions.length - 1];
    const prefix = /^[^0-9]*/.exec(dependency.version)[0];
    const installer = (version) => {
      atom.notifications.addInfo(`Installing ${dependency.name} to ${version || latest}`);
      return new atomEnv.BufferedProcess({
        command: 'npm',
        args: ['install', `${dependency.name}@${version || latest}`],
        options: {
          env: process.env,
          cwd: atom.project.getPaths()[0]
        },
        exit: (code) => {
          if (!code) {
            atom.notifications.addSuccess(`${dependency.name} is now up-to-date`);
          } else {
            atom.notifications.addError(`Failed to install ${dependency.name} (status: ${code})`);
          }
        }
      });
    };

    let severity = 'info';
    let solutions;
    let text = `The package ${dependency.name}`;
    let description;

    const validVersion = semver.valid(dependency.version);
    if (latest && semver.validRange(dependency.version) && (!validVersion || dependency.availableVersions.find((version) => version === validVersion))) {
      if (!semver.satisfies(latest, dependency.version)) {
        const filteredAvailableVersion = dependency.availableVersions.filter((version) => !semver.prerelease(version));<commit_msg>install into current module<commit_after>'use babel';

import atomEnv from 'atom';
import semver from 'semver';
import path from 'path';
import escapeStringRegexp from 'escape-string-regexp';

import { canRangeBeIgnored } from "./helpers";

/**
 * Linter helper class
 */
export class Linter {

  /**
   * Constructor of the Linter class
   * @constructor
   */
  constructor() {
    this.info = false;
  }

  /**
   * Find the range to select for a specific package name
   * @param {Object} dependency Dependency
   * @param {String} content Content of the current package.json
   * @param {TextEditor} textEditor Atom TextEditor
   * @return {Range} Range of the dependency text in the package.json file
   */
  getDependencyRange(dependency, content, textEditor) {
    try {
      const depRegex = new RegExp(`"${escapeStringRegexp(dependency.name)}" *: *"${escapeStringRegexp(dependency.version)}"`, 'ig')
      const startIdx = content.search(depRegex);
      const textBuffer = textEditor.getBuffer();

      if (startIdx < 0) {
        return [];
      }
      const match = content.substring(startIdx).match(depRegex);
      return new atomEnv.Range(textBuffer.positionForCharacterIndex(startIdx), textBuffer.positionForCharacterIndex(match ? match[0].length + startIdx : startIdx));

    } catch (ex) {
      return [];
    }
  }


  getVersionPrefix(version) {
    return /^[^0-9]*/.exec(version)[0];
  }

  /**
   * Generate the Linter message for the specific dependency
   * @param {Object} dependency Dependency
   * @param {String} content Content of the current package.json
   * @param {TextEditor} textEditor Atom TextEditor
   * @return {Promise} Message to the linter with the information relative to the dependency
   */
  reportDependency(dependency, content, textEditor) {
    const latest = dependency.availableVersions[dependency.availableVersions.length - 1];
    const prefix = /^[^0-9]*/.exec(dependency.version)[0];
    const installer = (version) => {
      atom.notifications.addInfo(`Installing ${dependency.name} to ${version || latest}`);
      return new atomEnv.BufferedProcess({
        command: 'npm',
        args: ['install', `${dependency.name}@${version || latest}`],
        options: {
          env: process.env,
          cwd: path.dirname(textEditor.getPath())
        },
        exit: (code) => {
          if (!code) {
            atom.notifications.addSuccess(`${dependency.name} is now up-to-date`);
          } else {
            atom.notifications.addError(`Failed to install ${dependency.name} (status: ${code})`);
          }
        }
      });
    };

    let severity = 'info';
    let solutions;
    let text = `The package ${dependency.name}`;
    let description;

    const validVersion = semver.valid(dependency.version);
    if (latest && semver.validRange(dependency.version) && (!validVersion || dependency.availableVersions.find((version) => version === validVersion))) {
      if (!semver.satisfies(latest, dependency.version)) {
        const filteredAvailableVersion = dependency.availableVersions.filter((version) => !semver.prerelease(version));
{'fraction_non_alphanumeric': 0.13172781638920317, 'fraction_numerical': 0.00307095522870535, 'mean_word_length': 3.297222222222222, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '7409535', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1721, 'n_words': 448}