<commit_before>/**
 * @author <NAME>
 * @copyright 2017 <NAME>
 * @license MIT
 * @module linebreak-style
 * @fileoverview
 *   Warn when linebreaks violate a given or detected style.
 *
 *   Options: either `'unix'` (for `\n`, denoted as `␊`), `'windows'` (for `\r\n`,
 *   denoted as `␍␊`), or `'consistent'` (to detect the first used linebreak in
 *   a file).  Default: `'consistent'`.
 *
 *   ## Fix
 *
 *   [`remark-stringify`](https://github.com/remarkjs/remark/tree/master/packages/remark-stringify)
 *   always uses unix-style linebreaks.
 *
 *   See [Using remark to fix your markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown)
 *   on how to automatically fix warnings for this rule.
 *
 * @example {"name": "valid-consistent-as-windows.md"}
 *
 *   Alpha␍␊
 *   Bravo␍␊
 *
 * @example {"name": "valid-consistent-as-unix.md"}
 *
 *   Alpha␊
 *   Bravo␊
 *
 * @example {"name": "invalid-unix.md", "label": "input", "setting": "unix", "config": {"positionless": true}}
 *
 *   Alpha␍␊
 *
 * @example {"name": "invalid-unix.md", "label": "output", "setting": "unix"}
 *
 *   1:7: Expected linebreaks to be unix (`\n`), not windows (`\r\n`)
 *
 * @example {"name": "invalid-windows.md", "label": "input", "setting": "windows", "config": {"positionless": true}}
 *
 *   Alpha␊
 *
 * @example {"name": "invalid-windows.md", "label": "output", "setting": "windows"}
 *
 *   1:6: Expected linebreaks to be windows (`\r\n`), not unix (`\n`)
 */

'use strict';

var rule = require('unified-lint-rule');
var location = require('vfile-location');

module.exports = rule('remark-lint:linebreak-style', linebreakStyle);

var sequences = {
  unix: '\n',
  windows: '\r\n'
};

var escaped = {
  unix: '\\n',
  windows: '\\r\\n'
};

function linebreakStyle(ast, file, preferred) {
  var content = String(file);
  var position = location(content).toPosition;
  var index = content.indexOf('\n');
  var type;

  while (index !== -1) {
    type = content.charAt(index - 1) === '\r' ? 'windows' : 'unix';

    if (preferred) {
      if (sequences[preferred] !== sequences[type]) {
        file.message(
          'Expected linebreaks to be ' + preferred + ' (`' + escaped[preferred] + '`), ' +
          'not ' + type + ' (`' + escaped[type] + '`)',
          position(index)
        );
      }
    } else {
      preferred = type;
    }

    index = content.indexOf('\n', index + 1);
  }
}
<commit_msg>linebreak-style: handle explicit default<commit_after>/**
 * @author <NAME>
 * @copyright 2017 <NAME>
 * @license MIT
 * @module linebreak-style
 * @fileoverview
 *   Warn when linebreaks violate a given or detected style.
 *
 *   Options: either `'unix'` (for `\n`, denoted as `␊`), `'windows'` (for `\r\n`,
 *   denoted as `␍␊`), or `'consistent'` (to detect the first used linebreak in
 *   a file).  Default: `'consistent'`.
 *
 *   ## Fix
 *
 *   [`remark-stringify`](https://github.com/remarkjs/remark/tree/master/packages/remark-stringify)
 *   always uses unix-style linebreaks.
 *
 *   See [Using remark to fix your markdown](https://github.com/remarkjs/remark-lint#using-remark-to-fix-your-markdown)
 *   on how to automatically fix warnings for this rule.
 *
 * @example {"name": "valid-consistent-as-windows.md"}
 *
 *   Alpha␍␊
 *   Bravo␍␊
 *
 * @example {"name": "valid-consistent-as-unix.md"}
 *
 *   Alpha␊
 *   Bravo␊
 *
 * @example {"name": "invalid-unix.md", "label": "input", "setting": "unix", "config": {"positionless": true}}
 *
 *   Alpha␍␊
 *
 * @example {"name": "invalid-unix.md", "label": "output", "setting": "unix"}
 *
 *   1:7: Expected linebreaks to be unix (`\n`), not windows (`\r\n`)
 *
 * @example {"name": "invalid-windows.md", "label": "input", "setting": "windows", "config": {"positionless": true}}
 *
 *   Alpha␊
 *
 * @example {"name": "invalid-windows.md", "label": "output", "setting": "windows"}
 *
 *   1:6: Expected linebreaks to be windows (`\r\n`), not unix (`\n`)
 */

'use strict';

var rule = require('unified-lint-rule');
var location = require('vfile-location');

module.exports = rule('remark-lint:linebreak-style', linebreakStyle);

var sequences = {
  unix: '\n',
  windows: '\r\n'
};

var escaped = {
  unix: '\\n',
  windows: '\\r\\n'
};

function linebreakStyle(ast, file, preferred) {
  var content = String(file);
  var position = location(content).toPosition;
  var index = content.indexOf('\n');
  var type;

  preferred = typeof preferred !== 'string' || preferred === 'consistent' ? null : preferred;

  while (index !== -1) {
    type = content.charAt(index - 1) === '\r' ? 'windows' : 'unix';

    if (preferred) {
      if (sequences[preferred] !== sequences[type]) {
        file.message(
          'Expected linebreaks to be ' + preferred + ' (`' + escaped[preferred] + '`), ' +
          'not ' + type + ' (`' + escaped[type] + '`)',
          position(index)
        );
      }
    } else {
      preferred = type;
    }

    index = content.indexOf('\n', index + 1);
  }
}

{'fraction_non_alphanumeric': 0.20225170888620828, 'fraction_numerical': 0.004422999597909127, 'mean_word_length': 3.237649063032368, 'pattern_counts': {'":': 36, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 4, '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': '1681835', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1761, 'n_words': 421}