Skip to content

Commit 88f1429

Browse files
committedMay 21, 2024
update eslint. lint, fix unit tests.
1 parent 415d660 commit 88f1429

23 files changed

+593
-499
lines changed
 

‎.eslintrc.json

+137-52
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
2-
"extends": [
3-
"eslint:recommended"
4-
],
2+
"root": true,
3+
"extends": "eslint:recommended",
54

65
"env": {
76
"browser": false,
87
"es6": true,
9-
"node": true,
10-
"mocha": true
8+
"mocha": true,
9+
"node": true
1110
},
1211

1312
"parserOptions":{
@@ -27,104 +26,190 @@
2726

2827
"rules": {
2928
"accessor-pairs": 2,
30-
"arrow-spacing": [2, { "before": true, "after": true }],
31-
"block-spacing": [2, "always"],
32-
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
33-
"comma-dangle": [2, "never"],
34-
"comma-spacing": [2, { "before": false, "after": true }],
35-
"comma-style": [2, "last"],
29+
"array-bracket-newline": [1, "consistent"],
30+
"array-bracket-spacing": [1, "never"],
31+
"array-callback-return": 1,
32+
"array-element-newline": [1, "consistent"],
33+
"arrow-body-style": 0,
34+
"arrow-parens": [1, "as-needed"],
35+
"arrow-spacing": [1, { "before": true, "after": true }],
36+
"block-scoped-var": 1,
37+
"block-spacing": [1, "always"],
38+
"brace-style": [1, "1tbs", { "allowSingleLine": true }],
39+
"callback-return": 0,
40+
"camelcase": [0, { "allow": [] }],
41+
"capitalized-comments": 0,
42+
"class-methods-use-this": 0,
43+
"comma-dangle": [1, "never"],
44+
"comma-spacing": [1, { "before": false, "after": true }],
45+
"comma-style": [1, "last"],
46+
"computed-property-spacing": 1,
47+
"consistent-return": 0,
48+
"consistent-this": 1,
3649
"constructor-super": 2,
37-
"curly": [2, "multi-line"],
38-
"dot-location": [2, "property"],
39-
"eol-last": 2,
40-
"eqeqeq": [2, "allow-null"],
41-
"generator-star-spacing": [2, { "before": true, "after": true }],
42-
"handle-callback-err": [2, "^(err|error)$" ],
43-
"indent": [2, 2, { "SwitchCase": 1 }],
44-
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
45-
"keyword-spacing": [2, { "before": true, "after": true }],
46-
"new-cap": [2, { "newIsCap": true, "capIsNew": false }],
50+
"curly": [1, "multi-line", "consistent"],
51+
"default-case": 1,
52+
"dot-location": [1, "property"],
53+
"dot-notation": 1,
54+
"eol-last": 1,
55+
"eqeqeq": [1, "allow-null"],
56+
"for-direction": 1,
57+
"func-call-spacing": 2,
58+
"generator-star-spacing": [1, { "before": true, "after": true }],
59+
"handle-callback-err": [2, "^(err|error)$"],
60+
"indent": [1, 2, { "SwitchCase": 1 }],
61+
"key-spacing": [1, { "beforeColon": false, "afterColon": true }],
62+
"keyword-spacing": [1, { "before": true, "after": true }],
63+
"linebreak-style": [1, "unix"],
64+
"new-cap": [1, { "newIsCap": true, "capIsNew": false }],
4765
"new-parens": 2,
48-
"no-array-constructor": 2,
66+
"no-alert": 1,
67+
"no-array-constructor": 1,
68+
"no-async-promise-executor": 1,
4969
"no-caller": 2,
70+
"no-case-declarations": 1,
5071
"no-class-assign": 2,
5172
"no-cond-assign": 2,
5273
"no-const-assign": 2,
74+
"no-constant-condition": [1, { "checkLoops": false }],
5375
"no-control-regex": 2,
5476
"no-debugger": 2,
5577
"no-delete-var": 2,
5678
"no-dupe-args": 2,
5779
"no-dupe-class-members": 2,
5880
"no-dupe-keys": 2,
5981
"no-duplicate-case": 2,
82+
"no-duplicate-imports": 0,
83+
"no-else-return": 0,
6084
"no-empty-character-class": 2,
61-
"no-eval": 2,
85+
"no-empty-function": 0,
86+
"no-empty-pattern": 0,
87+
"no-empty": [1, { "allowEmptyCatch": true }],
88+
"no-eval": 0,
6289
"no-ex-assign": 2,
6390
"no-extend-native": 2,
64-
"no-extra-bind": 2,
65-
"no-extra-boolean-cast": 2,
66-
"no-extra-parens": [2, "functions"],
91+
"no-extra-bind": 1,
92+
"no-extra-boolean-cast": 1,
93+
"no-extra-label": 1,
94+
"no-extra-parens": [1, "all",
95+
{
96+
"conditionalAssign": false,
97+
"returnAssign": false,
98+
"nestedBinaryExpressions": false,
99+
"ignoreJSX": "multi-line",
100+
"enforceForArrowConditionals": false
101+
}
102+
],
103+
"no-extra-semi": 1,
67104
"no-fallthrough": 2,
68105
"no-floating-decimal": 2,
69106
"no-func-assign": 2,
107+
"no-global-assign": 2,
108+
"no-implicit-coercion": 2,
109+
"no-implicit-globals": 1,
70110
"no-implied-eval": 2,
71-
"no-inner-declarations": [2, "functions"],
111+
"no-inner-declarations": [1, "functions"],
72112
"no-invalid-regexp": 2,
113+
"no-invalid-this": 1,
73114
"no-irregular-whitespace": 2,
74115
"no-iterator": 2,
75116
"no-label-var": 2,
76117
"no-labels": 2,
77118
"no-lone-blocks": 2,
119+
"no-lonely-if": 2,
120+
"no-loop-func": 1,
121+
"no-mixed-requires": 1,
78122
"no-mixed-spaces-and-tabs": 2,
79-
"no-multi-spaces": 2,
123+
"no-multi-assign": 0,
124+
"no-multi-spaces": 1,
80125
"no-multi-str": 2,
81-
"no-multiple-empty-lines": [2, { "max": 1 }],
82-
"no-native-reassign": 0,
126+
"no-multiple-empty-lines": [1, { "max": 1 }],
127+
"no-native-reassign": 2,
128+
"no-negated-condition": 0,
83129
"no-negated-in-lhs": 2,
84-
"no-new": 2,
85130
"no-new-func": 2,
86131
"no-new-object": 2,
87132
"no-new-require": 2,
133+
"no-new-symbol": 1,
88134
"no-new-wrappers": 2,
135+
"no-new": 1,
89136
"no-obj-calls": 2,
90-
"no-octal": 2,
91137
"no-octal-escape": 2,
92-
"no-proto": 0,
138+
"no-octal": 2,
139+
"no-path-concat": 1,
140+
"no-proto": 2,
141+
"no-prototype-builtins": 0,
93142
"no-redeclare": 2,
94143
"no-regex-spaces": 2,
95-
"no-return-assign": 2,
96-
"no-self-compare": 2,
144+
"no-restricted-globals": 2,
145+
"no-return-assign": 1,
146+
"no-return-await": 2,
147+
"no-script-url": 1,
148+
"no-self-assign": 1,
149+
"no-self-compare": 1,
97150
"no-sequences": 2,
98151
"no-shadow-restricted-names": 2,
152+
"no-shadow": 0,
99153
"no-spaced-func": 2,
100154
"no-sparse-arrays": 2,
155+
"no-template-curly-in-string": 0,
101156
"no-this-before-super": 2,
102157
"no-throw-literal": 2,
103-
"no-trailing-spaces": 0,
104-
"no-undef": 2,
158+
"no-trailing-spaces": 1,
105159
"no-undef-init": 2,
160+
"no-undef": 2,
106161
"no-unexpected-multiline": 2,
107-
"no-unneeded-ternary": [2, { "defaultAssignment": false }],
162+
"no-unneeded-ternary": [1, { "defaultAssignment": false }],
163+
"no-unreachable-loop": 1,
108164
"no-unreachable": 2,
109-
"no-unused-vars": [2, { "vars": "all", "args": "none" }],
110-
"no-useless-call": 0,
165+
"no-unsafe-assignment": 0,
166+
"no-unsafe-call": 0,
167+
"no-unsafe-finally": 2,
168+
"no-unsafe-member-access": 0,
169+
"no-unsafe-negation": 2,
170+
"no-unsafe-optional-chaining": 0,
171+
"no-unsafe-return": 0,
172+
"no-unused-expressions": 2,
173+
"no-unused-vars": [1, { "vars": "all", "args": "after-used" }],
174+
"no-use-before-define": 0,
175+
"no-useless-call": 2,
176+
"no-useless-catch": 0,
177+
"no-useless-escape": 0,
178+
"no-useless-rename": 1,
179+
"no-useless-return": 1,
180+
"no-var": 1,
181+
"no-void": 1,
182+
"no-warning-comments": 0,
111183
"no-with": 2,
112-
"one-var": [0, { "initialized": "never" }],
184+
"object-curly-spacing": [1, "always", { "objectsInObjects": true }],
185+
"object-shorthand": 1,
186+
"one-var": [1, { "initialized": "never" }],
113187
"operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
114-
"padded-blocks": [0, "never"],
115-
"quotes": [2, "single", "avoid-escape"],
188+
"padded-blocks": [1, { "switches": "never" }],
189+
"prefer-const": [1, { "destructuring": "all", "ignoreReadBeforeAssign": false }],
190+
"prefer-promise-reject-errors": 1,
191+
"quotes": [1, "single", "avoid-escape"],
116192
"radix": 2,
117-
"semi": [2, "always"],
118-
"semi-spacing": [2, { "before": false, "after": true }],
119-
"space-before-blocks": [2, "always"],
120-
"space-before-function-paren": [2, "never"],
121-
"space-in-parens": [2, "never"],
122-
"space-infix-ops": 2,
123-
"space-unary-ops": [2, { "words": true, "nonwords": false }],
193+
"rest-spread-spacing": 1,
194+
"semi-spacing": [1, { "before": false, "after": true }],
195+
"semi-style": 1,
196+
"semi": [1, "always"],
197+
"space-before-blocks": [1, "always"],
198+
"space-before-function-paren": [1, { "anonymous": "never", "named": "never", "asyncArrow": "always" }],
199+
"space-in-parens": [1, "never"],
200+
"space-infix-ops": 1,
201+
"space-unary-ops": [1, { "words": true, "nonwords": false }],
124202
"spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
203+
"strict": 2,
204+
"switch-colon-spacing": 1,
205+
"symbol-description": 1,
206+
"template-curly-spacing": [2, "never"],
207+
"template-tag-spacing": [2, "never"],
208+
"unicode-bom": 1,
125209
"use-isnan": 2,
210+
"valid-jsdoc": 1,
126211
"valid-typeof": 2,
127-
"wrap-iife": [2, "any"],
128-
"yoda": [2, "never"]
212+
"wrap-iife": [1, "any"],
213+
"yoda": [1, "never"]
129214
}
130215
}

‎LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014-2018, Jon Schlinkert.
3+
Copyright (c) 2014-present, Jon Schlinkert.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

‎bench/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const braces = require('..');
1111
*/
1212

1313
const cycle = (e, newline) => {
14-
process.stdout.write(`\u001b[G ${e.target}${newline ? `\n` : ''}`);
14+
process.stdout.write(`\u001b[G ${e.target}${newline ? '\n' : ''}`);
1515
};
1616

1717
const bench = (name, options) => {

‎examples/expand.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
const colors = require('ansi-colors');
3-
const parse = require('./parse');
43
const color = (arr, c) => arr.map(s => c(s)).join(', ');
54
const cp = require('child_process');
65
const braces = input => {
@@ -19,6 +18,6 @@ const braces = input => {
1918
const fixture = 'a{,b}c';
2019
console.log();
2120
console.log(' FIXTURE:', colors.magenta(fixture));
22-
console.log(' ACTUAL:', color(expand(parse(fixture)), colors.yellow));
21+
// console.log(' ACTUAL:', color(expand(parse(fixture)), colors.yellow));
2322
console.log('EXPECTED:', color(braces(fixture), colors.blue));
2423
console.log();

‎examples/option-transform.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ console.log(alpha);
1111
//=> [ 'x/foo/a-0/y', 'x/foo/b-1/y', 'x/foo/c-2/y', 'x/foo/d-3/y', 'x/foo/e-4/y' ]
1212

1313
const numeric = braces.expand('{1..5}', {
14-
transform(value, index) {
14+
transform(value) {
1515
return 'foo/' + value * 2;
1616
}
1717
});

‎index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const braces = (input, options = {}) => {
2323
let output = [];
2424

2525
if (Array.isArray(input)) {
26-
for (let pattern of input) {
27-
let result = braces.create(pattern, options);
26+
for (const pattern of input) {
27+
const result = braces.create(pattern, options);
2828
if (Array.isArray(result)) {
2929
output.push(...result);
3030
} else {
@@ -158,7 +158,7 @@ braces.create = (input, options = {}) => {
158158
return [input];
159159
}
160160

161-
return options.expand !== true
161+
return options.expand !== true
162162
? braces.compile(input, options)
163163
: braces.expand(input, options);
164164
};

‎lib/compile.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,53 @@ const fill = require('fill-range');
44
const utils = require('./utils');
55

66
const compile = (ast, options = {}) => {
7-
let walk = (node, parent = {}) => {
8-
let invalidBlock = utils.isInvalidBrace(parent);
9-
let invalidNode = node.invalid === true && options.escapeInvalid === true;
10-
let invalid = invalidBlock === true || invalidNode === true;
11-
let prefix = options.escapeInvalid === true ? '\\' : '';
7+
const walk = (node, parent = {}) => {
8+
const invalidBlock = utils.isInvalidBrace(parent);
9+
const invalidNode = node.invalid === true && options.escapeInvalid === true;
10+
const invalid = invalidBlock === true || invalidNode === true;
11+
const prefix = options.escapeInvalid === true ? '\\' : '';
1212
let output = '';
1313

1414
if (node.isOpen === true) {
1515
return prefix + node.value;
1616
}
17+
1718
if (node.isClose === true) {
19+
console.log('node.isClose', prefix, node.value);
1820
return prefix + node.value;
1921
}
2022

2123
if (node.type === 'open') {
22-
return invalid ? (prefix + node.value) : '(';
24+
return invalid ? prefix + node.value : '(';
2325
}
2426

2527
if (node.type === 'close') {
26-
return invalid ? (prefix + node.value) : ')';
28+
return invalid ? prefix + node.value : ')';
2729
}
2830

2931
if (node.type === 'comma') {
30-
return node.prev.type === 'comma' ? '' : (invalid ? node.value : '|');
32+
return node.prev.type === 'comma' ? '' : invalid ? node.value : '|';
3133
}
3234

3335
if (node.value) {
3436
return node.value;
3537
}
3638

3739
if (node.nodes && node.ranges > 0) {
38-
let args = utils.reduce(node.nodes);
39-
let range = fill(...args, { ...options, wrap: false, toRegex: true });
40+
const args = utils.reduce(node.nodes);
41+
const range = fill(...args, { ...options, wrap: false, toRegex: true, strictZeros: true });
4042

4143
if (range.length !== 0) {
4244
return args.length > 1 && range.length > 1 ? `(${range})` : range;
4345
}
4446
}
4547

4648
if (node.nodes) {
47-
for (let child of node.nodes) {
49+
for (const child of node.nodes) {
4850
output += walk(child, node);
4951
}
5052
}
53+
5154
return output;
5255
};
5356

0 commit comments

Comments
 (0)
Please sign in to comment.