<commit_before>'use babel';

/**
 * @author <NAME>
 * @copyright 2015 <NAME>
 * @license MIT
 * @module atom:linter-markdown
 * @fileoverview Linter.
 */

// eslint-disable-next-line import/no-extraneous-dependencies, import/extensions
import { CompositeDisposable } from 'atom';

const path = require('path');
const config = require('./config');

// Internal variables
let engine;
let processor;
let subscriptions;

// Settings
let scopes;
let detectIgnore;

const waitOnIdle = () =>
  new Promise((resolve) => {
    // Idle callbacks are done in FIFO order, so waiting on a newly queued idle
    // callback will ensure that the activation processes are completed
    window.requestIdleCallback(resolve);
  });

async function lint(editor) {
  if (!processor) {
    await waitOnIdle();
  }

  return engine({
    processor,
    detectIgnore,
    rcName: '.remarkrc',
    rcPath: path.resolve(__dirname, 'config.js'),
    packageField: 'remarkConfig',
    ignoreName: '.remarkignore',
    presetPrefix: 'remark-preset',
    pluginPrefix: 'remark'
  })(editor);
}

/**
 * Linter-markdown.
 *
 * @return {LinterConfiguration}
 */
function provideLinter() {
  return {
    grammarScopes: scopes,
    name: 'remark-lint',
    scope: 'file',
    lintOnFly: true,
    lint
  };
}

function activate() {
  const installLinterMarkdownDeps = () => {
    // Install package dependencies
    if (!atom.inSpecMode()) {
      require('atom-package-deps').install('linter-markdown');
    }
    // Load required modules
    engine = require('unified-engine-atom');
    processor = require('remark');
  };

  // Defer this till an idle time as we don't need it immediately
  window.requestIdleCallback(installLinterMarkdownDeps);

  subscriptions = new CompositeDisposable();

  subscriptions.add(atom.config.observe('linter-markdown.scopes', (value) => {
    scopes = value;
  }));
  subscriptions.add(atom.config.observe('linter-markdown.detectIgnore', (value) => {
    detectIgnore = value;
  }));

  config.on();
}

function deactivate() {
  subscriptions.dispose();

  config.off();
}<commit_msg>Cancel pending idle callbacks on deactivate<commit_after>'use babel';

/**
 * @author <NAME>
 * @copyright 2015 <NAME>
 * @license MIT
 * @module atom:linter-markdown
 * @fileoverview Linter.
 */

// eslint-disable-next-line import/no-extraneous-dependencies, import/extensions
import { CompositeDisposable } from 'atom';

const path = require('path');
const config = require('./config');

// Internal variables
let engine;
let processor;
let subscriptions;
const idleCallbacks = new Set();

// Settings
let scopes;
let detectIgnore;

const waitOnIdle = () =>
  new Promise((resolve) => {
    // Idle callbacks are done in FIFO order, so waiting on a newly queued idle
    // callback will ensure that the activation processes are completed
    const callbackID = window.requestIdleCallback(() => {
      idleCallbacks.delete(callbackID);
      resolve();
    });
    idleCallbacks.add(callbackID);
  });

async function lint(editor) {
  if (!processor) {
    await waitOnIdle();
  }

  return engine({
    processor,
    detectIgnore,
    rcName: '.remarkrc',
    rcPath: path.resolve(__dirname, 'config.js'),
    packageField: 'remarkConfig',
    ignoreName: '.remarkignore',
    presetPrefix: 'remark-preset',
    pluginPrefix: 'remark'
  })(editor);
}

/**
 * Linter-markdown.
 *
 * @return {LinterConfiguration}
 */
function provideLinter() {
  return {
    grammarScopes: scopes,
    name: 'remark-lint',
    scope: 'file',
    lintOnFly: true,
    lint
  };
}

function activate() {
  let callbackID;
  const installLinterMarkdownDeps = () => {
    idleCallbacks.delete(callbackID);

    // Install package dependencies
    if (!atom.inSpecMode()) {
      require('atom-package-deps').install('linter-markdown');
    }
    // Load required modules
    engine = require('unified-engine-atom');
    processor = require('remark');
  };

  // Defer this till an idle time as we don't need it immediately
  callbackID = window.requestIdleCallback(installLinterMarkdownDeps);
  idleCallbacks.add(callbackID);

  subscriptions = new CompositeDisposable();

  subscriptions.add(atom.config.observe('linter-markdown.scopes', (value) => {
    scopes = value;
  }));
  subscriptions.add(atom.config.observe('linter-markdown.detectIgnore', (value) => {
    detectIgnore = value;
  }));

  config.on();
}

function deactivate() {
  idleCallbacks.forEach(callbackID => window.cancleIdleCallback(callbackID));
  subscriptions.dispose();

  config.off();
}
{'fraction_non_alphanumeric': 0.13876020295609973, 'fraction_numerical': 0.0017648356496801235, 'mean_word_length': 3.7426778242677825, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '7605942', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1379, 'n_words': 327}