Skip to content

Commit

Permalink
Add prefer-const eslint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyfarrell committed Sep 17, 2019
1 parent 0682367 commit 5c7501c
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 74 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"one-var": [0, { "initialized": "never" }],
"operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
"padded-blocks": [0, "never"],
"prefer-const": 2,
"quotes": [2, "single", "avoid-escape"],
"radix": 2,
"semi": [2, "always"],
Expand Down
6 changes: 3 additions & 3 deletions examples/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const match = (list, pattern, options = {}) => {
normalize = true;
}

let isMatch = pm(pattern, options);
let matches = new Set();
const isMatch = pm(pattern, options);
const matches = new Set();
for (let ele of list) {
if (normalize === true || options.normalize === true) {
ele = path.posix.normalize(ele);
Expand All @@ -28,7 +28,7 @@ const match = (list, pattern, options = {}) => {
return [...matches];
};

let fixtures = ['a.md', 'a/b.md', './a.md', './a/b.md', 'a/b/c.md', './a/b/c.md', '.\\a\\b\\c.md', 'a\\b\\c.md'];
const fixtures = ['a.md', 'a/b.md', './a.md', './a/b.md', 'a/b/c.md', './a/b/c.md', '.\\a\\b\\c.md', 'a\\b\\c.md'];

console.log(path.posix.normalize('./{a,b,c}/*.md'));
console.log(match(fixtures, './**/*.md'));
Expand Down
44 changes: 22 additions & 22 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const expandRange = (args, options) => {
}

args.sort();
let value = `[${args.join('-')}]`;
const value = `[${args.join('-')}]`;

try {
/* eslint-disable no-new */
Expand Down Expand Up @@ -77,18 +77,18 @@ const parse = (input, options) => {

input = REPLACEMENTS[input] || input;

let opts = { ...options };
let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
let len = input.length;
const opts = { ...options };
const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
const len = input.length;
if (len > max) {
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
}

let bos = { type: 'bos', value: '', output: opts.prepend || '' };
let tokens = [bos];
const bos = { type: 'bos', value: '', output: opts.prepend || '' };
const tokens = [bos];

let capture = opts.capture ? '' : '?:';
let win32 = utils.isWindows(options);
const capture = opts.capture ? '' : '?:';
const win32 = utils.isWindows(options);

// create constants based on platform, for windows or posix
const PLATFORM_CHARS = constants.globChars(win32);
Expand All @@ -113,9 +113,9 @@ const parse = (input, options) => {
return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
};

let nodot = opts.dot ? '' : NO_DOT;
const nodot = opts.dot ? '' : NO_DOT;
let star = opts.bash === true ? globstar(opts) : STAR;
let qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;

if (opts.capture) {
star = `(${star})`;
Expand All @@ -126,7 +126,7 @@ const parse = (input, options) => {
opts.noextglob = opts.noext;
}

let state = {
const state = {
index: -1,
start: 0,
consumed: '',
Expand All @@ -139,8 +139,8 @@ const parse = (input, options) => {
tokens
};

let extglobs = [];
let stack = [];
const extglobs = [];
const stack = [];
let prev = bos;
let value;

Expand Down Expand Up @@ -176,8 +176,8 @@ const parse = (input, options) => {

const push = tok => {
if (prev.type === 'globstar') {
let isBrace = state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace');
let isExtglob = extglobs.length && (tok.type === 'pipe' || tok.type === 'paren');
const isBrace = state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace');
const isExtglob = extglobs.length && (tok.type === 'pipe' || tok.type === 'paren');
if (tok.type !== 'slash' && tok.type !== 'paren' && !isBrace && !isExtglob) {
state.output = state.output.slice(0, -prev.output.length);
prev.type = 'star';
Expand All @@ -203,12 +203,12 @@ const parse = (input, options) => {
};

const extglobOpen = (type, value) => {
let token = { ...EXTGLOB_CHARS[value], conditions: 1, inner: '' };
const token = { ...EXTGLOB_CHARS[value], conditions: 1, inner: '' };

token.prev = prev;
token.parens = state.parens;
token.output = state.output;
let output = (opts.capture ? '(' : '') + token.open;
const output = (opts.capture ? '(' : '') + token.open;

push({ type, value, output: state.output ? '' : ONE_CHAR });
push({ type: 'paren', extglob: true, value: advance(), output });
Expand Down Expand Up @@ -301,7 +301,7 @@ const parse = (input, options) => {
*/

if (value === '\\') {
let next = peek();
const next = peek();

if (next === '/' && opts.bash !== true) {
continue;
Expand Down Expand Up @@ -841,7 +841,7 @@ const parse = (input, options) => {
continue;
}

let token = { type: 'star', value, output: star };
const token = { type: 'star', value, output: star };

if (opts.bash === true) {
token.output = '.*?';
Expand Down Expand Up @@ -907,7 +907,7 @@ const parse = (input, options) => {
if (state.backtrack === true) {
state.output = '';

for (let token of state.tokens) {
for (const token of state.tokens) {
state.output += token.output != null ? token.output : token.value;

if (token.suffix) {
Expand Down Expand Up @@ -989,10 +989,10 @@ parse.fastpaths = (input, options) => {
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;

default: {
let match = /^(.*?)\.(\w+)$/.exec(str);
const match = /^(.*?)\.(\w+)$/.exec(str);
if (!match) return;

let source = create(match[1], options);
const source = create(match[1], options);
if (!source) return;

return source + DOT_LITERAL + match[2];
Expand Down
8 changes: 4 additions & 4 deletions lib/picomatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const picomatch = (glob, options, returnState = false) => {
if (Array.isArray(glob)) {
const fns = glob.map(input => picomatch(input, options, returnState));
return str => {
for (let isMatch of fns) {
for (const isMatch of fns) {
const state = isMatch(str);
if (state) return state;
}
Expand All @@ -52,13 +52,13 @@ const picomatch = (glob, options, returnState = false) => {

let isIgnored = () => false;
if (opts.ignore) {
let ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
isIgnored = picomatch(opts.ignore, ignoreOpts, returnState);
}

const matcher = (input, returnObject = false) => {
let { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
let result = { glob, state, regex, posix, input, output, match, isMatch };
const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix });
const result = { glob, state, regex, posix, input, output, match, isMatch };

if (typeof opts.onResult === 'function') {
opts.onResult(result);
Expand Down
4 changes: 2 additions & 2 deletions lib/scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ module.exports = (input, options) => {
}
}

let isExtglobChar = code === CHAR_PLUS
const isExtglobChar = code === CHAR_PLUS
|| code === CHAR_AT
|| code === CHAR_EXCLAMATION_MARK;

Expand Down Expand Up @@ -181,7 +181,7 @@ module.exports = (input, options) => {
}

let prefix = '';
let orig = input;
const orig = input;
let base = input;
let glob = '';

Expand Down
10 changes: 5 additions & 5 deletions test/api.scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const assert = require('assert').strict;
const scan = require('../lib/scan');
const base = (...args) => scan(...args).base;
const both = (...args) => {
let { base, glob } = scan(...args);
const { base, glob } = scan(...args);
return [base, glob];
};

Expand Down Expand Up @@ -273,7 +273,7 @@ describe('picomatch', () => {
});

it('should support regex character classes', () => {
let opts = { unescape: true };
const opts = { unescape: true };
assert.deepEqual(both('[a-c]b*'), ['', '[a-c]b*']);
assert.deepEqual(both('[a-j]*[^c]'), ['', '[a-j]*[^c]']);
assert.deepEqual(both('[a-j]*[^c]b/c'), ['', '[a-j]*[^c]b/c']);
Expand Down Expand Up @@ -355,7 +355,7 @@ describe('picomatch', () => {
});

it('should respect brace enclosures with embedded separators', () => {
let opts = { unescape: true };
const opts = { unescape: true };
assert.equal(base('path/{,/,bar/baz,qux}/', opts), 'path');
assert.equal(base('path/\\{,/,bar/baz,qux}/', opts), 'path/{,/,bar/baz,qux}/');
assert.equal(base('path/\\{,/,bar/baz,qux\\}/', opts), 'path/{,/,bar/baz,qux}/');
Expand All @@ -367,7 +367,7 @@ describe('picomatch', () => {
});

it('should handle escaped nested braces', () => {
let opts = { unescape: true };
const opts = { unescape: true };
assert.equal(base('\\{../,./,\\{bar,/baz},qux}', opts), '{../,./,{bar,/baz},qux}');
assert.equal(base('\\{../,./,\\{bar,/baz},qux}/', opts), '{../,./,{bar,/baz},qux}/');
assert.equal(base('path/\\{,/,bar/{baz,qux}}/', opts), 'path/{,/,bar/{baz,qux}}/');
Expand All @@ -378,7 +378,7 @@ describe('picomatch', () => {
});

it('should recognize escaped braces', () => {
let opts = { unescape: true };
const opts = { unescape: true };
assert.equal(base('\\{foo,bar\\}', opts), '{foo,bar}');
assert.equal(base('\\{foo,bar\\}/', opts), '{foo,bar}/');
assert.equal(base('\\{foo,bar}/', opts), '{foo,bar}/');
Expand Down
6 changes: 3 additions & 3 deletions test/dotfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('dotfiles', () => {
});

it('should match dotfiles when there is a leading dot:', () => {
let opts = { dot: true };
const opts = { dot: true };
assert.deepEqual(match(['.dotfile'], '*', opts), ['.dotfile']);
assert.deepEqual(match(['.dotfile'], '**', opts), ['.dotfile']);
assert.deepEqual(match(['a/b', 'a/.b', '.a/b', '.a/.b'], '**', opts), ['a/b', 'a/.b', '.a/b', '.a/.b']);
Expand All @@ -40,7 +40,7 @@ describe('dotfiles', () => {
});

it('should match dotfiles when there is not a leading dot:', () => {
let opts = { dot: true };
const opts = { dot: true };
assert.deepEqual(match(['.dotfile'], '*.*', opts), ['.dotfile']);
assert.deepEqual(match(['.a', '.b', 'c', 'c.md'], '*.*', opts), ['.a', '.b', 'c.md']);
assert.deepEqual(match(['.dotfile'], '*.md', opts), []);
Expand All @@ -61,7 +61,7 @@ describe('dotfiles', () => {

describe('options.dot', () => {
it('should match dotfiles when `options.dot` is true:', () => {
let fixtures = ['a/./b', 'a/../b', 'a/c/b', 'a/.d/b'];
const fixtures = ['a/./b', 'a/../b', 'a/c/b', 'a/.d/b'];
assert.deepEqual(match(['.dotfile'], '*.*', { dot: true }), ['.dotfile']);
assert.deepEqual(match(['.dotfile'], '*.md', { dot: true }), []);
assert.deepEqual(match(['.dotfile'], '.dotfile', { dot: true }), ['.dotfile']);
Expand Down
4 changes: 2 additions & 2 deletions test/extglobs-temp.js
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ describe('extglobs', () => {
});

it('should work with character classes', () => {
let opts = { posix: true };
const opts = { posix: true };
assert(isMatch('a.b', 'a[^[:alnum:]]b', opts));
assert(isMatch('a,b', 'a[^[:alnum:]]b', opts));
assert(isMatch('a:b', 'a[^[:alnum:]]b', opts));
Expand Down Expand Up @@ -1133,7 +1133,7 @@ describe('extglobs', () => {
});

it('should support POSIX character classes in extglobs', () => {
let opts = { posix: true };
const opts = { posix: true };
assert(isMatch('a.c', '+([[:alpha:].])', opts));
assert(isMatch('a.c', '+([[:alpha:].])+([[:alpha:].])', opts));
assert(isMatch('a.c', '*([[:alpha:].])', opts));
Expand Down
4 changes: 2 additions & 2 deletions test/extglobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { isMatch, makeRe } = require('..');

describe('extglobs', () => {
it('should throw on imbalanced sets when `options.strictBrackets` is true', () => {
let opts = { strictBrackets: true };
const opts = { strictBrackets: true };
assert.throws(() => makeRe('a(b', opts), /Missing closing: "\)"/i);
assert.throws(() => makeRe('a)b', opts), /Missing opening: "\("/i);
});
Expand Down Expand Up @@ -713,7 +713,7 @@ describe('extglobs', () => {
// these are not extglobs, and do not need to pass, but they are included
// to test integration with other features
it('should support regex characters', () => {
let fixtures = ['a c', 'a.c', 'a.xy.zc', 'a.zc', 'a123c', 'a1c', 'abbbbc', 'abbbc', 'abbc', 'abc', 'abq', 'axy zc', 'axy', 'axy.zc', 'axyzc'];
const fixtures = ['a c', 'a.c', 'a.xy.zc', 'a.zc', 'a123c', 'a1c', 'abbbbc', 'abbbc', 'abbc', 'abc', 'abq', 'axy zc', 'axy', 'axy.zc', 'axyzc'];

if (process.platform !== 'win32') {
assert.deepEqual(match(['a\\b', 'a/b', 'ab'], 'a/b'), ['a/b']);
Expand Down
6 changes: 3 additions & 3 deletions test/globstars.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('stars', () => {
});

it('should respect trailing slashes on paterns', () => {
let fixtures = ['a', 'a/', 'a/a', 'a/a/', 'a/a/a', 'a/a/a/', 'a/a/a/a', 'a/a/a/a/', 'a/a/a/a/a', 'a/a/a/a/a/', 'a/a/b', 'a/a/b/', 'a/b', 'a/b/', 'a/b/c/.d/e/', 'a/c', 'a/c/', 'a/b', 'a/x/', 'b', 'b/', 'x/y', 'x/y/', 'z/z', 'z/z/'];
const fixtures = ['a', 'a/', 'a/a', 'a/a/', 'a/a/a', 'a/a/a/', 'a/a/a/a', 'a/a/a/a/', 'a/a/a/a/a', 'a/a/a/a/a/', 'a/a/b', 'a/a/b/', 'a/b', 'a/b/', 'a/b/c/.d/e/', 'a/c', 'a/c/', 'a/b', 'a/x/', 'b', 'b/', 'x/y', 'x/y/', 'z/z', 'z/z/'];

assert.deepEqual(match(fixtures, '**/*/a/'), ['a/a/', 'a/a/a/', 'a/a/a/a/', 'a/a/a/a/a/']);
assert.deepEqual(match(fixtures, '**/*/a/*/'), ['a/a/a/', 'a/a/a/a/', 'a/a/a/a/a/', 'a/a/b/']);
Expand All @@ -52,7 +52,7 @@ describe('stars', () => {
});

it('should match literal globstars when stars are escaped', () => {
let fixtures = ['.md', '**a.md', '**.md', '.md', '**'];
const fixtures = ['.md', '**a.md', '**.md', '.md', '**'];
assert.deepEqual(match(fixtures, '\\*\\**.md'), ['**a.md', '**.md']);
assert.deepEqual(match(fixtures, '\\*\\*.md'), ['**.md']);
});
Expand Down Expand Up @@ -286,7 +286,7 @@ describe('stars', () => {
});

it('should match leading dots when defined in pattern', () => {
let fixtures = ['.gitignore', 'a/b/z/.dotfile', 'a/b/z/.dotfile.md', 'a/b/z/.dotfile.md', 'a/b/z/.dotfile.md'];
const fixtures = ['.gitignore', 'a/b/z/.dotfile', 'a/b/z/.dotfile.md', 'a/b/z/.dotfile.md', 'a/b/z/.dotfile.md'];
assert(!isMatch('.gitignore', 'a/**/z/*.md'));
assert(!isMatch('a/b/z/.dotfile', 'a/**/z/*.md'));
assert(!isMatch('a/b/z/.dotfile.md', '**/c/.*.md'));
Expand Down
2 changes: 1 addition & 1 deletion test/minimatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('minimatch parity:', () => {
});

it('https://github.com/isaacs/minimatch/issues/67 (should work consistently with `makeRe` and matcher functions)', () => {
let re = makeRe('node_modules/foobar/**/*.bar');
const re = makeRe('node_modules/foobar/**/*.bar');
assert(re.test('node_modules/foobar/foo.bar'));
assert(isMatch('node_modules/foobar/foo.bar', 'node_modules/foobar/**/*.bar'));
});
Expand Down
4 changes: 2 additions & 2 deletions test/options.format.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe('options.format', () => {

// see https://github.com/isaacs/minimatch/issues/30
it('should match the string returned by options.format', () => {
let opts = { format: str => str.replace(/\\/g, '/').replace(/^\.\//, ''), strictSlashes: true };
let fixtures = ['a', './a', 'b', 'a/a', './a/b', 'a/c', './a/x', './a/a/a', 'a/a/b', './a/a/a/a', './a/a/a/a/a', 'x/y', './z/z'];
const opts = { format: str => str.replace(/\\/g, '/').replace(/^\.\//, ''), strictSlashes: true };
const fixtures = ['a', './a', 'b', 'a/a', './a/b', 'a/c', './a/x', './a/a/a', 'a/a/b', './a/a/a/a', './a/a/a/a/a', 'x/y', './z/z'];

assert(!isMatch('./.a', '*.a', opts));
assert(!isMatch('./.a', './*.a', opts));
Expand Down
8 changes: 4 additions & 4 deletions test/options.ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ describe('options.ignore', () => {
assert(!isMatch('+b/src/glimini.js', '+b/src/*', { ignore: ['**/*.js'] }));
});

let negations = ['a/a', 'a/b', 'a/c', 'a/d', 'a/e', 'b/a', 'b/b', 'b/c'];
let globs = ['.a', '.a/a', '.a/a/a', '.a/a/a/a', 'a', 'a/.a', 'a/a', 'a/a/.a', 'a/a/a', 'a/a/a/a', 'a/a/a/a/a', 'a/a/b', 'a/b', 'a/b/c', 'a/c', 'a/x', 'b', 'b/b/b', 'b/b/c', 'c/c/c', 'e/f/g', 'h/i/a', 'x/x/x', 'x/y', 'z/z', 'z/z/z'].sort();
const negations = ['a/a', 'a/b', 'a/c', 'a/d', 'a/e', 'b/a', 'b/b', 'b/c'];
const globs = ['.a', '.a/a', '.a/a/a', '.a/a/a/a', 'a', 'a/.a', 'a/a', 'a/a/.a', 'a/a/a', 'a/a/a/a', 'a/a/a/a/a', 'a/a/b', 'a/b', 'a/b/c', 'a/c', 'a/x', 'b', 'b/b/b', 'b/b/c', 'c/c/c', 'e/f/g', 'h/i/a', 'x/x/x', 'x/y', 'z/z', 'z/z/z'].sort();

it('should filter out ignored patterns', () => {
let opts = { ignore: ['a/**'], strictSlashes: true };
let dotOpts = { ...opts, dot: true };
const opts = { ignore: ['a/**'], strictSlashes: true };
const dotOpts = { ...opts, dot: true };

assert.deepEqual(match(globs, '*', opts), ['b']);
assert.deepEqual(match(globs, '*', { ignore: '**/a' }), ['b']);
Expand Down
Loading

0 comments on commit 5c7501c

Please sign in to comment.