@bigbinary/eslint-plugin-neeto 1.0.14 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -13
- package/dist/index.js +2425 -503
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('path'), require('ramda'), require('fs')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['path', 'ramda', 'fs'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global["@bigbinary/eslint-plugin-neeto"] = factory(global.path, global.ramda, global.fs));
|
|
5
|
-
})(this, (function (path, ramda, fs) { 'use strict';
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global["@bigbinary/eslint-plugin-neeto"] = factory(global.path$2, global.ramda, global.fs));
|
|
5
|
+
})(this, (function (path$2, ramda, fs) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
8
|
|
|
9
|
-
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
9
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path$2);
|
|
10
10
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
11
11
|
|
|
12
12
|
function _arrayWithHoles(arr) {
|
|
@@ -80,6 +80,60 @@
|
|
|
80
80
|
}, _typeof(obj);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* @template {Function} T
|
|
85
|
+
* @param {T} func
|
|
86
|
+
* @returns {T}
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
var nullSafe = function nullSafe(func) {
|
|
90
|
+
return (// @ts-ignore
|
|
91
|
+
ramda.curryN(func.length, function () {
|
|
92
|
+
var _ref;
|
|
93
|
+
|
|
94
|
+
var dataArg = (_ref = func.length - 1, _ref < 0 || arguments.length <= _ref ? undefined : arguments[_ref]);
|
|
95
|
+
return ramda.isNil(dataArg) ? dataArg : func.apply(void 0, arguments);
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
var isNotEmpty$1 = /*#__PURE__*/ramda.complement(ramda.isEmpty);
|
|
100
|
+
var notEquals = /*#__PURE__*/ramda.curry(function (x, y) {
|
|
101
|
+
return x !== y;
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
var slugify = function slugify(string) {
|
|
105
|
+
return string.toString().toLowerCase().replace(/\s+/g, "-") // Replace spaces with -
|
|
106
|
+
.replace(/&/g, "-and-") // Replace & with 'and'
|
|
107
|
+
.replace(/[^\w-]+/g, "") // Remove all non-word characters
|
|
108
|
+
.replace(/--+/g, "-") // Replace multiple - with single -
|
|
109
|
+
.replace(/^-+/, "") // Trim - from start of text
|
|
110
|
+
.replace(/-+$/, "");
|
|
111
|
+
}; // Trim - from end of text
|
|
112
|
+
|
|
113
|
+
var humanize = function humanize(string) {
|
|
114
|
+
string = string.replace(/[_-]+/g, " ").replace(/\s{2,}/g, " ").replace(/([a-z\d])([A-Z])/g, "$1" + " " + "$2").replace(/([A-Z]+)([A-Z][a-z\d]+)/g, "$1" + " " + "$2").toLowerCase().trim();
|
|
115
|
+
string = string.charAt(0).toUpperCase() + string.slice(1);
|
|
116
|
+
return string;
|
|
117
|
+
};
|
|
118
|
+
var snakeToCamelCase = function snakeToCamelCase(string) {
|
|
119
|
+
return string.replace(/(_\w)/g, function (letter) {
|
|
120
|
+
return letter[1].toUpperCase();
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
var camelToSnakeCase = function camelToSnakeCase(string) {
|
|
124
|
+
return string.replace(/[A-Z]/g, function (letter) {
|
|
125
|
+
return "_".concat(letter.toLowerCase());
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
var capitalize$1 = function capitalize(string) {
|
|
129
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
130
|
+
};
|
|
131
|
+
nullSafe(slugify);
|
|
132
|
+
nullSafe(humanize);
|
|
133
|
+
nullSafe(snakeToCamelCase);
|
|
134
|
+
nullSafe(camelToSnakeCase);
|
|
135
|
+
nullSafe(capitalize$1);
|
|
136
|
+
|
|
83
137
|
var matchesImpl = function matchesImpl(pattern, object) {
|
|
84
138
|
var __parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : object;
|
|
85
139
|
|
|
@@ -98,25 +152,42 @@
|
|
|
98
152
|
var matches = /*#__PURE__*/ramda.curry(function (pattern, object) {
|
|
99
153
|
return matchesImpl(pattern, object);
|
|
100
154
|
});
|
|
155
|
+
var filterNonNull = function filterNonNull(object) {
|
|
156
|
+
return Object.fromEntries(Object.entries(object).filter(function (_ref5) {
|
|
157
|
+
var _ref6 = _slicedToArray(_ref5, 2),
|
|
158
|
+
v = _ref6[1];
|
|
159
|
+
|
|
160
|
+
return !ramda.isNil(v);
|
|
161
|
+
}).map(function (_ref7) {
|
|
162
|
+
var _ref8 = _slicedToArray(_ref7, 2),
|
|
163
|
+
k = _ref8[0],
|
|
164
|
+
v = _ref8[1];
|
|
165
|
+
|
|
166
|
+
return [k, _typeof(v) === "object" && !Array.isArray(v) ? filterNonNull(v) : v];
|
|
167
|
+
}));
|
|
168
|
+
};
|
|
169
|
+
nullSafe(filterNonNull);
|
|
101
170
|
var existsBy$1 = /*#__PURE__*/ramda.curry(function (pattern, array) {
|
|
102
171
|
return array.some(matches(pattern));
|
|
103
172
|
});
|
|
104
|
-
var
|
|
105
|
-
|
|
106
|
-
return x !== y;
|
|
173
|
+
var filterBy$1 = /*#__PURE__*/ramda.curry(function (pattern, array) {
|
|
174
|
+
return array.filter(matches(pattern));
|
|
107
175
|
});
|
|
108
176
|
|
|
109
177
|
const APIS_DIRECTORY = "app/javascript/src/apis";
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const BLACKLISTED_PACKAGES = ["moment", "bootstrap", "blueprint", "react-spinners", "react-table", "remixicon", "mjml", "react-select", "antd"];
|
|
178
|
+
const ROUTES_FILE_PATHS = ["app/javascript/src/routes.js", "app/javascript/src/common/routes.js"];
|
|
179
|
+
const BLACKLISTED_PACKAGES = ["moment", "bootstrap", "blueprint", "react-spinners", "react-table", "remixicon", "mjml", "react-select", "antd", "@bigbinary/neeto-utils"];
|
|
113
180
|
const TYPES = {
|
|
114
181
|
ARRAY_EXPRESSION: "ArrayExpression",
|
|
115
182
|
ARROW_FUNCTION_EXPRESSION: "ArrowFunctionExpression",
|
|
116
183
|
ASSIGNMENT_PATTERN: "AssignmentPattern",
|
|
117
184
|
AWAIT_EXPRESSION: "AwaitExpression",
|
|
118
185
|
BINARY_EXPRESSION: "BinaryExpression",
|
|
186
|
+
BLOCK_STATEMENT: "BlockStatement",
|
|
187
|
+
BREAK_STATEMENT: "BreakStatement",
|
|
119
188
|
CALL_EXPRESSION: "CallExpression",
|
|
189
|
+
CHAIN_EXPRESSION: "ChainExpression",
|
|
190
|
+
CONDITIONAL_EXPRESSION: "ConditionalExpression",
|
|
120
191
|
EXPORT_NAMED_DECLARATION: "ExportNamedDeclaration",
|
|
121
192
|
EXPORT_DEFAULT_DECLARATION: "ExportDefaultDeclaration",
|
|
122
193
|
FUNCTION_DECLARATION: "FunctionDeclaration",
|
|
@@ -137,7 +208,9 @@
|
|
|
137
208
|
OBJECT_PATTERN: "ObjectPattern",
|
|
138
209
|
PROGRAM: "Program",
|
|
139
210
|
PROPERTY: "Property",
|
|
211
|
+
RETURN_STATEMENT: "ReturnStatement",
|
|
140
212
|
SPREAD_ELEMENT: "SpreadElement",
|
|
213
|
+
TEMPLATE_ELEMENT: "TemplateElement",
|
|
141
214
|
TEMPLATE_LITERAL: "TemplateLiteral",
|
|
142
215
|
UNARY_EXPRESSION: "UnaryExpression",
|
|
143
216
|
VARIABLE_DECLARATION: "VariableDeclaration",
|
|
@@ -154,12 +227,74 @@
|
|
|
154
227
|
}]
|
|
155
228
|
};
|
|
156
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Returns a list of nodes that matches the pattern
|
|
232
|
+
* somewhere deep inside the given object-tree by
|
|
233
|
+
* partial object matching.
|
|
234
|
+
*
|
|
235
|
+
* @param {Object} obj the object tree to check
|
|
236
|
+
* @param {Object} pattern the pattern to match partially
|
|
237
|
+
* @param {Array} res list of nodes that matches the pattern
|
|
238
|
+
*/
|
|
239
|
+
|
|
240
|
+
const findMatchingNodesDeep = (obj, pattern, res = []) => {
|
|
241
|
+
if (typeof obj !== "object" || ramda.isNil(obj)) return res;
|
|
242
|
+
if (matches(pattern, obj)) return ramda.append(obj, res);
|
|
243
|
+
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
244
|
+
if (key === "parent") return acc;
|
|
245
|
+
return findMatchingNodesDeep(value, pattern, acc);
|
|
246
|
+
}, res);
|
|
247
|
+
};
|
|
248
|
+
/**
|
|
249
|
+
* Checks if any of the given pattern matches the object.
|
|
250
|
+
* @param {Object} obj The object tree to check.
|
|
251
|
+
* @param {Object[]} list The list of patterns to compare against.
|
|
252
|
+
* also @see matches
|
|
253
|
+
*/
|
|
254
|
+
|
|
255
|
+
const matchesAny = ramda.curry((list, obj) => list.some(matches(ramda.__, obj)));
|
|
256
|
+
/**
|
|
257
|
+
* Checks if the given pattern exists somewhere deep inside
|
|
258
|
+
* the given object-tree by partial object matching.
|
|
259
|
+
*
|
|
260
|
+
* @param {Object} pattern the pattern to match partially
|
|
261
|
+
* @param {Object} obj the object tree to check
|
|
262
|
+
*/
|
|
263
|
+
|
|
264
|
+
const patternExistsDeep = ramda.curry((pattern, obj) => {
|
|
265
|
+
if (typeof obj !== "object" || ramda.isNil(obj)) return false;
|
|
266
|
+
if (matches(pattern, obj)) return true;
|
|
267
|
+
return Object.entries(obj).some(([key, value]) => {
|
|
268
|
+
if (key === "parent") return false;
|
|
269
|
+
return patternExistsDeep(pattern, value);
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
const addFunctionImport = (context, fixer, functions, importPattern) => {
|
|
274
|
+
const root = context.getAncestors()[0];
|
|
275
|
+
const packageImport = root.body.find(matches(importPattern));
|
|
276
|
+
|
|
277
|
+
if (packageImport) {
|
|
278
|
+
const extraImports = functions.filter(func => !packageImport.specifiers.some(ramda.pathEq(["imported", "name"], func)));
|
|
279
|
+
if (ramda.isEmpty(extraImports)) return undefined;
|
|
280
|
+
return fixer.insertTextBefore(packageImport.specifiers[0], `${extraImports.join(", ")}, `);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const packageName = importPattern.source.value;
|
|
284
|
+
return fixer.insertTextBefore(root.body[0], `import { ${functions.join(", ")} } from "${packageName}";\n`);
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
const addNullSafeImport = (context, fixer) => {
|
|
288
|
+
const importPattern = ramda.assocPath(["source", "value"], "neetocommons/pure", IMPORT_DECLARATION);
|
|
289
|
+
return addFunctionImport(context, fixer, ["nullSafe"], importPattern);
|
|
290
|
+
};
|
|
157
291
|
/**
|
|
158
292
|
* @param {Object} context - ESLint context
|
|
159
293
|
* @param {Object} node - AST node
|
|
160
294
|
* @returns the source code corresponding to the supplied node.
|
|
161
295
|
*/
|
|
162
296
|
|
|
297
|
+
|
|
163
298
|
const getCode$1 = (context, node) => context.getSourceCode().text.substr(node.range[0], node.range[1] - node.range[0]);
|
|
164
299
|
/**
|
|
165
300
|
* Checks if the specified package is imported or not
|
|
@@ -203,43 +338,57 @@
|
|
|
203
338
|
*/
|
|
204
339
|
|
|
205
340
|
const isPackageImported = (context, node, packageName) => getPackagesAndAliases(context, [packageName]).includes(node.source.value);
|
|
206
|
-
const nodeReplacerWithImports = importPattern => {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
341
|
+
const nodeReplacerWithImports = importPattern => ({
|
|
342
|
+
replaceNode: ({
|
|
343
|
+
context,
|
|
344
|
+
node,
|
|
345
|
+
fix,
|
|
346
|
+
functions,
|
|
347
|
+
importNullSafe = false
|
|
348
|
+
}) => function* (fixer) {
|
|
349
|
+
const imports = addFunctionImport(context, fixer, Array.isArray(functions) ? functions : [functions], importPattern);
|
|
350
|
+
if (imports) yield imports;
|
|
351
|
+
|
|
352
|
+
if (importNullSafe) {
|
|
353
|
+
const nullSafeImport = addNullSafeImport(context, fixer);
|
|
354
|
+
if (nullSafeImport) yield nullSafeImport;
|
|
215
355
|
}
|
|
216
356
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
357
|
+
yield fixer.replaceText(node, fix);
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
const arrayFuncParam = root => root.arguments[0].params[0]; // find all file level imports from any node in the AST
|
|
220
361
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
362
|
+
/** @type {(any) => any[]} */
|
|
363
|
+
|
|
364
|
+
const getAllImports = node => {
|
|
365
|
+
let topNode = node;
|
|
366
|
+
|
|
367
|
+
while (!matches({
|
|
368
|
+
type: TYPES.PROGRAM
|
|
369
|
+
}, topNode)) {
|
|
370
|
+
topNode = topNode.parent;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
return filterBy$1({
|
|
374
|
+
type: TYPES.IMPORT_DECLARATION
|
|
375
|
+
}, topNode.body);
|
|
233
376
|
};
|
|
234
|
-
const
|
|
377
|
+
const isOptionalChainingPresent = node => patternExistsDeep({
|
|
378
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
379
|
+
optional: true
|
|
380
|
+
}, node);
|
|
381
|
+
const optionalChainingOptimizedName = (funcName, node) => isOptionalChainingPresent(node) ? `_${funcName}` : funcName;
|
|
235
382
|
|
|
236
383
|
const ARGUMENT_LIMIT = 3;
|
|
237
384
|
const API_ACTIONS_ARGUMENT_LIMIT = 2;
|
|
238
385
|
const FIXABLE_PARAMETER_TYPES = [TYPES.IDENTIFIER, TYPES.ASSIGNMENT_PATTERN];
|
|
239
386
|
|
|
240
|
-
const addInJsconfig = aliasName => `Add path for "${aliasName}" in jsconfig.json. Refer https://
|
|
387
|
+
const addInJsconfig = aliasName => `Add path for "${aliasName}" in jsconfig.json. Refer https://bit.ly/webpack-jsconfig-rule for more details.`;
|
|
241
388
|
const canBeReplacedWith = fix => `Can be replaced with: ${fix}`;
|
|
242
389
|
const disallowUse = packageName => `Do not use the package ${packageName}`;
|
|
390
|
+
const exportedObjectShouldBe = caseStyle => `Exported object should be in ${caseStyle}`;
|
|
391
|
+
const filenameShouldBe = caseStyle => `Filename should be in ${caseStyle}`;
|
|
243
392
|
const moveToConstantsJs = constantName => `Move the constant ${constantName} to a constants.js file.`;
|
|
244
393
|
const renameFile = filename => `Rename this file to ${filename}`;
|
|
245
394
|
const replaceWith = fix => `Replace this with: ${fix}`;
|
|
@@ -247,9 +396,9 @@
|
|
|
247
396
|
key,
|
|
248
397
|
fileName
|
|
249
398
|
}) => `Unable to resolve localized string '${key}' in ${fileName}`;
|
|
250
|
-
const useConstantCaseFor = constantName => `Use constant-case for naming the constant - ${constantName}.`;
|
|
251
399
|
const API_CONNECTOR_SHOULD_USE_DEFAULT_EXPORT_MESSAGE = "API Connector should be exported using the default export method";
|
|
252
400
|
const COMBINE_MULTIPLE_INDEPENDENT_AWAITS_MESSAGE = "Combine independent awaits to a single `Promise.all` call.";
|
|
401
|
+
const EXPORTED_OBJECT_AND_FILENAME_SHOULD_MATCH_MESSAGE = `Exported object and filename should match.`;
|
|
253
402
|
const GLOBALPROPS_NO_ASSIGNMENT_MESSAGE = "globalProps should not be assigned to other variables";
|
|
254
403
|
const NESTED_GLOBALPROPS_NO_ASSIGNMENT_MESSAGE = "Nested properties of globalProps should not be assigned to other variables";
|
|
255
404
|
const NO_AXIOS_IMPORT_OUTSIDE_APIS_MESSAGE = "Do not use axios outside `app/javascript/src/apis`";
|
|
@@ -266,11 +415,26 @@
|
|
|
266
415
|
const ROUTES_HAS_ALREADY_BEEN_DECLARED = "Identifier `routes` has already been declared";
|
|
267
416
|
const ROUTES_CONSTANT_SHOULD_BE_DECLARED = "A constant object named `routes` should be declared inside routes.js";
|
|
268
417
|
const ROUTES_SHOULD_USE_DEFAULT_EXPORT = "`routes` should be exported using the default export method.";
|
|
418
|
+
const USE_ARRAY_METHODS = "Use array methods (forEach, map, filter, reduce, etc) instead of 'for' loop. Refer 'Advanced Array Methods' section in https://bit.ly/learn-advanced-javascript";
|
|
269
419
|
const USE_AXIOS_CONFIG_FOR_PASSING_QUERY_PARAMETERS_MESSAGE = "Use 'params attribute in axios configuration' to pass query parameters.";
|
|
270
420
|
const USE_LINK_FOR_NAVIGATION = "Use Link or NavLink component from 'react-router-dom' for click-navigation instead of onClick handler";
|
|
271
421
|
const USE_ANCHOR_FOR_NAVIGATION = "Use Anchor element (<a>) for click-navigation instead of onClick handler";
|
|
272
422
|
const USE_BUTTON_TO_FOR_LINK_NAVIGATION = "Use `to` prop of Button (<Button to='path'>) for click-navigation instead of onClick handler";
|
|
273
423
|
const USE_BUTTON_TO_FOR_ANCHOR_NAVIGATION = "Use `href` prop of Button (<Button href='path'>) for click-navigation instead of onClick handler";
|
|
424
|
+
const USE_NEETOUI_BORDER_COLOR = "Use neetoUI border color. Refer https://bit.ly/border-color-page for more details.";
|
|
425
|
+
const USE_NEETOUI_BORDER_RADIUS = "Use neetoUI border radius. Refer https://bit.ly/border-radius-page for more details.";
|
|
426
|
+
const USE_NEETOUI_BOX_SHADOW = "Use neetoUI border shadow. Refer https://bit.ly/box-shadows-page for more details.";
|
|
427
|
+
const USE_NEETOUI_TEXT_COLOR = "Use neetoUI text color. Refer https://bit.ly/text-color-page for more details.";
|
|
428
|
+
const DONT_USE_ZUSTAND_STORE_WITHOUT_SELECTOR = "Don't use zustand store hook without a selector function. It will impact the performance";
|
|
429
|
+
const DONT_USE_ZUSTAND_STORE_WITHOUT_COMPARATOR_FUNCTION = "Don't pick multiple zustand state items without comparator function";
|
|
430
|
+
const USE_PROP_FOR_PICKING_SINGLE_ITEM = "Use prop instead of pick when picking single item";
|
|
431
|
+
const ENSURE_ZUSTAND_STORES_ARE_TYPE_ANNOTATED = `
|
|
432
|
+
Zustand stores should be type annotated like this:
|
|
433
|
+
/** @type {import(”neetocommons/react-utils”).ZustandStoreHook} */
|
|
434
|
+
const useUserStore = create(...)
|
|
435
|
+
`;
|
|
436
|
+
const ENSURE_ZUSTAND_CREATE_IMPORT_ARE_CONSISTENT = "default import from zustand should always be named create";
|
|
437
|
+
const ENSURE_ZUSTAND_SHALLOW_IMPORT_ARE_CONSISTENT = "default import from zustand/shallow should always be named shallow";
|
|
274
438
|
|
|
275
439
|
const toCamelCase = text => {
|
|
276
440
|
const capitalized = text.split(/[^0-9a-z]/i).map(part => `${part[0].toUpperCase()}${part.slice(1)}`).join("");
|
|
@@ -332,49 +496,6 @@
|
|
|
332
496
|
})
|
|
333
497
|
};
|
|
334
498
|
|
|
335
|
-
/**
|
|
336
|
-
* Returns a list of nodes that matches the pattern
|
|
337
|
-
* somewhere deep inside the given object-tree by
|
|
338
|
-
* partial object matching.
|
|
339
|
-
*
|
|
340
|
-
* @param {Object} obj the object tree to check
|
|
341
|
-
* @param {Object} pattern the pattern to match partially
|
|
342
|
-
* @param {Array} res list of nodes that matches the pattern
|
|
343
|
-
*/
|
|
344
|
-
|
|
345
|
-
const findMatchingNodesDeep = (obj, pattern, res = []) => {
|
|
346
|
-
if (typeof obj !== "object" || ramda.isNil(obj)) return res;
|
|
347
|
-
if (matches(pattern, obj)) return ramda.append(obj, res);
|
|
348
|
-
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
349
|
-
if (key === "parent") return acc;
|
|
350
|
-
return findMatchingNodesDeep(value, pattern, acc);
|
|
351
|
-
}, res);
|
|
352
|
-
};
|
|
353
|
-
/**
|
|
354
|
-
* Checks if any of the given pattern matches the object.
|
|
355
|
-
* @param {Object} obj The object tree to check.
|
|
356
|
-
* @param {Object[]} list The list of patterns to compare against.
|
|
357
|
-
* also @see matches
|
|
358
|
-
*/
|
|
359
|
-
|
|
360
|
-
const matchesAny = ramda.curry((list, obj) => list.some(matches(ramda.__, obj)));
|
|
361
|
-
/**
|
|
362
|
-
* Checks if the given pattern exists somewhere deep inside
|
|
363
|
-
* the given object-tree by partial object matching.
|
|
364
|
-
*
|
|
365
|
-
* @param {Object} obj the object tree to check
|
|
366
|
-
* @param {Object} pattern the pattern to match partially
|
|
367
|
-
*/
|
|
368
|
-
|
|
369
|
-
const patternExistsDeep = ramda.curry((pattern, obj) => {
|
|
370
|
-
if (typeof obj !== "object" || ramda.isNil(obj)) return false;
|
|
371
|
-
if (matches(pattern, obj)) return true;
|
|
372
|
-
return Object.entries(obj).some(([key, value]) => {
|
|
373
|
-
if (key === "parent") return false;
|
|
374
|
-
return patternExistsDeep(pattern, value);
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
|
|
378
499
|
const AWAIT_DECLARATION_PATTERN = {
|
|
379
500
|
type: TYPES.VARIABLE_DECLARATOR,
|
|
380
501
|
init: {
|
|
@@ -494,13 +615,13 @@
|
|
|
494
615
|
})
|
|
495
616
|
};
|
|
496
617
|
|
|
497
|
-
const SPECIAL_KEYS = ["home", "index", "show"]; // import routes from "
|
|
618
|
+
const SPECIAL_KEYS = ["home", "index", "show"]; // import routes from "routes"
|
|
498
619
|
|
|
499
620
|
const ROUTES_IMPORT_PATTERN = {
|
|
500
621
|
type: TYPES.IMPORT_DECLARATION,
|
|
501
622
|
source: {
|
|
502
623
|
type: TYPES.LITERAL,
|
|
503
|
-
value: matchesAny(["routes", "common/routes"])
|
|
624
|
+
value: matchesAny(["routes", "src/routes", "common/routes"])
|
|
504
625
|
},
|
|
505
626
|
specifiers: [{
|
|
506
627
|
type: TYPES.IMPORT_DEFAULT_SPECIFIER,
|
|
@@ -511,7 +632,7 @@
|
|
|
511
632
|
}]
|
|
512
633
|
}; // const routes = { home: "/" }, const routes = "/", const routes = ["/"] etc
|
|
513
634
|
|
|
514
|
-
const DECALARATION_PATTERN = {
|
|
635
|
+
const DECALARATION_PATTERN$1 = {
|
|
515
636
|
type: TYPES.VARIABLE_DECLARATION,
|
|
516
637
|
declarations: [{
|
|
517
638
|
type: TYPES.VARIABLE_DECLARATOR,
|
|
@@ -524,7 +645,7 @@
|
|
|
524
645
|
|
|
525
646
|
const OBJECT_DECALARATION_PATTERN = ramda.assocPath(["declarations", 0, "init"], {
|
|
526
647
|
type: TYPES.OBJECT_EXPRESSION
|
|
527
|
-
}, DECALARATION_PATTERN); // export const routes = { home: "/" }
|
|
648
|
+
}, DECALARATION_PATTERN$1); // export const routes = { home: "/" }
|
|
528
649
|
|
|
529
650
|
const EXPORT_NAMED_DECLARATION_PATTERN = {
|
|
530
651
|
type: TYPES.EXPORT_NAMED_DECLARATION,
|
|
@@ -643,7 +764,7 @@
|
|
|
643
764
|
},
|
|
644
765
|
create: context => ({
|
|
645
766
|
VariableDeclaration(node) {
|
|
646
|
-
if (matches(DECALARATION_PATTERN, node) && isRoutesImportPresent(context)) {
|
|
767
|
+
if (matches(DECALARATION_PATTERN$1, node) && isRoutesImportPresent(context)) {
|
|
647
768
|
context.report(node, ROUTES_HAS_ALREADY_BEEN_DECLARED);
|
|
648
769
|
}
|
|
649
770
|
},
|
|
@@ -665,14 +786,14 @@
|
|
|
665
786
|
|
|
666
787
|
const isInsideRoutesFile$1 = context => {
|
|
667
788
|
const filename = context.getFilename();
|
|
668
|
-
return
|
|
789
|
+
return ramda.any(ramda.endsWith(ramda.__, filename), ROUTES_FILE_PATHS);
|
|
669
790
|
};
|
|
670
791
|
|
|
671
792
|
var routesShouldBeDeclaredAndDefaultExported = {
|
|
672
793
|
meta: {
|
|
673
794
|
type: "problem",
|
|
674
795
|
docs: {
|
|
675
|
-
description: "
|
|
796
|
+
description: "routes.js file should declare a constant named routes and should be exported using default export"
|
|
676
797
|
}
|
|
677
798
|
},
|
|
678
799
|
create: context => ({
|
|
@@ -699,7 +820,7 @@
|
|
|
699
820
|
|
|
700
821
|
const isInsideRoutesFile = context => {
|
|
701
822
|
const filename = context.getFilename();
|
|
702
|
-
return
|
|
823
|
+
return ramda.any(ramda.endsWith(ramda.__, filename), ROUTES_FILE_PATHS);
|
|
703
824
|
};
|
|
704
825
|
|
|
705
826
|
const isParam = e => e === null || e === void 0 ? void 0 : e.startsWith(":");
|
|
@@ -753,7 +874,7 @@
|
|
|
753
874
|
},
|
|
754
875
|
create: context => ({
|
|
755
876
|
VariableDeclaration(node) {
|
|
756
|
-
if (isInsideRoutesFile(context) && matches(DECALARATION_PATTERN, node)) {
|
|
877
|
+
if (isInsideRoutesFile(context) && matches(DECALARATION_PATTERN$1, node)) {
|
|
757
878
|
const object = node.declarations[0].init;
|
|
758
879
|
checkObjectPath(context, object);
|
|
759
880
|
}
|
|
@@ -1009,7 +1130,7 @@
|
|
|
1009
1130
|
};
|
|
1010
1131
|
|
|
1011
1132
|
const CONSTANT_CASE_PATTERN = /^[A-Z0-9_]*$/;
|
|
1012
|
-
const CONSTANTS_FILES = [/.*constants.(js|jsx)$/i, /app\/javascript\/src\/common\/urls.js$/];
|
|
1133
|
+
const CONSTANTS_FILES = [/constants\//, /.*constants.(js|jsx)$/i, /app\/javascript\/src\/common\/urls.js$/];
|
|
1013
1134
|
const CONSTANT_DECALARATION_PATTERN = {
|
|
1014
1135
|
kind: "const",
|
|
1015
1136
|
declarations: [{
|
|
@@ -1081,106 +1202,52 @@
|
|
|
1081
1202
|
})
|
|
1082
1203
|
};
|
|
1083
1204
|
|
|
1084
|
-
const
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
fix: fixer => fixer.replaceText(node, toConstantCase(name))
|
|
1098
|
-
}]
|
|
1099
|
-
});
|
|
1100
|
-
};
|
|
1101
|
-
|
|
1102
|
-
const checkExportAndReport = ({
|
|
1103
|
-
context,
|
|
1104
|
-
exported,
|
|
1105
|
-
local,
|
|
1106
|
-
node,
|
|
1107
|
-
statement
|
|
1108
|
-
}) => {
|
|
1109
|
-
if (CONSTANT_CASE_PATTERN.test(exported.name)) return;
|
|
1110
|
-
context.report({
|
|
1111
|
-
node,
|
|
1112
|
-
message: useConstantCaseFor(exported.name),
|
|
1113
|
-
suggest: [{
|
|
1114
|
-
desc: `Replace ${getCode$1(context, node)} with ${toConstantCase(exported.name)}`,
|
|
1115
|
-
fix: fixer => {
|
|
1116
|
-
const newName = toConstantCase(exported.name);
|
|
1117
|
-
|
|
1118
|
-
if (local.name === exported.name) {
|
|
1119
|
-
return fixer.replaceText(statement, newName);
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
if (local.name === newName) {
|
|
1123
|
-
return fixer.replaceText(statement, local.name);
|
|
1124
|
-
}
|
|
1205
|
+
const ZUSTAND_CREATE_IMPORT_PATTERN = {
|
|
1206
|
+
specifiers: [{
|
|
1207
|
+
type: TYPES.IMPORT_DEFAULT_SPECIFIER,
|
|
1208
|
+
local: {
|
|
1209
|
+
type: TYPES.IDENTIFIER,
|
|
1210
|
+
name: name => name !== "create"
|
|
1211
|
+
}
|
|
1212
|
+
}],
|
|
1213
|
+
source: {
|
|
1214
|
+
type: TYPES.LITERAL,
|
|
1215
|
+
value: "zustand"
|
|
1216
|
+
}
|
|
1217
|
+
}; // import somethingOtherThan_shallow from "zustand/shallow";
|
|
1125
1218
|
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1219
|
+
const ZUSTAND_SHALLOW_IMPORT_PATTERN = {
|
|
1220
|
+
specifiers: [{
|
|
1221
|
+
type: TYPES.IMPORT_DEFAULT_SPECIFIER,
|
|
1222
|
+
local: {
|
|
1223
|
+
type: TYPES.IDENTIFIER,
|
|
1224
|
+
name: name => name !== "shallow"
|
|
1225
|
+
}
|
|
1226
|
+
}],
|
|
1227
|
+
source: {
|
|
1228
|
+
type: TYPES.LITERAL,
|
|
1229
|
+
value: "zustand/shallow"
|
|
1230
|
+
}
|
|
1130
1231
|
};
|
|
1131
1232
|
|
|
1132
|
-
var
|
|
1233
|
+
var ensureZustandImportNamesAreConsistent = {
|
|
1133
1234
|
meta: {
|
|
1134
|
-
type: "
|
|
1235
|
+
type: "error",
|
|
1135
1236
|
docs: {
|
|
1136
|
-
description: "
|
|
1137
|
-
}
|
|
1138
|
-
hasSuggestions: true
|
|
1237
|
+
description: "Throw error if zustand import names are not consistent"
|
|
1238
|
+
}
|
|
1139
1239
|
},
|
|
1140
1240
|
create: context => ({
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
if (((_node$declaration = node.declaration) === null || _node$declaration === void 0 ? void 0 : _node$declaration.kind) === "const") {
|
|
1147
|
-
var _node$declaration2;
|
|
1148
|
-
|
|
1149
|
-
(_node$declaration2 = node.declaration) === null || _node$declaration2 === void 0 ? void 0 : _node$declaration2.declarations.forEach(({
|
|
1150
|
-
id
|
|
1151
|
-
}) => {
|
|
1152
|
-
if (id.type !== TYPES.OBJECT_PATTERN) {
|
|
1153
|
-
checkCaseAndReport({
|
|
1154
|
-
context,
|
|
1155
|
-
name: id.name,
|
|
1156
|
-
node: id
|
|
1157
|
-
});
|
|
1158
|
-
return;
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
id.properties.forEach(statement => {
|
|
1162
|
-
checkExportAndReport({
|
|
1163
|
-
context,
|
|
1164
|
-
exported: statement.value,
|
|
1165
|
-
local: statement.key,
|
|
1166
|
-
node,
|
|
1167
|
-
statement
|
|
1168
|
-
});
|
|
1169
|
-
});
|
|
1241
|
+
ImportDeclaration(node) {
|
|
1242
|
+
if (matches(ZUSTAND_CREATE_IMPORT_PATTERN, node)) {
|
|
1243
|
+
context.report({
|
|
1244
|
+
node,
|
|
1245
|
+
message: ENSURE_ZUSTAND_CREATE_IMPORT_ARE_CONSISTENT
|
|
1170
1246
|
});
|
|
1171
|
-
} else {
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
local
|
|
1176
|
-
} = statement;
|
|
1177
|
-
checkExportAndReport({
|
|
1178
|
-
context,
|
|
1179
|
-
exported,
|
|
1180
|
-
local,
|
|
1181
|
-
node,
|
|
1182
|
-
statement
|
|
1183
|
-
});
|
|
1247
|
+
} else if (matches(ZUSTAND_SHALLOW_IMPORT_PATTERN, node)) {
|
|
1248
|
+
context.report({
|
|
1249
|
+
node,
|
|
1250
|
+
message: ENSURE_ZUSTAND_SHALLOW_IMPORT_ARE_CONSISTENT
|
|
1184
1251
|
});
|
|
1185
1252
|
}
|
|
1186
1253
|
}
|
|
@@ -1188,74 +1255,1555 @@
|
|
|
1188
1255
|
})
|
|
1189
1256
|
};
|
|
1190
1257
|
|
|
1191
|
-
const
|
|
1192
|
-
|
|
1193
|
-
type: TYPES.
|
|
1258
|
+
const storeImportPattern = () => ({
|
|
1259
|
+
specifiers: [{
|
|
1260
|
+
type: TYPES.IMPORT_DEFAULT_SPECIFIER,
|
|
1261
|
+
local: {
|
|
1262
|
+
type: TYPES.IDENTIFIER
|
|
1263
|
+
}
|
|
1264
|
+
}],
|
|
1265
|
+
source: {
|
|
1266
|
+
type: TYPES.LITERAL,
|
|
1267
|
+
value: "zustand"
|
|
1194
1268
|
}
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
|
|
1269
|
+
});
|
|
1270
|
+
|
|
1271
|
+
const DECALARATION_PATTERN = [{
|
|
1272
|
+
type: TYPES.VARIABLE_DECLARATOR,
|
|
1273
|
+
init: {
|
|
1274
|
+
type: TYPES.CALL_EXPRESSION,
|
|
1275
|
+
callee: {
|
|
1276
|
+
type: TYPES.IDENTIFIER,
|
|
1277
|
+
name: (name, root) => name === "create" && existsBy$1(storeImportPattern(), getAllImports(root))
|
|
1278
|
+
},
|
|
1279
|
+
optional: false
|
|
1198
1280
|
}
|
|
1199
1281
|
}];
|
|
1200
|
-
const
|
|
1201
|
-
type:
|
|
1202
|
-
|
|
1203
|
-
};
|
|
1204
|
-
const
|
|
1205
|
-
type: TYPES.MEMBER_EXPRESSION,
|
|
1206
|
-
object: {
|
|
1207
|
-
type: TYPES.IDENTIFIER,
|
|
1208
|
-
name: "globalProps"
|
|
1209
|
-
}
|
|
1210
|
-
};
|
|
1211
|
-
const GLOBALPROPS_REASSIGNMENT_PATTERN = {
|
|
1212
|
-
type: TYPES.IDENTIFIER,
|
|
1213
|
-
name: "globalProps"
|
|
1214
|
-
};
|
|
1282
|
+
const TYPE_ANNOTATION_COMMENT_PATTERN = [{
|
|
1283
|
+
type: "Block",
|
|
1284
|
+
value: "* @type {import(”neetocommons/react-utils”).ZustandStoreHook} "
|
|
1285
|
+
}]; // .....
|
|
1286
|
+
// const useCurrentUserStore = create(....);
|
|
1215
1287
|
|
|
1216
|
-
const
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1288
|
+
const ZUSTAND_STORE_CREATE_PATTERN = {
|
|
1289
|
+
kind: "const",
|
|
1290
|
+
declarations: DECALARATION_PATTERN,
|
|
1291
|
+
parent: {
|
|
1292
|
+
type: TYPES.PROGRAM,
|
|
1293
|
+
comments: comments => !matches(TYPE_ANNOTATION_COMMENT_PATTERN, comments)
|
|
1221
1294
|
}
|
|
1222
1295
|
};
|
|
1223
1296
|
|
|
1224
|
-
var
|
|
1297
|
+
var ensureZustandStoresAreTypeAnnotated = {
|
|
1225
1298
|
meta: {
|
|
1226
|
-
type: "
|
|
1299
|
+
type: "error",
|
|
1227
1300
|
docs: {
|
|
1228
|
-
description: "
|
|
1301
|
+
description: "Throw error if zustand stores are not type annotated via JSDoc comments"
|
|
1229
1302
|
}
|
|
1230
1303
|
},
|
|
1231
1304
|
create: context => ({
|
|
1232
|
-
|
|
1233
|
-
if (!
|
|
1234
|
-
|
|
1235
|
-
|
|
1305
|
+
VariableDeclaration(node) {
|
|
1306
|
+
if (!matches(ZUSTAND_STORE_CREATE_PATTERN, node)) return;
|
|
1307
|
+
context.report({
|
|
1308
|
+
node,
|
|
1309
|
+
message: ENSURE_ZUSTAND_STORES_ARE_TYPE_ANNOTATED
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1236
1312
|
|
|
1237
|
-
AssignmentExpression: node => checkAssignment(context, node.right)
|
|
1238
1313
|
})
|
|
1239
1314
|
};
|
|
1240
1315
|
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1316
|
+
const isWindows = typeof process === 'object' &&
|
|
1317
|
+
process &&
|
|
1318
|
+
process.platform === 'win32';
|
|
1319
|
+
var path$1 = isWindows ? { sep: '\\' } : { sep: '/' };
|
|
1320
|
+
|
|
1321
|
+
var balancedMatch = balanced$1;
|
|
1322
|
+
function balanced$1(a, b, str) {
|
|
1323
|
+
if (a instanceof RegExp) a = maybeMatch(a, str);
|
|
1324
|
+
if (b instanceof RegExp) b = maybeMatch(b, str);
|
|
1325
|
+
|
|
1326
|
+
var r = range(a, b, str);
|
|
1327
|
+
|
|
1328
|
+
return r && {
|
|
1329
|
+
start: r[0],
|
|
1330
|
+
end: r[1],
|
|
1331
|
+
pre: str.slice(0, r[0]),
|
|
1332
|
+
body: str.slice(r[0] + a.length, r[1]),
|
|
1333
|
+
post: str.slice(r[1] + b.length)
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
function maybeMatch(reg, str) {
|
|
1338
|
+
var m = str.match(reg);
|
|
1339
|
+
return m ? m[0] : null;
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
balanced$1.range = range;
|
|
1343
|
+
function range(a, b, str) {
|
|
1344
|
+
var begs, beg, left, right, result;
|
|
1345
|
+
var ai = str.indexOf(a);
|
|
1346
|
+
var bi = str.indexOf(b, ai + 1);
|
|
1347
|
+
var i = ai;
|
|
1348
|
+
|
|
1349
|
+
if (ai >= 0 && bi > 0) {
|
|
1350
|
+
if(a===b) {
|
|
1351
|
+
return [ai, bi];
|
|
1352
|
+
}
|
|
1353
|
+
begs = [];
|
|
1354
|
+
left = str.length;
|
|
1355
|
+
|
|
1356
|
+
while (i >= 0 && !result) {
|
|
1357
|
+
if (i == ai) {
|
|
1358
|
+
begs.push(i);
|
|
1359
|
+
ai = str.indexOf(a, i + 1);
|
|
1360
|
+
} else if (begs.length == 1) {
|
|
1361
|
+
result = [ begs.pop(), bi ];
|
|
1362
|
+
} else {
|
|
1363
|
+
beg = begs.pop();
|
|
1364
|
+
if (beg < left) {
|
|
1365
|
+
left = beg;
|
|
1366
|
+
right = bi;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
bi = str.indexOf(b, i + 1);
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
i = ai < bi && ai >= 0 ? ai : bi;
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
if (begs.length) {
|
|
1376
|
+
result = [ left, right ];
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
return result;
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
var balanced = balancedMatch;
|
|
1384
|
+
|
|
1385
|
+
var braceExpansion = expandTop;
|
|
1386
|
+
|
|
1387
|
+
var escSlash = '\0SLASH'+Math.random()+'\0';
|
|
1388
|
+
var escOpen = '\0OPEN'+Math.random()+'\0';
|
|
1389
|
+
var escClose = '\0CLOSE'+Math.random()+'\0';
|
|
1390
|
+
var escComma = '\0COMMA'+Math.random()+'\0';
|
|
1391
|
+
var escPeriod = '\0PERIOD'+Math.random()+'\0';
|
|
1392
|
+
|
|
1393
|
+
function numeric(str) {
|
|
1394
|
+
return parseInt(str, 10) == str
|
|
1395
|
+
? parseInt(str, 10)
|
|
1396
|
+
: str.charCodeAt(0);
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
function escapeBraces(str) {
|
|
1400
|
+
return str.split('\\\\').join(escSlash)
|
|
1401
|
+
.split('\\{').join(escOpen)
|
|
1402
|
+
.split('\\}').join(escClose)
|
|
1403
|
+
.split('\\,').join(escComma)
|
|
1404
|
+
.split('\\.').join(escPeriod);
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
function unescapeBraces(str) {
|
|
1408
|
+
return str.split(escSlash).join('\\')
|
|
1409
|
+
.split(escOpen).join('{')
|
|
1410
|
+
.split(escClose).join('}')
|
|
1411
|
+
.split(escComma).join(',')
|
|
1412
|
+
.split(escPeriod).join('.');
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
|
|
1416
|
+
// Basically just str.split(","), but handling cases
|
|
1417
|
+
// where we have nested braced sections, which should be
|
|
1418
|
+
// treated as individual members, like {a,{b,c},d}
|
|
1419
|
+
function parseCommaParts(str) {
|
|
1420
|
+
if (!str)
|
|
1421
|
+
return [''];
|
|
1422
|
+
|
|
1423
|
+
var parts = [];
|
|
1424
|
+
var m = balanced('{', '}', str);
|
|
1425
|
+
|
|
1426
|
+
if (!m)
|
|
1427
|
+
return str.split(',');
|
|
1428
|
+
|
|
1429
|
+
var pre = m.pre;
|
|
1430
|
+
var body = m.body;
|
|
1431
|
+
var post = m.post;
|
|
1432
|
+
var p = pre.split(',');
|
|
1433
|
+
|
|
1434
|
+
p[p.length-1] += '{' + body + '}';
|
|
1435
|
+
var postParts = parseCommaParts(post);
|
|
1436
|
+
if (post.length) {
|
|
1437
|
+
p[p.length-1] += postParts.shift();
|
|
1438
|
+
p.push.apply(p, postParts);
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
parts.push.apply(parts, p);
|
|
1442
|
+
|
|
1443
|
+
return parts;
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
function expandTop(str) {
|
|
1447
|
+
if (!str)
|
|
1448
|
+
return [];
|
|
1449
|
+
|
|
1450
|
+
// I don't know why Bash 4.3 does this, but it does.
|
|
1451
|
+
// Anything starting with {} will have the first two bytes preserved
|
|
1452
|
+
// but *only* at the top level, so {},a}b will not expand to anything,
|
|
1453
|
+
// but a{},b}c will be expanded to [a}c,abc].
|
|
1454
|
+
// One could argue that this is a bug in Bash, but since the goal of
|
|
1455
|
+
// this module is to match Bash's rules, we escape a leading {}
|
|
1456
|
+
if (str.substr(0, 2) === '{}') {
|
|
1457
|
+
str = '\\{\\}' + str.substr(2);
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
return expand$1(escapeBraces(str), true).map(unescapeBraces);
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
function embrace(str) {
|
|
1464
|
+
return '{' + str + '}';
|
|
1465
|
+
}
|
|
1466
|
+
function isPadded(el) {
|
|
1467
|
+
return /^-?0\d/.test(el);
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
function lte(i, y) {
|
|
1471
|
+
return i <= y;
|
|
1472
|
+
}
|
|
1473
|
+
function gte(i, y) {
|
|
1474
|
+
return i >= y;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
function expand$1(str, isTop) {
|
|
1478
|
+
var expansions = [];
|
|
1479
|
+
|
|
1480
|
+
var m = balanced('{', '}', str);
|
|
1481
|
+
if (!m) return [str];
|
|
1482
|
+
|
|
1483
|
+
// no need to expand pre, since it is guaranteed to be free of brace-sets
|
|
1484
|
+
var pre = m.pre;
|
|
1485
|
+
var post = m.post.length
|
|
1486
|
+
? expand$1(m.post, false)
|
|
1487
|
+
: [''];
|
|
1488
|
+
|
|
1489
|
+
if (/\$$/.test(m.pre)) {
|
|
1490
|
+
for (var k = 0; k < post.length; k++) {
|
|
1491
|
+
var expansion = pre+ '{' + m.body + '}' + post[k];
|
|
1492
|
+
expansions.push(expansion);
|
|
1493
|
+
}
|
|
1494
|
+
} else {
|
|
1495
|
+
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
1496
|
+
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
1497
|
+
var isSequence = isNumericSequence || isAlphaSequence;
|
|
1498
|
+
var isOptions = m.body.indexOf(',') >= 0;
|
|
1499
|
+
if (!isSequence && !isOptions) {
|
|
1500
|
+
// {a},b}
|
|
1501
|
+
if (m.post.match(/,.*\}/)) {
|
|
1502
|
+
str = m.pre + '{' + m.body + escClose + m.post;
|
|
1503
|
+
return expand$1(str);
|
|
1504
|
+
}
|
|
1505
|
+
return [str];
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
var n;
|
|
1509
|
+
if (isSequence) {
|
|
1510
|
+
n = m.body.split(/\.\./);
|
|
1511
|
+
} else {
|
|
1512
|
+
n = parseCommaParts(m.body);
|
|
1513
|
+
if (n.length === 1) {
|
|
1514
|
+
// x{{a,b}}y ==> x{a}y x{b}y
|
|
1515
|
+
n = expand$1(n[0], false).map(embrace);
|
|
1516
|
+
if (n.length === 1) {
|
|
1517
|
+
return post.map(function(p) {
|
|
1518
|
+
return m.pre + n[0] + p;
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
// at this point, n is the parts, and we know it's not a comma set
|
|
1525
|
+
// with a single entry.
|
|
1526
|
+
var N;
|
|
1527
|
+
|
|
1528
|
+
if (isSequence) {
|
|
1529
|
+
var x = numeric(n[0]);
|
|
1530
|
+
var y = numeric(n[1]);
|
|
1531
|
+
var width = Math.max(n[0].length, n[1].length);
|
|
1532
|
+
var incr = n.length == 3
|
|
1533
|
+
? Math.abs(numeric(n[2]))
|
|
1534
|
+
: 1;
|
|
1535
|
+
var test = lte;
|
|
1536
|
+
var reverse = y < x;
|
|
1537
|
+
if (reverse) {
|
|
1538
|
+
incr *= -1;
|
|
1539
|
+
test = gte;
|
|
1540
|
+
}
|
|
1541
|
+
var pad = n.some(isPadded);
|
|
1542
|
+
|
|
1543
|
+
N = [];
|
|
1544
|
+
|
|
1545
|
+
for (var i = x; test(i, y); i += incr) {
|
|
1546
|
+
var c;
|
|
1547
|
+
if (isAlphaSequence) {
|
|
1548
|
+
c = String.fromCharCode(i);
|
|
1549
|
+
if (c === '\\')
|
|
1550
|
+
c = '';
|
|
1551
|
+
} else {
|
|
1552
|
+
c = String(i);
|
|
1553
|
+
if (pad) {
|
|
1554
|
+
var need = width - c.length;
|
|
1555
|
+
if (need > 0) {
|
|
1556
|
+
var z = new Array(need + 1).join('0');
|
|
1557
|
+
if (i < 0)
|
|
1558
|
+
c = '-' + z + c.slice(1);
|
|
1559
|
+
else
|
|
1560
|
+
c = z + c;
|
|
1561
|
+
}
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
N.push(c);
|
|
1565
|
+
}
|
|
1566
|
+
} else {
|
|
1567
|
+
N = [];
|
|
1568
|
+
|
|
1569
|
+
for (var j = 0; j < n.length; j++) {
|
|
1570
|
+
N.push.apply(N, expand$1(n[j], false));
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
for (var j = 0; j < N.length; j++) {
|
|
1575
|
+
for (var k = 0; k < post.length; k++) {
|
|
1576
|
+
var expansion = pre + N[j] + post[k];
|
|
1577
|
+
if (!isTop || isSequence || expansion)
|
|
1578
|
+
expansions.push(expansion);
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
return expansions;
|
|
1584
|
+
}
|
|
1585
|
+
|
|
1586
|
+
const minimatch = minimatch_1 = (p, pattern, options = {}) => {
|
|
1587
|
+
assertValidPattern(pattern);
|
|
1588
|
+
|
|
1589
|
+
// shortcut: comments match nothing.
|
|
1590
|
+
if (!options.nocomment && pattern.charAt(0) === '#') {
|
|
1591
|
+
return false
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
return new Minimatch(pattern, options).match(p)
|
|
1595
|
+
};
|
|
1596
|
+
|
|
1597
|
+
var minimatch_1 = minimatch;
|
|
1598
|
+
|
|
1599
|
+
const path = path$1;
|
|
1600
|
+
minimatch.sep = path.sep;
|
|
1601
|
+
|
|
1602
|
+
const GLOBSTAR = Symbol('globstar **');
|
|
1603
|
+
minimatch.GLOBSTAR = GLOBSTAR;
|
|
1604
|
+
const expand = braceExpansion;
|
|
1605
|
+
|
|
1606
|
+
const plTypes = {
|
|
1607
|
+
'!': { open: '(?:(?!(?:', close: '))[^/]*?)'},
|
|
1608
|
+
'?': { open: '(?:', close: ')?' },
|
|
1609
|
+
'+': { open: '(?:', close: ')+' },
|
|
1610
|
+
'*': { open: '(?:', close: ')*' },
|
|
1611
|
+
'@': { open: '(?:', close: ')' }
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1614
|
+
// any single thing other than /
|
|
1615
|
+
// don't need to escape / when using new RegExp()
|
|
1616
|
+
const qmark = '[^/]';
|
|
1617
|
+
|
|
1618
|
+
// * => any number of characters
|
|
1619
|
+
const star = qmark + '*?';
|
|
1620
|
+
|
|
1621
|
+
// ** when dots are allowed. Anything goes, except .. and .
|
|
1622
|
+
// not (^ or / followed by one or two dots followed by $ or /),
|
|
1623
|
+
// followed by anything, any number of times.
|
|
1624
|
+
const twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?';
|
|
1625
|
+
|
|
1626
|
+
// not a ^ or / followed by a dot,
|
|
1627
|
+
// followed by anything, any number of times.
|
|
1628
|
+
const twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?';
|
|
1629
|
+
|
|
1630
|
+
// "abc" -> { a:true, b:true, c:true }
|
|
1631
|
+
const charSet = s => s.split('').reduce((set, c) => {
|
|
1632
|
+
set[c] = true;
|
|
1633
|
+
return set
|
|
1634
|
+
}, {});
|
|
1635
|
+
|
|
1636
|
+
// characters that need to be escaped in RegExp.
|
|
1637
|
+
const reSpecials = charSet('().*{}+?[]^$\\!');
|
|
1638
|
+
|
|
1639
|
+
// characters that indicate we have to add the pattern start
|
|
1640
|
+
const addPatternStartSet = charSet('[.(');
|
|
1641
|
+
|
|
1642
|
+
// normalizes slashes.
|
|
1643
|
+
const slashSplit = /\/+/;
|
|
1644
|
+
|
|
1645
|
+
minimatch.filter = (pattern, options = {}) =>
|
|
1646
|
+
(p, i, list) => minimatch(p, pattern, options);
|
|
1647
|
+
|
|
1648
|
+
const ext = (a, b = {}) => {
|
|
1649
|
+
const t = {};
|
|
1650
|
+
Object.keys(a).forEach(k => t[k] = a[k]);
|
|
1651
|
+
Object.keys(b).forEach(k => t[k] = b[k]);
|
|
1652
|
+
return t
|
|
1653
|
+
};
|
|
1654
|
+
|
|
1655
|
+
minimatch.defaults = def => {
|
|
1656
|
+
if (!def || typeof def !== 'object' || !Object.keys(def).length) {
|
|
1657
|
+
return minimatch
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
const orig = minimatch;
|
|
1661
|
+
|
|
1662
|
+
const m = (p, pattern, options) => orig(p, pattern, ext(def, options));
|
|
1663
|
+
m.Minimatch = class Minimatch extends orig.Minimatch {
|
|
1664
|
+
constructor (pattern, options) {
|
|
1665
|
+
super(pattern, ext(def, options));
|
|
1666
|
+
}
|
|
1667
|
+
};
|
|
1668
|
+
m.Minimatch.defaults = options => orig.defaults(ext(def, options)).Minimatch;
|
|
1669
|
+
m.filter = (pattern, options) => orig.filter(pattern, ext(def, options));
|
|
1670
|
+
m.defaults = options => orig.defaults(ext(def, options));
|
|
1671
|
+
m.makeRe = (pattern, options) => orig.makeRe(pattern, ext(def, options));
|
|
1672
|
+
m.braceExpand = (pattern, options) => orig.braceExpand(pattern, ext(def, options));
|
|
1673
|
+
m.match = (list, pattern, options) => orig.match(list, pattern, ext(def, options));
|
|
1674
|
+
|
|
1675
|
+
return m
|
|
1676
|
+
};
|
|
1677
|
+
|
|
1678
|
+
|
|
1679
|
+
|
|
1680
|
+
|
|
1681
|
+
|
|
1682
|
+
// Brace expansion:
|
|
1683
|
+
// a{b,c}d -> abd acd
|
|
1684
|
+
// a{b,}c -> abc ac
|
|
1685
|
+
// a{0..3}d -> a0d a1d a2d a3d
|
|
1686
|
+
// a{b,c{d,e}f}g -> abg acdfg acefg
|
|
1687
|
+
// a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
|
|
1688
|
+
//
|
|
1689
|
+
// Invalid sets are not expanded.
|
|
1690
|
+
// a{2..}b -> a{2..}b
|
|
1691
|
+
// a{b}c -> a{b}c
|
|
1692
|
+
minimatch.braceExpand = (pattern, options) => braceExpand(pattern, options);
|
|
1693
|
+
|
|
1694
|
+
const braceExpand = (pattern, options = {}) => {
|
|
1695
|
+
assertValidPattern(pattern);
|
|
1696
|
+
|
|
1697
|
+
// Thanks to Yeting Li <https://github.com/yetingli> for
|
|
1698
|
+
// improving this regexp to avoid a ReDOS vulnerability.
|
|
1699
|
+
if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
|
|
1700
|
+
// shortcut. no need to expand.
|
|
1701
|
+
return [pattern]
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
return expand(pattern)
|
|
1705
|
+
};
|
|
1706
|
+
|
|
1707
|
+
const MAX_PATTERN_LENGTH = 1024 * 64;
|
|
1708
|
+
const assertValidPattern = pattern => {
|
|
1709
|
+
if (typeof pattern !== 'string') {
|
|
1710
|
+
throw new TypeError('invalid pattern')
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
if (pattern.length > MAX_PATTERN_LENGTH) {
|
|
1714
|
+
throw new TypeError('pattern is too long')
|
|
1715
|
+
}
|
|
1716
|
+
};
|
|
1717
|
+
|
|
1718
|
+
// parse a component of the expanded set.
|
|
1719
|
+
// At this point, no pattern may contain "/" in it
|
|
1720
|
+
// so we're going to return a 2d array, where each entry is the full
|
|
1721
|
+
// pattern, split on '/', and then turned into a regular expression.
|
|
1722
|
+
// A regexp is made at the end which joins each array with an
|
|
1723
|
+
// escaped /, and another full one which joins each regexp with |.
|
|
1724
|
+
//
|
|
1725
|
+
// Following the lead of Bash 4.1, note that "**" only has special meaning
|
|
1726
|
+
// when it is the *only* thing in a path portion. Otherwise, any series
|
|
1727
|
+
// of * is equivalent to a single *. Globstar behavior is enabled by
|
|
1728
|
+
// default, and can be disabled by setting options.noglobstar.
|
|
1729
|
+
const SUBPARSE = Symbol('subparse');
|
|
1730
|
+
|
|
1731
|
+
minimatch.makeRe = (pattern, options) =>
|
|
1732
|
+
new Minimatch(pattern, options || {}).makeRe();
|
|
1733
|
+
|
|
1734
|
+
minimatch.match = (list, pattern, options = {}) => {
|
|
1735
|
+
const mm = new Minimatch(pattern, options);
|
|
1736
|
+
list = list.filter(f => mm.match(f));
|
|
1737
|
+
if (mm.options.nonull && !list.length) {
|
|
1738
|
+
list.push(pattern);
|
|
1739
|
+
}
|
|
1740
|
+
return list
|
|
1741
|
+
};
|
|
1742
|
+
|
|
1743
|
+
// replace stuff like \* with *
|
|
1744
|
+
const globUnescape = s => s.replace(/\\(.)/g, '$1');
|
|
1745
|
+
const regExpEscape = s => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
|
1746
|
+
|
|
1747
|
+
class Minimatch {
|
|
1748
|
+
constructor (pattern, options) {
|
|
1749
|
+
assertValidPattern(pattern);
|
|
1750
|
+
|
|
1751
|
+
if (!options) options = {};
|
|
1752
|
+
|
|
1753
|
+
this.options = options;
|
|
1754
|
+
this.set = [];
|
|
1755
|
+
this.pattern = pattern;
|
|
1756
|
+
this.windowsPathsNoEscape = !!options.windowsPathsNoEscape ||
|
|
1757
|
+
options.allowWindowsEscape === false;
|
|
1758
|
+
if (this.windowsPathsNoEscape) {
|
|
1759
|
+
this.pattern = this.pattern.replace(/\\/g, '/');
|
|
1760
|
+
}
|
|
1761
|
+
this.regexp = null;
|
|
1762
|
+
this.negate = false;
|
|
1763
|
+
this.comment = false;
|
|
1764
|
+
this.empty = false;
|
|
1765
|
+
this.partial = !!options.partial;
|
|
1766
|
+
|
|
1767
|
+
// make the set of regexps etc.
|
|
1768
|
+
this.make();
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
debug () {}
|
|
1772
|
+
|
|
1773
|
+
make () {
|
|
1774
|
+
const pattern = this.pattern;
|
|
1775
|
+
const options = this.options;
|
|
1776
|
+
|
|
1777
|
+
// empty patterns and comments match nothing.
|
|
1778
|
+
if (!options.nocomment && pattern.charAt(0) === '#') {
|
|
1779
|
+
this.comment = true;
|
|
1780
|
+
return
|
|
1781
|
+
}
|
|
1782
|
+
if (!pattern) {
|
|
1783
|
+
this.empty = true;
|
|
1784
|
+
return
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
// step 1: figure out negation, etc.
|
|
1788
|
+
this.parseNegate();
|
|
1789
|
+
|
|
1790
|
+
// step 2: expand braces
|
|
1791
|
+
let set = this.globSet = this.braceExpand();
|
|
1792
|
+
|
|
1793
|
+
if (options.debug) this.debug = (...args) => console.error(...args);
|
|
1794
|
+
|
|
1795
|
+
this.debug(this.pattern, set);
|
|
1796
|
+
|
|
1797
|
+
// step 3: now we have a set, so turn each one into a series of path-portion
|
|
1798
|
+
// matching patterns.
|
|
1799
|
+
// These will be regexps, except in the case of "**", which is
|
|
1800
|
+
// set to the GLOBSTAR object for globstar behavior,
|
|
1801
|
+
// and will not contain any / characters
|
|
1802
|
+
set = this.globParts = set.map(s => s.split(slashSplit));
|
|
1803
|
+
|
|
1804
|
+
this.debug(this.pattern, set);
|
|
1805
|
+
|
|
1806
|
+
// glob --> regexps
|
|
1807
|
+
set = set.map((s, si, set) => s.map(this.parse, this));
|
|
1808
|
+
|
|
1809
|
+
this.debug(this.pattern, set);
|
|
1810
|
+
|
|
1811
|
+
// filter out everything that didn't compile properly.
|
|
1812
|
+
set = set.filter(s => s.indexOf(false) === -1);
|
|
1813
|
+
|
|
1814
|
+
this.debug(this.pattern, set);
|
|
1815
|
+
|
|
1816
|
+
this.set = set;
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
parseNegate () {
|
|
1820
|
+
if (this.options.nonegate) return
|
|
1821
|
+
|
|
1822
|
+
const pattern = this.pattern;
|
|
1823
|
+
let negate = false;
|
|
1824
|
+
let negateOffset = 0;
|
|
1825
|
+
|
|
1826
|
+
for (let i = 0; i < pattern.length && pattern.charAt(i) === '!'; i++) {
|
|
1827
|
+
negate = !negate;
|
|
1828
|
+
negateOffset++;
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
if (negateOffset) this.pattern = pattern.substr(negateOffset);
|
|
1832
|
+
this.negate = negate;
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
// set partial to true to test if, for example,
|
|
1836
|
+
// "/a/b" matches the start of "/*/b/*/d"
|
|
1837
|
+
// Partial means, if you run out of file before you run
|
|
1838
|
+
// out of pattern, then that's fine, as long as all
|
|
1839
|
+
// the parts match.
|
|
1840
|
+
matchOne (file, pattern, partial) {
|
|
1841
|
+
var options = this.options;
|
|
1842
|
+
|
|
1843
|
+
this.debug('matchOne',
|
|
1844
|
+
{ 'this': this, file: file, pattern: pattern });
|
|
1845
|
+
|
|
1846
|
+
this.debug('matchOne', file.length, pattern.length);
|
|
1847
|
+
|
|
1848
|
+
for (var fi = 0,
|
|
1849
|
+
pi = 0,
|
|
1850
|
+
fl = file.length,
|
|
1851
|
+
pl = pattern.length
|
|
1852
|
+
; (fi < fl) && (pi < pl)
|
|
1853
|
+
; fi++, pi++) {
|
|
1854
|
+
this.debug('matchOne loop');
|
|
1855
|
+
var p = pattern[pi];
|
|
1856
|
+
var f = file[fi];
|
|
1857
|
+
|
|
1858
|
+
this.debug(pattern, p, f);
|
|
1859
|
+
|
|
1860
|
+
// should be impossible.
|
|
1861
|
+
// some invalid regexp stuff in the set.
|
|
1862
|
+
/* istanbul ignore if */
|
|
1863
|
+
if (p === false) return false
|
|
1864
|
+
|
|
1865
|
+
if (p === GLOBSTAR) {
|
|
1866
|
+
this.debug('GLOBSTAR', [pattern, p, f]);
|
|
1867
|
+
|
|
1868
|
+
// "**"
|
|
1869
|
+
// a/**/b/**/c would match the following:
|
|
1870
|
+
// a/b/x/y/z/c
|
|
1871
|
+
// a/x/y/z/b/c
|
|
1872
|
+
// a/b/x/b/x/c
|
|
1873
|
+
// a/b/c
|
|
1874
|
+
// To do this, take the rest of the pattern after
|
|
1875
|
+
// the **, and see if it would match the file remainder.
|
|
1876
|
+
// If so, return success.
|
|
1877
|
+
// If not, the ** "swallows" a segment, and try again.
|
|
1878
|
+
// This is recursively awful.
|
|
1879
|
+
//
|
|
1880
|
+
// a/**/b/**/c matching a/b/x/y/z/c
|
|
1881
|
+
// - a matches a
|
|
1882
|
+
// - doublestar
|
|
1883
|
+
// - matchOne(b/x/y/z/c, b/**/c)
|
|
1884
|
+
// - b matches b
|
|
1885
|
+
// - doublestar
|
|
1886
|
+
// - matchOne(x/y/z/c, c) -> no
|
|
1887
|
+
// - matchOne(y/z/c, c) -> no
|
|
1888
|
+
// - matchOne(z/c, c) -> no
|
|
1889
|
+
// - matchOne(c, c) yes, hit
|
|
1890
|
+
var fr = fi;
|
|
1891
|
+
var pr = pi + 1;
|
|
1892
|
+
if (pr === pl) {
|
|
1893
|
+
this.debug('** at the end');
|
|
1894
|
+
// a ** at the end will just swallow the rest.
|
|
1895
|
+
// We have found a match.
|
|
1896
|
+
// however, it will not swallow /.x, unless
|
|
1897
|
+
// options.dot is set.
|
|
1898
|
+
// . and .. are *never* matched by **, for explosively
|
|
1899
|
+
// exponential reasons.
|
|
1900
|
+
for (; fi < fl; fi++) {
|
|
1901
|
+
if (file[fi] === '.' || file[fi] === '..' ||
|
|
1902
|
+
(!options.dot && file[fi].charAt(0) === '.')) return false
|
|
1903
|
+
}
|
|
1904
|
+
return true
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
// ok, let's see if we can swallow whatever we can.
|
|
1908
|
+
while (fr < fl) {
|
|
1909
|
+
var swallowee = file[fr];
|
|
1910
|
+
|
|
1911
|
+
this.debug('\nglobstar while', file, fr, pattern, pr, swallowee);
|
|
1912
|
+
|
|
1913
|
+
// XXX remove this slice. Just pass the start index.
|
|
1914
|
+
if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
|
|
1915
|
+
this.debug('globstar found match!', fr, fl, swallowee);
|
|
1916
|
+
// found a match.
|
|
1917
|
+
return true
|
|
1918
|
+
} else {
|
|
1919
|
+
// can't swallow "." or ".." ever.
|
|
1920
|
+
// can only swallow ".foo" when explicitly asked.
|
|
1921
|
+
if (swallowee === '.' || swallowee === '..' ||
|
|
1922
|
+
(!options.dot && swallowee.charAt(0) === '.')) {
|
|
1923
|
+
this.debug('dot detected!', file, fr, pattern, pr);
|
|
1924
|
+
break
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
// ** swallows a segment, and continue.
|
|
1928
|
+
this.debug('globstar swallow a segment, and continue');
|
|
1929
|
+
fr++;
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
// no match was found.
|
|
1934
|
+
// However, in partial mode, we can't say this is necessarily over.
|
|
1935
|
+
// If there's more *pattern* left, then
|
|
1936
|
+
/* istanbul ignore if */
|
|
1937
|
+
if (partial) {
|
|
1938
|
+
// ran out of file
|
|
1939
|
+
this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
|
|
1940
|
+
if (fr === fl) return true
|
|
1941
|
+
}
|
|
1942
|
+
return false
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
// something other than **
|
|
1946
|
+
// non-magic patterns just have to match exactly
|
|
1947
|
+
// patterns with magic have been turned into regexps.
|
|
1948
|
+
var hit;
|
|
1949
|
+
if (typeof p === 'string') {
|
|
1950
|
+
hit = f === p;
|
|
1951
|
+
this.debug('string match', p, f, hit);
|
|
1952
|
+
} else {
|
|
1953
|
+
hit = f.match(p);
|
|
1954
|
+
this.debug('pattern match', p, f, hit);
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
if (!hit) return false
|
|
1958
|
+
}
|
|
1959
|
+
|
|
1960
|
+
// Note: ending in / means that we'll get a final ""
|
|
1961
|
+
// at the end of the pattern. This can only match a
|
|
1962
|
+
// corresponding "" at the end of the file.
|
|
1963
|
+
// If the file ends in /, then it can only match a
|
|
1964
|
+
// a pattern that ends in /, unless the pattern just
|
|
1965
|
+
// doesn't have any more for it. But, a/b/ should *not*
|
|
1966
|
+
// match "a/b/*", even though "" matches against the
|
|
1967
|
+
// [^/]*? pattern, except in partial mode, where it might
|
|
1968
|
+
// simply not be reached yet.
|
|
1969
|
+
// However, a/b/ should still satisfy a/*
|
|
1970
|
+
|
|
1971
|
+
// now either we fell off the end of the pattern, or we're done.
|
|
1972
|
+
if (fi === fl && pi === pl) {
|
|
1973
|
+
// ran out of pattern and filename at the same time.
|
|
1974
|
+
// an exact hit!
|
|
1975
|
+
return true
|
|
1976
|
+
} else if (fi === fl) {
|
|
1977
|
+
// ran out of file, but still had pattern left.
|
|
1978
|
+
// this is ok if we're doing the match as part of
|
|
1979
|
+
// a glob fs traversal.
|
|
1980
|
+
return partial
|
|
1981
|
+
} else /* istanbul ignore else */ if (pi === pl) {
|
|
1982
|
+
// ran out of pattern, still have file left.
|
|
1983
|
+
// this is only acceptable if we're on the very last
|
|
1984
|
+
// empty segment of a file with a trailing slash.
|
|
1985
|
+
// a/* should match a/b/
|
|
1986
|
+
return (fi === fl - 1) && (file[fi] === '')
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
// should be unreachable.
|
|
1990
|
+
/* istanbul ignore next */
|
|
1991
|
+
throw new Error('wtf?')
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
braceExpand () {
|
|
1995
|
+
return braceExpand(this.pattern, this.options)
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
parse (pattern, isSub) {
|
|
1999
|
+
assertValidPattern(pattern);
|
|
2000
|
+
|
|
2001
|
+
const options = this.options;
|
|
2002
|
+
|
|
2003
|
+
// shortcuts
|
|
2004
|
+
if (pattern === '**') {
|
|
2005
|
+
if (!options.noglobstar)
|
|
2006
|
+
return GLOBSTAR
|
|
2007
|
+
else
|
|
2008
|
+
pattern = '*';
|
|
2009
|
+
}
|
|
2010
|
+
if (pattern === '') return ''
|
|
2011
|
+
|
|
2012
|
+
let re = '';
|
|
2013
|
+
let hasMagic = !!options.nocase;
|
|
2014
|
+
let escaping = false;
|
|
2015
|
+
// ? => one single character
|
|
2016
|
+
const patternListStack = [];
|
|
2017
|
+
const negativeLists = [];
|
|
2018
|
+
let stateChar;
|
|
2019
|
+
let inClass = false;
|
|
2020
|
+
let reClassStart = -1;
|
|
2021
|
+
let classStart = -1;
|
|
2022
|
+
let cs;
|
|
2023
|
+
let pl;
|
|
2024
|
+
let sp;
|
|
2025
|
+
// . and .. never match anything that doesn't start with .,
|
|
2026
|
+
// even when options.dot is set.
|
|
2027
|
+
const patternStart = pattern.charAt(0) === '.' ? '' // anything
|
|
2028
|
+
// not (start or / followed by . or .. followed by / or end)
|
|
2029
|
+
: options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))'
|
|
2030
|
+
: '(?!\\.)';
|
|
2031
|
+
|
|
2032
|
+
const clearStateChar = () => {
|
|
2033
|
+
if (stateChar) {
|
|
2034
|
+
// we had some state-tracking character
|
|
2035
|
+
// that wasn't consumed by this pass.
|
|
2036
|
+
switch (stateChar) {
|
|
2037
|
+
case '*':
|
|
2038
|
+
re += star;
|
|
2039
|
+
hasMagic = true;
|
|
2040
|
+
break
|
|
2041
|
+
case '?':
|
|
2042
|
+
re += qmark;
|
|
2043
|
+
hasMagic = true;
|
|
2044
|
+
break
|
|
2045
|
+
default:
|
|
2046
|
+
re += '\\' + stateChar;
|
|
2047
|
+
break
|
|
2048
|
+
}
|
|
2049
|
+
this.debug('clearStateChar %j %j', stateChar, re);
|
|
2050
|
+
stateChar = false;
|
|
2051
|
+
}
|
|
2052
|
+
};
|
|
2053
|
+
|
|
2054
|
+
for (let i = 0, c; (i < pattern.length) && (c = pattern.charAt(i)); i++) {
|
|
2055
|
+
this.debug('%s\t%s %s %j', pattern, i, re, c);
|
|
2056
|
+
|
|
2057
|
+
// skip over any that are escaped.
|
|
2058
|
+
if (escaping) {
|
|
2059
|
+
/* istanbul ignore next - completely not allowed, even escaped. */
|
|
2060
|
+
if (c === '/') {
|
|
2061
|
+
return false
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
if (reSpecials[c]) {
|
|
2065
|
+
re += '\\';
|
|
2066
|
+
}
|
|
2067
|
+
re += c;
|
|
2068
|
+
escaping = false;
|
|
2069
|
+
continue
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
switch (c) {
|
|
2073
|
+
/* istanbul ignore next */
|
|
2074
|
+
case '/': {
|
|
2075
|
+
// Should already be path-split by now.
|
|
2076
|
+
return false
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
case '\\':
|
|
2080
|
+
clearStateChar();
|
|
2081
|
+
escaping = true;
|
|
2082
|
+
continue
|
|
2083
|
+
|
|
2084
|
+
// the various stateChar values
|
|
2085
|
+
// for the "extglob" stuff.
|
|
2086
|
+
case '?':
|
|
2087
|
+
case '*':
|
|
2088
|
+
case '+':
|
|
2089
|
+
case '@':
|
|
2090
|
+
case '!':
|
|
2091
|
+
this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c);
|
|
2092
|
+
|
|
2093
|
+
// all of those are literals inside a class, except that
|
|
2094
|
+
// the glob [!a] means [^a] in regexp
|
|
2095
|
+
if (inClass) {
|
|
2096
|
+
this.debug(' in class');
|
|
2097
|
+
if (c === '!' && i === classStart + 1) c = '^';
|
|
2098
|
+
re += c;
|
|
2099
|
+
continue
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
// if we already have a stateChar, then it means
|
|
2103
|
+
// that there was something like ** or +? in there.
|
|
2104
|
+
// Handle the stateChar, then proceed with this one.
|
|
2105
|
+
this.debug('call clearStateChar %j', stateChar);
|
|
2106
|
+
clearStateChar();
|
|
2107
|
+
stateChar = c;
|
|
2108
|
+
// if extglob is disabled, then +(asdf|foo) isn't a thing.
|
|
2109
|
+
// just clear the statechar *now*, rather than even diving into
|
|
2110
|
+
// the patternList stuff.
|
|
2111
|
+
if (options.noext) clearStateChar();
|
|
2112
|
+
continue
|
|
2113
|
+
|
|
2114
|
+
case '(':
|
|
2115
|
+
if (inClass) {
|
|
2116
|
+
re += '(';
|
|
2117
|
+
continue
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
if (!stateChar) {
|
|
2121
|
+
re += '\\(';
|
|
2122
|
+
continue
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2125
|
+
patternListStack.push({
|
|
2126
|
+
type: stateChar,
|
|
2127
|
+
start: i - 1,
|
|
2128
|
+
reStart: re.length,
|
|
2129
|
+
open: plTypes[stateChar].open,
|
|
2130
|
+
close: plTypes[stateChar].close
|
|
2131
|
+
});
|
|
2132
|
+
// negation is (?:(?!js)[^/]*)
|
|
2133
|
+
re += stateChar === '!' ? '(?:(?!(?:' : '(?:';
|
|
2134
|
+
this.debug('plType %j %j', stateChar, re);
|
|
2135
|
+
stateChar = false;
|
|
2136
|
+
continue
|
|
2137
|
+
|
|
2138
|
+
case ')':
|
|
2139
|
+
if (inClass || !patternListStack.length) {
|
|
2140
|
+
re += '\\)';
|
|
2141
|
+
continue
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
clearStateChar();
|
|
2145
|
+
hasMagic = true;
|
|
2146
|
+
pl = patternListStack.pop();
|
|
2147
|
+
// negation is (?:(?!js)[^/]*)
|
|
2148
|
+
// The others are (?:<pattern>)<type>
|
|
2149
|
+
re += pl.close;
|
|
2150
|
+
if (pl.type === '!') {
|
|
2151
|
+
negativeLists.push(pl);
|
|
2152
|
+
}
|
|
2153
|
+
pl.reEnd = re.length;
|
|
2154
|
+
continue
|
|
2155
|
+
|
|
2156
|
+
case '|':
|
|
2157
|
+
if (inClass || !patternListStack.length) {
|
|
2158
|
+
re += '\\|';
|
|
2159
|
+
continue
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
clearStateChar();
|
|
2163
|
+
re += '|';
|
|
2164
|
+
continue
|
|
2165
|
+
|
|
2166
|
+
// these are mostly the same in regexp and glob
|
|
2167
|
+
case '[':
|
|
2168
|
+
// swallow any state-tracking char before the [
|
|
2169
|
+
clearStateChar();
|
|
2170
|
+
|
|
2171
|
+
if (inClass) {
|
|
2172
|
+
re += '\\' + c;
|
|
2173
|
+
continue
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
inClass = true;
|
|
2177
|
+
classStart = i;
|
|
2178
|
+
reClassStart = re.length;
|
|
2179
|
+
re += c;
|
|
2180
|
+
continue
|
|
2181
|
+
|
|
2182
|
+
case ']':
|
|
2183
|
+
// a right bracket shall lose its special
|
|
2184
|
+
// meaning and represent itself in
|
|
2185
|
+
// a bracket expression if it occurs
|
|
2186
|
+
// first in the list. -- POSIX.2 2.8.3.2
|
|
2187
|
+
if (i === classStart + 1 || !inClass) {
|
|
2188
|
+
re += '\\' + c;
|
|
2189
|
+
continue
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
// handle the case where we left a class open.
|
|
2193
|
+
// "[z-a]" is valid, equivalent to "\[z-a\]"
|
|
2194
|
+
// split where the last [ was, make sure we don't have
|
|
2195
|
+
// an invalid re. if so, re-walk the contents of the
|
|
2196
|
+
// would-be class to re-translate any characters that
|
|
2197
|
+
// were passed through as-is
|
|
2198
|
+
// TODO: It would probably be faster to determine this
|
|
2199
|
+
// without a try/catch and a new RegExp, but it's tricky
|
|
2200
|
+
// to do safely. For now, this is safe and works.
|
|
2201
|
+
cs = pattern.substring(classStart + 1, i);
|
|
2202
|
+
try {
|
|
2203
|
+
RegExp('[' + cs + ']');
|
|
2204
|
+
} catch (er) {
|
|
2205
|
+
// not a valid class!
|
|
2206
|
+
sp = this.parse(cs, SUBPARSE);
|
|
2207
|
+
re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]';
|
|
2208
|
+
hasMagic = hasMagic || sp[1];
|
|
2209
|
+
inClass = false;
|
|
2210
|
+
continue
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2213
|
+
// finish up the class.
|
|
2214
|
+
hasMagic = true;
|
|
2215
|
+
inClass = false;
|
|
2216
|
+
re += c;
|
|
2217
|
+
continue
|
|
2218
|
+
|
|
2219
|
+
default:
|
|
2220
|
+
// swallow any state char that wasn't consumed
|
|
2221
|
+
clearStateChar();
|
|
2222
|
+
|
|
2223
|
+
if (reSpecials[c] && !(c === '^' && inClass)) {
|
|
2224
|
+
re += '\\';
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
re += c;
|
|
2228
|
+
break
|
|
2229
|
+
|
|
2230
|
+
} // switch
|
|
2231
|
+
} // for
|
|
2232
|
+
|
|
2233
|
+
// handle the case where we left a class open.
|
|
2234
|
+
// "[abc" is valid, equivalent to "\[abc"
|
|
2235
|
+
if (inClass) {
|
|
2236
|
+
// split where the last [ was, and escape it
|
|
2237
|
+
// this is a huge pita. We now have to re-walk
|
|
2238
|
+
// the contents of the would-be class to re-translate
|
|
2239
|
+
// any characters that were passed through as-is
|
|
2240
|
+
cs = pattern.substr(classStart + 1);
|
|
2241
|
+
sp = this.parse(cs, SUBPARSE);
|
|
2242
|
+
re = re.substr(0, reClassStart) + '\\[' + sp[0];
|
|
2243
|
+
hasMagic = hasMagic || sp[1];
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
// handle the case where we had a +( thing at the *end*
|
|
2247
|
+
// of the pattern.
|
|
2248
|
+
// each pattern list stack adds 3 chars, and we need to go through
|
|
2249
|
+
// and escape any | chars that were passed through as-is for the regexp.
|
|
2250
|
+
// Go through and escape them, taking care not to double-escape any
|
|
2251
|
+
// | chars that were already escaped.
|
|
2252
|
+
for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
|
|
2253
|
+
let tail;
|
|
2254
|
+
tail = re.slice(pl.reStart + pl.open.length);
|
|
2255
|
+
this.debug('setting tail', re, pl);
|
|
2256
|
+
// maybe some even number of \, then maybe 1 \, followed by a |
|
|
2257
|
+
tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, (_, $1, $2) => {
|
|
2258
|
+
/* istanbul ignore else - should already be done */
|
|
2259
|
+
if (!$2) {
|
|
2260
|
+
// the | isn't already escaped, so escape it.
|
|
2261
|
+
$2 = '\\';
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
// need to escape all those slashes *again*, without escaping the
|
|
2265
|
+
// one that we need for escaping the | character. As it works out,
|
|
2266
|
+
// escaping an even number of slashes can be done by simply repeating
|
|
2267
|
+
// it exactly after itself. That's why this trick works.
|
|
2268
|
+
//
|
|
2269
|
+
// I am sorry that you have to see this.
|
|
2270
|
+
return $1 + $1 + $2 + '|'
|
|
2271
|
+
});
|
|
2272
|
+
|
|
2273
|
+
this.debug('tail=%j\n %s', tail, tail, pl, re);
|
|
2274
|
+
const t = pl.type === '*' ? star
|
|
2275
|
+
: pl.type === '?' ? qmark
|
|
2276
|
+
: '\\' + pl.type;
|
|
2277
|
+
|
|
2278
|
+
hasMagic = true;
|
|
2279
|
+
re = re.slice(0, pl.reStart) + t + '\\(' + tail;
|
|
2280
|
+
}
|
|
2281
|
+
|
|
2282
|
+
// handle trailing things that only matter at the very end.
|
|
2283
|
+
clearStateChar();
|
|
2284
|
+
if (escaping) {
|
|
2285
|
+
// trailing \\
|
|
2286
|
+
re += '\\\\';
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2289
|
+
// only need to apply the nodot start if the re starts with
|
|
2290
|
+
// something that could conceivably capture a dot
|
|
2291
|
+
const addPatternStart = addPatternStartSet[re.charAt(0)];
|
|
2292
|
+
|
|
2293
|
+
// Hack to work around lack of negative lookbehind in JS
|
|
2294
|
+
// A pattern like: *.!(x).!(y|z) needs to ensure that a name
|
|
2295
|
+
// like 'a.xyz.yz' doesn't match. So, the first negative
|
|
2296
|
+
// lookahead, has to look ALL the way ahead, to the end of
|
|
2297
|
+
// the pattern.
|
|
2298
|
+
for (let n = negativeLists.length - 1; n > -1; n--) {
|
|
2299
|
+
const nl = negativeLists[n];
|
|
2300
|
+
|
|
2301
|
+
const nlBefore = re.slice(0, nl.reStart);
|
|
2302
|
+
const nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
|
|
2303
|
+
let nlAfter = re.slice(nl.reEnd);
|
|
2304
|
+
const nlLast = re.slice(nl.reEnd - 8, nl.reEnd) + nlAfter;
|
|
2305
|
+
|
|
2306
|
+
// Handle nested stuff like *(*.js|!(*.json)), where open parens
|
|
2307
|
+
// mean that we should *not* include the ) in the bit that is considered
|
|
2308
|
+
// "after" the negated section.
|
|
2309
|
+
const openParensBefore = nlBefore.split('(').length - 1;
|
|
2310
|
+
let cleanAfter = nlAfter;
|
|
2311
|
+
for (let i = 0; i < openParensBefore; i++) {
|
|
2312
|
+
cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
|
|
2313
|
+
}
|
|
2314
|
+
nlAfter = cleanAfter;
|
|
2315
|
+
|
|
2316
|
+
const dollar = nlAfter === '' && isSub !== SUBPARSE ? '$' : '';
|
|
2317
|
+
re = nlBefore + nlFirst + nlAfter + dollar + nlLast;
|
|
2318
|
+
}
|
|
2319
|
+
|
|
2320
|
+
// if the re is not "" at this point, then we need to make sure
|
|
2321
|
+
// it doesn't match against an empty path part.
|
|
2322
|
+
// Otherwise a/* will match a/, which it should not.
|
|
2323
|
+
if (re !== '' && hasMagic) {
|
|
2324
|
+
re = '(?=.)' + re;
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
if (addPatternStart) {
|
|
2328
|
+
re = patternStart + re;
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
// parsing just a piece of a larger pattern.
|
|
2332
|
+
if (isSub === SUBPARSE) {
|
|
2333
|
+
return [re, hasMagic]
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
// skip the regexp for non-magical patterns
|
|
2337
|
+
// unescape anything in it, though, so that it'll be
|
|
2338
|
+
// an exact match against a file etc.
|
|
2339
|
+
if (!hasMagic) {
|
|
2340
|
+
return globUnescape(pattern)
|
|
2341
|
+
}
|
|
2342
|
+
|
|
2343
|
+
const flags = options.nocase ? 'i' : '';
|
|
2344
|
+
try {
|
|
2345
|
+
return Object.assign(new RegExp('^' + re + '$', flags), {
|
|
2346
|
+
_glob: pattern,
|
|
2347
|
+
_src: re,
|
|
2348
|
+
})
|
|
2349
|
+
} catch (er) /* istanbul ignore next - should be impossible */ {
|
|
2350
|
+
// If it was an invalid regular expression, then it can't match
|
|
2351
|
+
// anything. This trick looks for a character after the end of
|
|
2352
|
+
// the string, which is of course impossible, except in multi-line
|
|
2353
|
+
// mode, but it's not a /m regex.
|
|
2354
|
+
return new RegExp('$.')
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2358
|
+
makeRe () {
|
|
2359
|
+
if (this.regexp || this.regexp === false) return this.regexp
|
|
2360
|
+
|
|
2361
|
+
// at this point, this.set is a 2d array of partial
|
|
2362
|
+
// pattern strings, or "**".
|
|
2363
|
+
//
|
|
2364
|
+
// It's better to use .match(). This function shouldn't
|
|
2365
|
+
// be used, really, but it's pretty convenient sometimes,
|
|
2366
|
+
// when you just want to work with a regex.
|
|
2367
|
+
const set = this.set;
|
|
2368
|
+
|
|
2369
|
+
if (!set.length) {
|
|
2370
|
+
this.regexp = false;
|
|
2371
|
+
return this.regexp
|
|
2372
|
+
}
|
|
2373
|
+
const options = this.options;
|
|
2374
|
+
|
|
2375
|
+
const twoStar = options.noglobstar ? star
|
|
2376
|
+
: options.dot ? twoStarDot
|
|
2377
|
+
: twoStarNoDot;
|
|
2378
|
+
const flags = options.nocase ? 'i' : '';
|
|
2379
|
+
|
|
2380
|
+
// coalesce globstars and regexpify non-globstar patterns
|
|
2381
|
+
// if it's the only item, then we just do one twoStar
|
|
2382
|
+
// if it's the first, and there are more, prepend (\/|twoStar\/)? to next
|
|
2383
|
+
// if it's the last, append (\/twoStar|) to previous
|
|
2384
|
+
// if it's in the middle, append (\/|\/twoStar\/) to previous
|
|
2385
|
+
// then filter out GLOBSTAR symbols
|
|
2386
|
+
let re = set.map(pattern => {
|
|
2387
|
+
pattern = pattern.map(p =>
|
|
2388
|
+
typeof p === 'string' ? regExpEscape(p)
|
|
2389
|
+
: p === GLOBSTAR ? GLOBSTAR
|
|
2390
|
+
: p._src
|
|
2391
|
+
).reduce((set, p) => {
|
|
2392
|
+
if (!(set[set.length - 1] === GLOBSTAR && p === GLOBSTAR)) {
|
|
2393
|
+
set.push(p);
|
|
2394
|
+
}
|
|
2395
|
+
return set
|
|
2396
|
+
}, []);
|
|
2397
|
+
pattern.forEach((p, i) => {
|
|
2398
|
+
if (p !== GLOBSTAR || pattern[i-1] === GLOBSTAR) {
|
|
2399
|
+
return
|
|
2400
|
+
}
|
|
2401
|
+
if (i === 0) {
|
|
2402
|
+
if (pattern.length > 1) {
|
|
2403
|
+
pattern[i+1] = '(?:\\\/|' + twoStar + '\\\/)?' + pattern[i+1];
|
|
2404
|
+
} else {
|
|
2405
|
+
pattern[i] = twoStar;
|
|
2406
|
+
}
|
|
2407
|
+
} else if (i === pattern.length - 1) {
|
|
2408
|
+
pattern[i-1] += '(?:\\\/|' + twoStar + ')?';
|
|
2409
|
+
} else {
|
|
2410
|
+
pattern[i-1] += '(?:\\\/|\\\/' + twoStar + '\\\/)' + pattern[i+1];
|
|
2411
|
+
pattern[i+1] = GLOBSTAR;
|
|
2412
|
+
}
|
|
2413
|
+
});
|
|
2414
|
+
return pattern.filter(p => p !== GLOBSTAR).join('/')
|
|
2415
|
+
}).join('|');
|
|
2416
|
+
|
|
2417
|
+
// must match entire pattern
|
|
2418
|
+
// ending in a * or ** will make it less strict.
|
|
2419
|
+
re = '^(?:' + re + ')$';
|
|
2420
|
+
|
|
2421
|
+
// can match anything, as long as it's not this.
|
|
2422
|
+
if (this.negate) re = '^(?!' + re + ').*$';
|
|
2423
|
+
|
|
2424
|
+
try {
|
|
2425
|
+
this.regexp = new RegExp(re, flags);
|
|
2426
|
+
} catch (ex) /* istanbul ignore next - should be impossible */ {
|
|
2427
|
+
this.regexp = false;
|
|
2428
|
+
}
|
|
2429
|
+
return this.regexp
|
|
2430
|
+
}
|
|
2431
|
+
|
|
2432
|
+
match (f, partial = this.partial) {
|
|
2433
|
+
this.debug('match', f, this.pattern);
|
|
2434
|
+
// short-circuit in the case of busted things.
|
|
2435
|
+
// comments, etc.
|
|
2436
|
+
if (this.comment) return false
|
|
2437
|
+
if (this.empty) return f === ''
|
|
2438
|
+
|
|
2439
|
+
if (f === '/' && partial) return true
|
|
2440
|
+
|
|
2441
|
+
const options = this.options;
|
|
2442
|
+
|
|
2443
|
+
// windows: need to use /, not \
|
|
2444
|
+
if (path.sep !== '/') {
|
|
2445
|
+
f = f.split(path.sep).join('/');
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
// treat the test path as a set of pathparts.
|
|
2449
|
+
f = f.split(slashSplit);
|
|
2450
|
+
this.debug(this.pattern, 'split', f);
|
|
2451
|
+
|
|
2452
|
+
// just ONE of the pattern sets in this.set needs to match
|
|
2453
|
+
// in order for it to be valid. If negating, then just one
|
|
2454
|
+
// match means that we have failed.
|
|
2455
|
+
// Either way, return on the first hit.
|
|
2456
|
+
|
|
2457
|
+
const set = this.set;
|
|
2458
|
+
this.debug(this.pattern, 'set', set);
|
|
2459
|
+
|
|
2460
|
+
// Find the basename of the path by looking for the last non-empty segment
|
|
2461
|
+
let filename;
|
|
2462
|
+
for (let i = f.length - 1; i >= 0; i--) {
|
|
2463
|
+
filename = f[i];
|
|
2464
|
+
if (filename) break
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2467
|
+
for (let i = 0; i < set.length; i++) {
|
|
2468
|
+
const pattern = set[i];
|
|
2469
|
+
let file = f;
|
|
2470
|
+
if (options.matchBase && pattern.length === 1) {
|
|
2471
|
+
file = [filename];
|
|
2472
|
+
}
|
|
2473
|
+
const hit = this.matchOne(file, pattern, partial);
|
|
2474
|
+
if (hit) {
|
|
2475
|
+
if (options.flipNegate) return true
|
|
2476
|
+
return !this.negate
|
|
2477
|
+
}
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
// didn't get any hits. this is success if it's a negative
|
|
2481
|
+
// pattern, failure otherwise.
|
|
2482
|
+
if (options.flipNegate) return false
|
|
2483
|
+
return this.negate
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2486
|
+
static defaults (def) {
|
|
2487
|
+
return minimatch.defaults(def).Minimatch
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
|
|
2491
|
+
minimatch.Minimatch = Minimatch;
|
|
2492
|
+
|
|
2493
|
+
var minimatch$1 = minimatch_1;
|
|
2494
|
+
|
|
2495
|
+
const CAMEL_CASE_REGEX = /^[a-z][A-Za-z0-9]*$/;
|
|
2496
|
+
const CONSTANT_CASE_REGEX = /^[A-Z_]+$/;
|
|
2497
|
+
const PASCAL_CASE_REGEX = /^[A-Z][A-Za-z0-9]*$/;
|
|
2498
|
+
const SNAKE_CASE_REGEX$1 = /^[a-z0-9_]+$/;
|
|
2499
|
+
const EXPORT_PATTERN = {
|
|
2500
|
+
type: ramda.includes(ramda.__, [TYPES.EXPORT_DEFAULT_DECLARATION, TYPES.EXPORT_NAMED_DECLARATION])
|
|
2501
|
+
};
|
|
2502
|
+
|
|
2503
|
+
const isInsideBaseDirectory = context => context.getFilename().startsWith(context.options[0].basePath);
|
|
2504
|
+
|
|
2505
|
+
const asArray = item => {
|
|
2506
|
+
if (!item) return [];
|
|
2507
|
+
return Array.isArray(item) ? item : new Array(item);
|
|
2508
|
+
};
|
|
2509
|
+
|
|
2510
|
+
const isCaseMatching = (text, caseStyle) => {
|
|
2511
|
+
var _regexes$caseStyle;
|
|
2512
|
+
|
|
2513
|
+
if (!text) return true;
|
|
2514
|
+
const regexes = {
|
|
2515
|
+
camelCase: CAMEL_CASE_REGEX,
|
|
2516
|
+
CONSTANT_CASE: CONSTANT_CASE_REGEX,
|
|
2517
|
+
PascalCase: PASCAL_CASE_REGEX,
|
|
2518
|
+
snake_case: SNAKE_CASE_REGEX$1
|
|
2519
|
+
};
|
|
2520
|
+
return ((_regexes$caseStyle = regexes[caseStyle]) === null || _regexes$caseStyle === void 0 ? void 0 : _regexes$caseStyle.test(text)) ?? true;
|
|
2521
|
+
};
|
|
2522
|
+
|
|
2523
|
+
const findMatchedConfig = (context, configs) => {
|
|
2524
|
+
const fullFilePath = context.getFilename();
|
|
2525
|
+
const basePath = context.options[0].basePath;
|
|
2526
|
+
const matchedConfig = configs.find(config => {
|
|
2527
|
+
const isIncluded = asArray(config.includes).some(pathPattern => minimatch$1(fullFilePath, basePath + pathPattern));
|
|
2528
|
+
if (config.includes && !isIncluded) return false;
|
|
2529
|
+
const isExcluded = asArray(config.excludes).some(pathPattern => minimatch$1(fullFilePath, basePath + pathPattern));
|
|
2530
|
+
if (config.excludes && isExcluded) return false;
|
|
2531
|
+
return true;
|
|
2532
|
+
});
|
|
2533
|
+
return matchedConfig;
|
|
2534
|
+
};
|
|
2535
|
+
|
|
2536
|
+
const checkFilenameCase = (context, node, filenameCase) => {
|
|
2537
|
+
const [filename] = getFilenameAndExtension(context);
|
|
2538
|
+
if (filename === "index") return;
|
|
2539
|
+
|
|
2540
|
+
if (!isCaseMatching(filename, filenameCase)) {
|
|
2541
|
+
context.report({
|
|
2542
|
+
node,
|
|
2543
|
+
message: filenameShouldBe(filenameCase)
|
|
2544
|
+
});
|
|
2545
|
+
}
|
|
2546
|
+
};
|
|
2547
|
+
|
|
2548
|
+
const reportExportCaseMismatch = ({
|
|
2549
|
+
context,
|
|
2550
|
+
node,
|
|
2551
|
+
exportnameCase,
|
|
2552
|
+
objectName
|
|
2553
|
+
}) => {
|
|
2554
|
+
if (objectName && !isCaseMatching(objectName, exportnameCase)) {
|
|
2555
|
+
context.report({
|
|
2556
|
+
node,
|
|
2557
|
+
message: exportedObjectShouldBe(exportnameCase)
|
|
2558
|
+
});
|
|
2559
|
+
}
|
|
2560
|
+
};
|
|
2561
|
+
|
|
2562
|
+
const checkExportItemsCase = ({
|
|
2563
|
+
context,
|
|
2564
|
+
items,
|
|
2565
|
+
itemsType,
|
|
2566
|
+
exportnameCase
|
|
2567
|
+
}) => {
|
|
2568
|
+
items === null || items === void 0 ? void 0 : items.forEach(item => {
|
|
2569
|
+
const objectName = itemsType === "specifiers" ? item.exported.name : item.value.name;
|
|
2570
|
+
reportExportCaseMismatch({
|
|
2571
|
+
context,
|
|
2572
|
+
node: item,
|
|
2573
|
+
exportnameCase,
|
|
2574
|
+
objectName
|
|
2575
|
+
});
|
|
2576
|
+
});
|
|
2577
|
+
};
|
|
2578
|
+
|
|
2579
|
+
const checkNamedExportCase = (context, node, exportnameCase) => {
|
|
2580
|
+
var _node$declaration;
|
|
2581
|
+
|
|
2582
|
+
if (((_node$declaration = node.declaration) === null || _node$declaration === void 0 ? void 0 : _node$declaration.kind) === "const") {
|
|
2583
|
+
node.declaration.declarations.forEach(({
|
|
2584
|
+
id
|
|
2585
|
+
}) => {
|
|
2586
|
+
if (id.type === TYPES.IDENTIFIER) {
|
|
2587
|
+
reportExportCaseMismatch({
|
|
2588
|
+
context,
|
|
2589
|
+
node: id,
|
|
2590
|
+
exportnameCase,
|
|
2591
|
+
objectName: id.name
|
|
2592
|
+
});
|
|
2593
|
+
} else {
|
|
2594
|
+
checkExportItemsCase({
|
|
2595
|
+
context,
|
|
2596
|
+
items: id.properties,
|
|
2597
|
+
itemsType: "properties",
|
|
2598
|
+
exportnameCase
|
|
2599
|
+
});
|
|
2600
|
+
}
|
|
2601
|
+
});
|
|
2602
|
+
} else {
|
|
2603
|
+
checkExportItemsCase({
|
|
2604
|
+
context,
|
|
2605
|
+
items: node.specifiers,
|
|
2606
|
+
itemsType: "specifiers",
|
|
2607
|
+
exportnameCase
|
|
2608
|
+
});
|
|
2609
|
+
}
|
|
2610
|
+
};
|
|
2611
|
+
|
|
2612
|
+
const checkDefaultExportCase = (context, node, exportnameCase) => {
|
|
2613
|
+
var _declaration$id;
|
|
2614
|
+
|
|
2615
|
+
const declaration = node.declaration;
|
|
2616
|
+
|
|
2617
|
+
if (declaration.type === TYPES.OBJECT_EXPRESSION) {
|
|
2618
|
+
checkExportItemsCase({
|
|
2619
|
+
context,
|
|
2620
|
+
items: declaration.properties,
|
|
2621
|
+
itemsType: "properties",
|
|
2622
|
+
exportnameCase
|
|
2623
|
+
});
|
|
2624
|
+
return;
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
const objectName = declaration.type === TYPES.IDENTIFIER ? declaration.name : (_declaration$id = declaration.id) === null || _declaration$id === void 0 ? void 0 : _declaration$id.name;
|
|
2628
|
+
reportExportCaseMismatch({
|
|
2629
|
+
context,
|
|
2630
|
+
node,
|
|
2631
|
+
exportnameCase,
|
|
2632
|
+
objectName
|
|
2633
|
+
});
|
|
2634
|
+
};
|
|
2635
|
+
|
|
2636
|
+
const checkExportnameCase = (context, exportNodes, exportnameCase) => {
|
|
2637
|
+
exportNodes.forEach(node => {
|
|
2638
|
+
const isNamedExport = node.type === TYPES.EXPORT_NAMED_DECLARATION;
|
|
2639
|
+
|
|
2640
|
+
if (isNamedExport) {
|
|
2641
|
+
checkNamedExportCase(context, node, exportnameCase);
|
|
2642
|
+
} else {
|
|
2643
|
+
checkDefaultExportCase(context, node, exportnameCase);
|
|
2644
|
+
}
|
|
2645
|
+
});
|
|
2646
|
+
};
|
|
2647
|
+
|
|
2648
|
+
const checkFilenameAndExportname = (context, exportNodes) => {
|
|
2649
|
+
var _defaultExportNode$de;
|
|
2650
|
+
|
|
2651
|
+
const [filename] = getFilenameAndExtension(context);
|
|
2652
|
+
const defaultExportNode = exportNodes.find(node => node.type === TYPES.EXPORT_DEFAULT_DECLARATION);
|
|
2653
|
+
if (!defaultExportNode) return;
|
|
2654
|
+
const exportedObjectName = (_defaultExportNode$de = defaultExportNode.declaration) === null || _defaultExportNode$de === void 0 ? void 0 : _defaultExportNode$de.name;
|
|
2655
|
+
if (!exportedObjectName) return;
|
|
2656
|
+
const pathKeys = context.getFilename().split(/\.|\//g).slice(0, -1);
|
|
2657
|
+
const pathString = filename === "index" ? pathKeys.slice(0, -1).join("") : pathKeys.join("");
|
|
2658
|
+
const isNameMatches = pathString.endsWith(exportedObjectName);
|
|
2659
|
+
if (isNameMatches) return;
|
|
2660
|
+
context.report({
|
|
2661
|
+
node: defaultExportNode,
|
|
2662
|
+
message: EXPORTED_OBJECT_AND_FILENAME_SHOULD_MATCH_MESSAGE
|
|
2663
|
+
});
|
|
2664
|
+
};
|
|
2665
|
+
|
|
2666
|
+
var fileNameAndExportNameStandards = {
|
|
2667
|
+
meta: {
|
|
2668
|
+
type: "suggestion",
|
|
2669
|
+
docs: {
|
|
2670
|
+
description: "Allows you to enforce a consistent naming pattern for the filenames and exports."
|
|
2671
|
+
}
|
|
2672
|
+
},
|
|
2673
|
+
create: context => ({
|
|
2674
|
+
Program(node) {
|
|
2675
|
+
if (!isInsideBaseDirectory(context)) return;
|
|
2676
|
+
const defaultConfig = context.options[0].default;
|
|
2677
|
+
const configs = context.options[0].configs;
|
|
2678
|
+
const {
|
|
2679
|
+
filenameCase,
|
|
2680
|
+
exportnameCase,
|
|
2681
|
+
matchFileNameAndExportName
|
|
2682
|
+
} = findMatchedConfig(context, configs) || defaultConfig;
|
|
2683
|
+
|
|
2684
|
+
if (filenameCase) {
|
|
2685
|
+
checkFilenameCase(context, node, filenameCase);
|
|
2686
|
+
}
|
|
2687
|
+
|
|
2688
|
+
if (exportnameCase || matchFileNameAndExportName) {
|
|
2689
|
+
const exportNodes = findMatchingNodesDeep(node, EXPORT_PATTERN);
|
|
2690
|
+
|
|
2691
|
+
if (exportnameCase) {
|
|
2692
|
+
checkExportnameCase(context, exportNodes, exportnameCase);
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2695
|
+
if (matchFileNameAndExportName) {
|
|
2696
|
+
checkFilenameAndExportname(context, exportNodes);
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
|
|
2701
|
+
})
|
|
2702
|
+
};
|
|
2703
|
+
|
|
2704
|
+
const ASSIGNMENT_PATTERNS = [{
|
|
2705
|
+
id: {
|
|
2706
|
+
type: TYPES.OBJECT_PATTERN
|
|
2707
|
+
}
|
|
2708
|
+
}, {
|
|
2709
|
+
id: {
|
|
2710
|
+
type: TYPES.IDENTIFIER
|
|
2711
|
+
}
|
|
2712
|
+
}];
|
|
2713
|
+
const IDENTIFIER_INITIALIZATION_PATTERN = {
|
|
2714
|
+
type: TYPES.IDENTIFIER,
|
|
2715
|
+
name: "globalProps"
|
|
2716
|
+
};
|
|
2717
|
+
const MEMBER_EXPRESSION_INITIALIZATION_PATTERN = {
|
|
2718
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
2719
|
+
object: {
|
|
2720
|
+
type: TYPES.IDENTIFIER,
|
|
2721
|
+
name: "globalProps"
|
|
2722
|
+
}
|
|
2723
|
+
};
|
|
2724
|
+
const GLOBALPROPS_REASSIGNMENT_PATTERN = {
|
|
2725
|
+
type: TYPES.IDENTIFIER,
|
|
2726
|
+
name: "globalProps"
|
|
2727
|
+
};
|
|
2728
|
+
|
|
2729
|
+
const checkAssignment = (context, node) => {
|
|
2730
|
+
if (matches(IDENTIFIER_INITIALIZATION_PATTERN, node)) {
|
|
2731
|
+
context.report(node, GLOBALPROPS_NO_ASSIGNMENT_MESSAGE);
|
|
2732
|
+
} else if (matches(MEMBER_EXPRESSION_INITIALIZATION_PATTERN, node)) {
|
|
2733
|
+
context.report(node, NESTED_GLOBALPROPS_NO_ASSIGNMENT_MESSAGE);
|
|
2734
|
+
}
|
|
2735
|
+
};
|
|
2736
|
+
|
|
2737
|
+
var noGlobalPropsDestructure = {
|
|
2738
|
+
meta: {
|
|
2739
|
+
type: "problem",
|
|
2740
|
+
docs: {
|
|
2741
|
+
description: "Disallows destructuring of globalProps."
|
|
1253
2742
|
}
|
|
2743
|
+
},
|
|
2744
|
+
create: context => ({
|
|
2745
|
+
VariableDeclarator(node) {
|
|
2746
|
+
if (!matchesAny(ASSIGNMENT_PATTERNS, node)) return;
|
|
2747
|
+
checkAssignment(context, node.init);
|
|
2748
|
+
},
|
|
1254
2749
|
|
|
2750
|
+
AssignmentExpression: node => checkAssignment(context, node.right)
|
|
1255
2751
|
})
|
|
1256
2752
|
};
|
|
1257
2753
|
|
|
1258
|
-
|
|
2754
|
+
var noGlobalPropsReassignment = {
|
|
2755
|
+
meta: {
|
|
2756
|
+
type: "problem",
|
|
2757
|
+
docs: {
|
|
2758
|
+
description: "Disallows re-assignment of globalProps."
|
|
2759
|
+
}
|
|
2760
|
+
},
|
|
2761
|
+
create: context => ({
|
|
2762
|
+
AssignmentExpression(node) {
|
|
2763
|
+
if (patternExistsDeep(GLOBALPROPS_REASSIGNMENT_PATTERN, node.left)) {
|
|
2764
|
+
context.report(node, NO_GLOBALPROPS_REASSIGNMENT_MESSAGE);
|
|
2765
|
+
}
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
})
|
|
2769
|
+
};
|
|
2770
|
+
|
|
2771
|
+
const ZUSTAND_HOOK_USAGE_PATTERN$1 = {
|
|
2772
|
+
kind: "const",
|
|
2773
|
+
declarations: [{
|
|
2774
|
+
type: TYPES.VARIABLE_DECLARATOR,
|
|
2775
|
+
init: {
|
|
2776
|
+
type: TYPES.CALL_EXPRESSION,
|
|
2777
|
+
callee: {
|
|
2778
|
+
type: TYPES.IDENTIFIER,
|
|
2779
|
+
name: name => name.match(/use[a-zA-z0-9].+Store/)
|
|
2780
|
+
},
|
|
2781
|
+
arguments: ramda.isEmpty,
|
|
2782
|
+
optional: false
|
|
2783
|
+
}
|
|
2784
|
+
}]
|
|
2785
|
+
};
|
|
2786
|
+
|
|
2787
|
+
var minimizeZustandStoreAccessScope = {
|
|
2788
|
+
meta: {
|
|
2789
|
+
type: "problem",
|
|
2790
|
+
docs: {
|
|
2791
|
+
description: "Use function based accessor for obtaining values from zustand stores. Using state as a whole is not recommended."
|
|
2792
|
+
}
|
|
2793
|
+
},
|
|
2794
|
+
create: context => ({
|
|
2795
|
+
VariableDeclaration(node) {
|
|
2796
|
+
if (!matches(ZUSTAND_HOOK_USAGE_PATTERN$1, node)) return;
|
|
2797
|
+
context.report({
|
|
2798
|
+
node,
|
|
2799
|
+
message: DONT_USE_ZUSTAND_STORE_WITHOUT_SELECTOR
|
|
2800
|
+
});
|
|
2801
|
+
}
|
|
2802
|
+
|
|
2803
|
+
})
|
|
2804
|
+
};
|
|
2805
|
+
|
|
2806
|
+
const reportSuggestion$1 = ({
|
|
1259
2807
|
context,
|
|
1260
2808
|
node,
|
|
1261
2809
|
fix,
|
|
@@ -1351,6 +2899,57 @@
|
|
|
1351
2899
|
type: TYPES.IDENTIFIER,
|
|
1352
2900
|
name: "length"
|
|
1353
2901
|
}
|
|
2902
|
+
}; // string.charAt(0).toUpperCase()
|
|
2903
|
+
|
|
2904
|
+
const CAPITALIZE_LEFT_PATTERN = {
|
|
2905
|
+
type: TYPES.CALL_EXPRESSION,
|
|
2906
|
+
callee: {
|
|
2907
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
2908
|
+
object: {
|
|
2909
|
+
type: TYPES.CALL_EXPRESSION,
|
|
2910
|
+
callee: {
|
|
2911
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
2912
|
+
object: {
|
|
2913
|
+
type: TYPES.IDENTIFIER,
|
|
2914
|
+
name: (name, root) => {
|
|
2915
|
+
var _root$right$callee, _root$right$callee$ob, _root$right$expressio, _root$right$expressio2, _root$right$expressio3;
|
|
2916
|
+
|
|
2917
|
+
return name === ((_root$right$callee = root.right.callee) === null || _root$right$callee === void 0 ? void 0 : (_root$right$callee$ob = _root$right$callee.object) === null || _root$right$callee$ob === void 0 ? void 0 : _root$right$callee$ob.name) || ((_root$right$expressio = root.right.expression) === null || _root$right$expressio === void 0 ? void 0 : (_root$right$expressio2 = _root$right$expressio.callee) === null || _root$right$expressio2 === void 0 ? void 0 : (_root$right$expressio3 = _root$right$expressio2.object) === null || _root$right$expressio3 === void 0 ? void 0 : _root$right$expressio3.name);
|
|
2918
|
+
}
|
|
2919
|
+
},
|
|
2920
|
+
property: {
|
|
2921
|
+
type: TYPES.IDENTIFIER,
|
|
2922
|
+
name: "charAt"
|
|
2923
|
+
}
|
|
2924
|
+
},
|
|
2925
|
+
arguments: args => args.length === 1 && matches([{
|
|
2926
|
+
type: TYPES.LITERAL,
|
|
2927
|
+
value: 0
|
|
2928
|
+
}], args)
|
|
2929
|
+
},
|
|
2930
|
+
property: {
|
|
2931
|
+
type: TYPES.IDENTIFIER,
|
|
2932
|
+
name: "toUpperCase"
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
}; // string.slice(1)
|
|
2936
|
+
|
|
2937
|
+
const CAPITALIZE_RIGHT_PATTERN = {
|
|
2938
|
+
type: TYPES.CALL_EXPRESSION,
|
|
2939
|
+
callee: {
|
|
2940
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
2941
|
+
object: {
|
|
2942
|
+
type: TYPES.IDENTIFIER
|
|
2943
|
+
},
|
|
2944
|
+
property: {
|
|
2945
|
+
type: TYPES.IDENTIFIER,
|
|
2946
|
+
name: "slice"
|
|
2947
|
+
}
|
|
2948
|
+
},
|
|
2949
|
+
arguments: args => args.length === 1 && matches([{
|
|
2950
|
+
type: TYPES.LITERAL,
|
|
2951
|
+
value: 1
|
|
2952
|
+
}], args)
|
|
1354
2953
|
};
|
|
1355
2954
|
const OBJ_KEY_LENGTH_PATTERN$1 = {
|
|
1356
2955
|
type: TYPES.MEMBER_EXPRESSION,
|
|
@@ -1378,8 +2977,11 @@
|
|
|
1378
2977
|
async: false,
|
|
1379
2978
|
expression: false,
|
|
1380
2979
|
body: {
|
|
1381
|
-
type:
|
|
2980
|
+
type: TYPES.BLOCK_STATEMENT,
|
|
1382
2981
|
body: body => ramda.isEmpty(body)
|
|
2982
|
+
},
|
|
2983
|
+
parent: {
|
|
2984
|
+
type: notEquals(TYPES.EXPORT_DEFAULT_DECLARATION)
|
|
1383
2985
|
}
|
|
1384
2986
|
};
|
|
1385
2987
|
const LABEL_AND_VALUE_PATTERN = {
|
|
@@ -1470,6 +3072,17 @@
|
|
|
1470
3072
|
type: matchesAny([TYPES.IF_STATEMENT, TYPES.WHILE_STATEMENT]),
|
|
1471
3073
|
test: matchesAny([ARRAY_LENGTH_PATTERN$1, OBJ_KEY_LENGTH_PATTERN$1])
|
|
1472
3074
|
},
|
|
3075
|
+
// !!array.length, !!Object.keys(obj).length
|
|
3076
|
+
UNARY_EXP: {
|
|
3077
|
+
type: TYPES.UNARY_EXPRESSION,
|
|
3078
|
+
operator: "!",
|
|
3079
|
+
prefix: true,
|
|
3080
|
+
argument: matchesAny([ARRAY_LENGTH_PATTERN$1, OBJ_KEY_LENGTH_PATTERN$1]),
|
|
3081
|
+
parent: {
|
|
3082
|
+
type: TYPES.UNARY_EXPRESSION,
|
|
3083
|
+
operator: "!"
|
|
3084
|
+
}
|
|
3085
|
+
},
|
|
1473
3086
|
// x => !isEmpty(x)
|
|
1474
3087
|
ARROW_FUNC: {
|
|
1475
3088
|
type: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
@@ -1504,11 +3117,15 @@
|
|
|
1504
3117
|
expression: true,
|
|
1505
3118
|
params: params => params.length === 1 && params[0].type === TYPES.IDENTIFIER,
|
|
1506
3119
|
body: {
|
|
1507
|
-
type:
|
|
3120
|
+
type: TYPES.CONDITIONAL_EXPRESSION,
|
|
1508
3121
|
test: (test, root) => areAllChecksWithParams(test, arrayFuncParam(root), {
|
|
1509
3122
|
compare: "===",
|
|
1510
3123
|
join: "&&"
|
|
1511
3124
|
}),
|
|
3125
|
+
consequent: (consq, root) => ramda.not(ramda.any(patternExistsDeep({
|
|
3126
|
+
type: TYPES.IDENTIFIER,
|
|
3127
|
+
name: name => name === arrayFuncParam(root).name
|
|
3128
|
+
}), consq.type === TYPES.OBJECT_EXPRESSION ? consq.properties : [consq])),
|
|
1512
3129
|
alternate: {
|
|
1513
3130
|
type: TYPES.IDENTIFIER,
|
|
1514
3131
|
name: (name, root) => name === arrayFuncParam(root).name
|
|
@@ -1517,7 +3134,7 @@
|
|
|
1517
3134
|
}]
|
|
1518
3135
|
};
|
|
1519
3136
|
const REPLACE_BY_NEGATED_PATTERN = ramda.assocPath(["arguments", 0, "body"], {
|
|
1520
|
-
type:
|
|
3137
|
+
type: TYPES.CONDITIONAL_EXPRESSION,
|
|
1521
3138
|
test: (test, root) => areAllChecksWithParams(test, arrayFuncParam(root), {
|
|
1522
3139
|
compare: "!==",
|
|
1523
3140
|
join: "||"
|
|
@@ -1525,36 +3142,56 @@
|
|
|
1525
3142
|
consequent: {
|
|
1526
3143
|
type: TYPES.IDENTIFIER,
|
|
1527
3144
|
name: (name, root) => name === arrayFuncParam(root).name
|
|
1528
|
-
}
|
|
3145
|
+
},
|
|
3146
|
+
alternate: (alt, root) => ramda.not(ramda.any(patternExistsDeep({
|
|
3147
|
+
type: TYPES.IDENTIFIER,
|
|
3148
|
+
name: name => name === arrayFuncParam(root).name
|
|
3149
|
+
}), alt.type === TYPES.OBJECT_EXPRESSION ? alt.properties : [alt]))
|
|
1529
3150
|
}, REPLACE_BY_PATTERN);
|
|
1530
3151
|
const COPY_KEYS_PATTERN = {
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
3152
|
+
type: TYPES.CALL_EXPRESSION,
|
|
3153
|
+
callee: {
|
|
3154
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
3155
|
+
property: {
|
|
3156
|
+
type: TYPES.IDENTIFIER,
|
|
3157
|
+
name: "map"
|
|
1535
3158
|
}
|
|
1536
|
-
},
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
3159
|
+
},
|
|
3160
|
+
arguments: [{
|
|
3161
|
+
type: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
3162
|
+
params: params => params.length === 1 && params[0].type === TYPES.IDENTIFIER,
|
|
3163
|
+
body: {
|
|
3164
|
+
type: TYPES.OBJECT_EXPRESSION,
|
|
3165
|
+
properties: (props, root) => props.length > 1 && matches({
|
|
3166
|
+
type: TYPES.SPREAD_ELEMENT,
|
|
3167
|
+
argument: {
|
|
3168
|
+
type: TYPES.IDENTIFIER,
|
|
3169
|
+
name: root.arguments[0].params[0].name
|
|
3170
|
+
}
|
|
3171
|
+
}, props[0]) && props.slice(1).every(matches({
|
|
3172
|
+
type: TYPES.PROPERTY,
|
|
3173
|
+
kind: "init",
|
|
3174
|
+
method: false,
|
|
3175
|
+
computed: false,
|
|
3176
|
+
shorthand: false,
|
|
3177
|
+
key: {
|
|
3178
|
+
type: TYPES.IDENTIFIER
|
|
3179
|
+
},
|
|
3180
|
+
value: {
|
|
3181
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
3182
|
+
computed: false,
|
|
3183
|
+
optional: false,
|
|
3184
|
+
object: {
|
|
3185
|
+
type: TYPES.IDENTIFIER,
|
|
3186
|
+
name: props[0].argument.name
|
|
3187
|
+
},
|
|
3188
|
+
property: {
|
|
3189
|
+
type: TYPES.IDENTIFIER
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
}))
|
|
1556
3193
|
}
|
|
1557
|
-
}
|
|
3194
|
+
}]
|
|
1558
3195
|
};
|
|
1559
3196
|
const NOT_EQUALS_PATTERNS = {
|
|
1560
3197
|
// !Object.is(item1, item2)
|
|
@@ -1611,60 +3248,23 @@
|
|
|
1611
3248
|
}
|
|
1612
3249
|
}
|
|
1613
3250
|
};
|
|
1614
|
-
const
|
|
1615
|
-
|
|
1616
|
-
|
|
3251
|
+
const CAPITALIZE_PATTERNS = [// string.charAt(0).toUpperCase() + string.slice(1)
|
|
3252
|
+
{
|
|
3253
|
+
operator: "+",
|
|
3254
|
+
left: CAPITALIZE_LEFT_PATTERN,
|
|
3255
|
+
right: CAPITALIZE_RIGHT_PATTERN
|
|
3256
|
+
}, // string?.charAt(0).toUpperCase() + string?.slice(1)
|
|
3257
|
+
{
|
|
1617
3258
|
operator: "+",
|
|
1618
3259
|
left: {
|
|
1619
|
-
type: TYPES.
|
|
1620
|
-
|
|
1621
|
-
type: TYPES.MEMBER_EXPRESSION,
|
|
1622
|
-
object: {
|
|
1623
|
-
type: TYPES.CALL_EXPRESSION,
|
|
1624
|
-
callee: {
|
|
1625
|
-
type: TYPES.MEMBER_EXPRESSION,
|
|
1626
|
-
object: {
|
|
1627
|
-
type: TYPES.IDENTIFIER,
|
|
1628
|
-
name: (name, root) => {
|
|
1629
|
-
var _root$right$callee, _root$right$callee$ob;
|
|
1630
|
-
|
|
1631
|
-
return name === ((_root$right$callee = root.right.callee) === null || _root$right$callee === void 0 ? void 0 : (_root$right$callee$ob = _root$right$callee.object) === null || _root$right$callee$ob === void 0 ? void 0 : _root$right$callee$ob.name);
|
|
1632
|
-
}
|
|
1633
|
-
},
|
|
1634
|
-
property: {
|
|
1635
|
-
type: TYPES.IDENTIFIER,
|
|
1636
|
-
name: "charAt"
|
|
1637
|
-
}
|
|
1638
|
-
},
|
|
1639
|
-
arguments: args => args.length === 1 && matches([{
|
|
1640
|
-
type: TYPES.LITERAL,
|
|
1641
|
-
value: 0
|
|
1642
|
-
}], args)
|
|
1643
|
-
},
|
|
1644
|
-
property: {
|
|
1645
|
-
type: TYPES.IDENTIFIER,
|
|
1646
|
-
name: "toUpperCase"
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
3260
|
+
type: TYPES.CHAIN_EXPRESSION,
|
|
3261
|
+
expression: CAPITALIZE_LEFT_PATTERN
|
|
1649
3262
|
},
|
|
1650
3263
|
right: {
|
|
1651
|
-
type: TYPES.
|
|
1652
|
-
|
|
1653
|
-
type: TYPES.MEMBER_EXPRESSION,
|
|
1654
|
-
object: {
|
|
1655
|
-
type: TYPES.IDENTIFIER
|
|
1656
|
-
},
|
|
1657
|
-
property: {
|
|
1658
|
-
type: TYPES.IDENTIFIER,
|
|
1659
|
-
name: "slice"
|
|
1660
|
-
}
|
|
1661
|
-
},
|
|
1662
|
-
arguments: args => args.length === 1 && matches([{
|
|
1663
|
-
type: TYPES.LITERAL,
|
|
1664
|
-
value: 1
|
|
1665
|
-
}], args)
|
|
3264
|
+
type: TYPES.CHAIN_EXPRESSION,
|
|
3265
|
+
expression: CAPITALIZE_RIGHT_PATTERN
|
|
1666
3266
|
}
|
|
1667
|
-
};
|
|
3267
|
+
}];
|
|
1668
3268
|
const COUNT_BY_PATTERN = {
|
|
1669
3269
|
type: TYPES.MEMBER_EXPRESSION,
|
|
1670
3270
|
computed: false,
|
|
@@ -1711,11 +3311,14 @@
|
|
|
1711
3311
|
array = getCode$1(context, node.callee.object);
|
|
1712
3312
|
} else if (matches(genericPatterns.RAMDA, node)) {
|
|
1713
3313
|
array = getCode$1(context, node.arguments[1]);
|
|
1714
|
-
} else return;
|
|
3314
|
+
} else return;
|
|
1715
3315
|
|
|
3316
|
+
const byIdFunc = optionalChainingOptimizedName(functions.byId, node.callee);
|
|
3317
|
+
const byFunc = optionalChainingOptimizedName(functions.by, node.callee); // arr.filter(x => x.prop === something).length
|
|
1716
3318
|
|
|
1717
3319
|
if (functions.by === "filterBy" && matches(COUNT_BY_PATTERN, node.parent)) {
|
|
1718
|
-
const
|
|
3320
|
+
const func = optionalChainingOptimizedName("countBy", node.callee);
|
|
3321
|
+
const message = canBeShortenedWithCommons(func);
|
|
1719
3322
|
context.report({
|
|
1720
3323
|
node: node.parent,
|
|
1721
3324
|
message
|
|
@@ -1735,15 +3338,15 @@
|
|
|
1735
3338
|
|
|
1736
3339
|
if (idUsagePattern) {
|
|
1737
3340
|
const id = matches(idUsagePattern, predicate.body.left) ? getCode$1(context, predicate.body.right) : getCode$1(context, predicate.body.left);
|
|
1738
|
-
const fix = `${
|
|
1739
|
-
reportSuggestion({
|
|
3341
|
+
const fix = `${byIdFunc}(${id}, ${array})`;
|
|
3342
|
+
reportSuggestion$1({
|
|
1740
3343
|
context,
|
|
1741
3344
|
node,
|
|
1742
3345
|
fix,
|
|
1743
|
-
func:
|
|
3346
|
+
func: byIdFunc
|
|
1744
3347
|
});
|
|
1745
3348
|
} else {
|
|
1746
|
-
const message = canBeShortenedWithCommons(
|
|
3349
|
+
const message = canBeShortenedWithCommons(byFunc);
|
|
1747
3350
|
context.report({
|
|
1748
3351
|
node,
|
|
1749
3352
|
message
|
|
@@ -1752,7 +3355,7 @@
|
|
|
1752
3355
|
} else {
|
|
1753
3356
|
context.report({
|
|
1754
3357
|
node,
|
|
1755
|
-
message: canBeShortenedWithCommons(
|
|
3358
|
+
message: canBeShortenedWithCommons(byFunc)
|
|
1756
3359
|
});
|
|
1757
3360
|
}
|
|
1758
3361
|
};
|
|
@@ -1885,30 +3488,33 @@
|
|
|
1885
3488
|
var capitalize = {
|
|
1886
3489
|
operateOn: TYPES.BINARY_EXPRESSION,
|
|
1887
3490
|
check: (context, node) => {
|
|
1888
|
-
if (!
|
|
1889
|
-
const
|
|
1890
|
-
|
|
3491
|
+
if (!matchesAny(CAPITALIZE_PATTERNS, node)) return;
|
|
3492
|
+
const stringNode = node.right.type === TYPES.CHAIN_EXPRESSION ? node.right.expression.callee.object : node.right.callee.object;
|
|
3493
|
+
const func = optionalChainingOptimizedName("capitalize", node.right);
|
|
3494
|
+
const fix = `${func}(${getCode$1(context, stringNode)})`;
|
|
3495
|
+
reportSuggestion$1({
|
|
1891
3496
|
context,
|
|
1892
3497
|
node,
|
|
1893
3498
|
fix,
|
|
1894
|
-
func
|
|
3499
|
+
func
|
|
1895
3500
|
});
|
|
1896
3501
|
}
|
|
1897
3502
|
};
|
|
1898
3503
|
|
|
1899
3504
|
var copyKeys = {
|
|
1900
|
-
operateOn: TYPES.
|
|
3505
|
+
operateOn: TYPES.CALL_EXPRESSION,
|
|
1901
3506
|
check: (context, node) => {
|
|
1902
3507
|
if (!matches(COPY_KEYS_PATTERN, node)) return;
|
|
1903
|
-
const keyValuePairs = node.properties.slice(1).map(prop => [prop.value.property.name, prop.key.name]);
|
|
3508
|
+
const keyValuePairs = node.arguments[0].body.properties.slice(1).map(prop => [prop.value.property.name, prop.key.name]);
|
|
1904
3509
|
const keyMap = JSON.stringify(ramda.fromPairs(keyValuePairs));
|
|
1905
|
-
const sourceObject = getCode$1(context, node.
|
|
1906
|
-
const
|
|
1907
|
-
|
|
3510
|
+
const sourceObject = getCode$1(context, node.callee.object);
|
|
3511
|
+
const func = optionalChainingOptimizedName("copyKeys", node.callee);
|
|
3512
|
+
const fix = `${func}(${keyMap}, ${sourceObject})`;
|
|
3513
|
+
reportSuggestion$1({
|
|
1908
3514
|
context,
|
|
1909
3515
|
node,
|
|
1910
3516
|
fix,
|
|
1911
|
-
func
|
|
3517
|
+
func
|
|
1912
3518
|
});
|
|
1913
3519
|
}
|
|
1914
3520
|
};
|
|
@@ -1920,10 +3526,12 @@
|
|
|
1920
3526
|
|
|
1921
3527
|
if (!matches(DYNAMIC_ARRAY_PATTERN, node)) return;
|
|
1922
3528
|
const length = getCode$1(context, node.arguments[0].properties[0].value);
|
|
1923
|
-
const
|
|
1924
|
-
const
|
|
1925
|
-
const
|
|
1926
|
-
|
|
3529
|
+
const indexParam = (_node$arguments$1$par = node.arguments[1].params[1]) === null || _node$arguments$1$par === void 0 ? void 0 : _node$arguments$1$par.name;
|
|
3530
|
+
const generatorBody = getCode$1(context, node.arguments[1].body);
|
|
3531
|
+
const isArrOrObjExp = [TYPES.ARRAY_EXPRESSION, TYPES.OBJECT_EXPRESSION].includes(node.arguments[1].body.type);
|
|
3532
|
+
const generator = `${indexParam || "()"} => ${isArrOrObjExp ? `(${generatorBody})` : generatorBody}`;
|
|
3533
|
+
const fix = `dynamicArray(${length}, ${generator})`;
|
|
3534
|
+
reportSuggestion$1({
|
|
1927
3535
|
context,
|
|
1928
3536
|
node,
|
|
1929
3537
|
fix,
|
|
@@ -1951,11 +3559,18 @@
|
|
|
1951
3559
|
externalValueNode = node.body.left;
|
|
1952
3560
|
} else return;
|
|
1953
3561
|
|
|
3562
|
+
if (patternExistsDeep({
|
|
3563
|
+
type: TYPES.IDENTIFIER,
|
|
3564
|
+
name: argumentName
|
|
3565
|
+
}, externalValueNode)) {
|
|
3566
|
+
return;
|
|
3567
|
+
}
|
|
3568
|
+
|
|
1954
3569
|
const externalValue = getCode$1(context, externalValueNode);
|
|
1955
3570
|
fix = `isNot(${externalValue})`;
|
|
1956
3571
|
} else return;
|
|
1957
3572
|
|
|
1958
|
-
reportSuggestion({
|
|
3573
|
+
reportSuggestion$1({
|
|
1959
3574
|
context,
|
|
1960
3575
|
node,
|
|
1961
3576
|
fix,
|
|
@@ -1965,7 +3580,7 @@
|
|
|
1965
3580
|
};
|
|
1966
3581
|
|
|
1967
3582
|
var isNotEmpty = {
|
|
1968
|
-
operateOn: [TYPES.IF_STATEMENT, TYPES.WHILE_STATEMENT, TYPES.BINARY_EXPRESSION, TYPES.ARROW_FUNCTION_EXPRESSION],
|
|
3583
|
+
operateOn: [TYPES.IF_STATEMENT, TYPES.WHILE_STATEMENT, TYPES.BINARY_EXPRESSION, TYPES.ARROW_FUNCTION_EXPRESSION, TYPES.UNARY_EXPRESSION],
|
|
1969
3584
|
check: (context, node) => {
|
|
1970
3585
|
let fix = null;
|
|
1971
3586
|
let message = "";
|
|
@@ -1973,11 +3588,20 @@
|
|
|
1973
3588
|
|
|
1974
3589
|
if (matches(NOT_EMPTY_PATTERNS.ARROW_FUNC, node)) {
|
|
1975
3590
|
fix = "isNotEmpty";
|
|
1976
|
-
} else if (matchesAny([NOT_EMPTY_PATTERNS.BINARY_EXP, NOT_EMPTY_PATTERNS.CONDT_STAT], node)) {
|
|
1977
|
-
const
|
|
1978
|
-
|
|
3591
|
+
} else if (matchesAny([NOT_EMPTY_PATTERNS.BINARY_EXP, NOT_EMPTY_PATTERNS.CONDT_STAT, NOT_EMPTY_PATTERNS.UNARY_EXP], node)) {
|
|
3592
|
+
const expNode = {
|
|
3593
|
+
[TYPES.BINARY_EXPRESSION]: node.left,
|
|
3594
|
+
[TYPES.UNARY_EXPRESSION]: node.argument,
|
|
3595
|
+
[TYPES.IF_STATEMENT]: node.test,
|
|
3596
|
+
[TYPES.WHILE_STATEMENT]: node.test
|
|
3597
|
+
}[node.type];
|
|
1979
3598
|
const isObjLenCheck = matches(OBJ_KEY_LENGTH_PATTERN$1, expNode);
|
|
1980
|
-
nodeToBeReplaced =
|
|
3599
|
+
nodeToBeReplaced = {
|
|
3600
|
+
[TYPES.BINARY_EXPRESSION]: node,
|
|
3601
|
+
[TYPES.UNARY_EXPRESSION]: node.parent,
|
|
3602
|
+
[TYPES.IF_STATEMENT]: node.test,
|
|
3603
|
+
[TYPES.WHILE_STATEMENT]: node.test
|
|
3604
|
+
}[node.type];
|
|
1981
3605
|
|
|
1982
3606
|
if (isObjLenCheck) {
|
|
1983
3607
|
const objName = getCode$1(context, expNode.object.arguments[0]);
|
|
@@ -1989,7 +3613,7 @@
|
|
|
1989
3613
|
}
|
|
1990
3614
|
} else return;
|
|
1991
3615
|
|
|
1992
|
-
reportSuggestion({
|
|
3616
|
+
reportSuggestion$1({
|
|
1993
3617
|
context,
|
|
1994
3618
|
node: nodeToBeReplaced,
|
|
1995
3619
|
fix,
|
|
@@ -2022,7 +3646,7 @@
|
|
|
2022
3646
|
fix = `isNotEqualDeep(${externalValue})`;
|
|
2023
3647
|
} else return;
|
|
2024
3648
|
|
|
2025
|
-
reportSuggestion({
|
|
3649
|
+
reportSuggestion$1({
|
|
2026
3650
|
context,
|
|
2027
3651
|
node,
|
|
2028
3652
|
fix,
|
|
@@ -2040,10 +3664,10 @@
|
|
|
2040
3664
|
if (node.type === TYPES.ARROW_FUNCTION_EXPRESSION) {
|
|
2041
3665
|
fix = `isNotNil`;
|
|
2042
3666
|
} else if (node.type === TYPES.LOGICAL_EXPRESSION) {
|
|
2043
|
-
fix = `isNotNil(${node.left.left
|
|
3667
|
+
fix = `isNotNil(${getCode$1(context, node.left.left)})`;
|
|
2044
3668
|
}
|
|
2045
3669
|
|
|
2046
|
-
reportSuggestion({
|
|
3670
|
+
reportSuggestion$1({
|
|
2047
3671
|
context,
|
|
2048
3672
|
node,
|
|
2049
3673
|
fix,
|
|
@@ -2055,14 +3679,23 @@
|
|
|
2055
3679
|
var noop = {
|
|
2056
3680
|
operateOn: [TYPES.FUNCTION_EXPRESSION, TYPES.ARROW_FUNCTION_EXPRESSION, TYPES.FUNCTION_DECLARATION],
|
|
2057
3681
|
check: (context, node) => {
|
|
2058
|
-
if (matches(NOOP_PATTERN, node))
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
3682
|
+
if (!matches(NOOP_PATTERN, node)) return;
|
|
3683
|
+
let fix = "noop";
|
|
3684
|
+
let nodeToBeReplaced = node;
|
|
3685
|
+
|
|
3686
|
+
if (node.type === TYPES.FUNCTION_DECLARATION) {
|
|
3687
|
+
fix = `const ${node.id.name} = noop`;
|
|
3688
|
+
} else if (node.type === TYPES.FUNCTION_EXPRESSION && node.parent.type === TYPES.PROPERTY) {
|
|
3689
|
+
nodeToBeReplaced = node.parent;
|
|
3690
|
+
fix = `${node.parent.key.name}: noop`;
|
|
2065
3691
|
}
|
|
3692
|
+
|
|
3693
|
+
reportSuggestion$1({
|
|
3694
|
+
context,
|
|
3695
|
+
node: nodeToBeReplaced,
|
|
3696
|
+
fix,
|
|
3697
|
+
func: "noop"
|
|
3698
|
+
});
|
|
2066
3699
|
}
|
|
2067
3700
|
};
|
|
2068
3701
|
|
|
@@ -2109,9 +3742,10 @@
|
|
|
2109
3742
|
} else return;
|
|
2110
3743
|
|
|
2111
3744
|
if (!matches(binaryExpressionPattern, comparison)) {
|
|
3745
|
+
const func = optionalChainingOptimizedName("replaceBy", node.callee);
|
|
2112
3746
|
context.report({
|
|
2113
3747
|
node,
|
|
2114
|
-
message: canBeShortenedWithCommons(
|
|
3748
|
+
message: canBeShortenedWithCommons(func)
|
|
2115
3749
|
});
|
|
2116
3750
|
return;
|
|
2117
3751
|
}
|
|
@@ -2129,12 +3763,13 @@
|
|
|
2129
3763
|
const id = getCode$1(context, externalId);
|
|
2130
3764
|
const replacement = getCode$1(context, replaceNode);
|
|
2131
3765
|
const array = getCode$1(context, node.callee.object);
|
|
2132
|
-
const
|
|
2133
|
-
|
|
3766
|
+
const func = optionalChainingOptimizedName("replaceById", node.callee);
|
|
3767
|
+
const fix = `${func}(${id}, ${replacement}, ${array})`;
|
|
3768
|
+
reportSuggestion$1({
|
|
2134
3769
|
context,
|
|
2135
3770
|
node,
|
|
2136
3771
|
fix,
|
|
2137
|
-
func
|
|
3772
|
+
func
|
|
2138
3773
|
});
|
|
2139
3774
|
}
|
|
2140
3775
|
};
|
|
@@ -2147,7 +3782,7 @@
|
|
|
2147
3782
|
|
|
2148
3783
|
if (label !== value) return;
|
|
2149
3784
|
const fix = `toLabelAndValue(${label})`;
|
|
2150
|
-
reportSuggestion({
|
|
3785
|
+
reportSuggestion$1({
|
|
2151
3786
|
context,
|
|
2152
3787
|
node,
|
|
2153
3788
|
fix,
|
|
@@ -2207,10 +3842,11 @@
|
|
|
2207
3842
|
create: context => ({
|
|
2208
3843
|
ImportDeclaration(node) {
|
|
2209
3844
|
const disallowSources = getPackagesAndAliases(context, BLACKLISTED_PACKAGES);
|
|
2210
|
-
|
|
2211
|
-
|
|
3845
|
+
const impSrc = node.source.value;
|
|
3846
|
+
const pkgName = disallowSources.find(src => impSrc === src || impSrc.startsWith(`${src}/`));
|
|
3847
|
+
if (pkgName) context.report({
|
|
2212
3848
|
node,
|
|
2213
|
-
message: disallowUse(
|
|
3849
|
+
message: disallowUse(pkgName)
|
|
2214
3850
|
});
|
|
2215
3851
|
}
|
|
2216
3852
|
|
|
@@ -2701,9 +4337,7 @@
|
|
|
2701
4337
|
const ARRAY_INSERTS_PATTERN = {
|
|
2702
4338
|
APPEND: {
|
|
2703
4339
|
// x => [...x, y]
|
|
2704
|
-
params: [
|
|
2705
|
-
type: TYPES.IDENTIFIER
|
|
2706
|
-
}],
|
|
4340
|
+
params: params => params.length === 1 && params[0].type === TYPES.IDENTIFIER,
|
|
2707
4341
|
body: {
|
|
2708
4342
|
type: TYPES.ARRAY_EXPRESSION,
|
|
2709
4343
|
elements: [{
|
|
@@ -2723,9 +4357,7 @@
|
|
|
2723
4357
|
},
|
|
2724
4358
|
PREPEND: {
|
|
2725
4359
|
// x => [y, ...x]
|
|
2726
|
-
params: [
|
|
2727
|
-
type: TYPES.IDENTIFIER
|
|
2728
|
-
}],
|
|
4360
|
+
params: params => params.length === 1 && params[0].type === TYPES.IDENTIFIER,
|
|
2729
4361
|
body: {
|
|
2730
4362
|
type: TYPES.ARRAY_EXPRESSION,
|
|
2731
4363
|
elements: [{
|
|
@@ -2745,9 +4377,7 @@
|
|
|
2745
4377
|
},
|
|
2746
4378
|
CONCAT: {
|
|
2747
4379
|
// x => [...x, ...y]
|
|
2748
|
-
params: [
|
|
2749
|
-
type: TYPES.IDENTIFIER
|
|
2750
|
-
}],
|
|
4380
|
+
params: params => params.length === 1 && params[0].type === TYPES.IDENTIFIER,
|
|
2751
4381
|
body: {
|
|
2752
4382
|
type: TYPES.ARRAY_EXPRESSION,
|
|
2753
4383
|
elements: [{
|
|
@@ -2932,9 +4562,9 @@
|
|
|
2932
4562
|
return name === ((_root$params$9 = root.params[0]) === null || _root$params$9 === void 0 ? void 0 : _root$params$9.name);
|
|
2933
4563
|
}
|
|
2934
4564
|
},
|
|
2935
|
-
property: {
|
|
2936
|
-
type: TYPES.IDENTIFIER
|
|
2937
|
-
}
|
|
4565
|
+
property: property => matches({
|
|
4566
|
+
type: ramda.includes(ramda.__, [TYPES.IDENTIFIER, TYPES.LITERAL])
|
|
4567
|
+
}, property)
|
|
2938
4568
|
}
|
|
2939
4569
|
},
|
|
2940
4570
|
DESTRUCTURE: {
|
|
@@ -3002,9 +4632,6 @@
|
|
|
3002
4632
|
|
|
3003
4633
|
return name === ((_root$params$10 = root.params[0]) === null || _root$params$10 === void 0 ? void 0 : _root$params$10.name);
|
|
3004
4634
|
}
|
|
3005
|
-
},
|
|
3006
|
-
property: {
|
|
3007
|
-
type: TYPES.IDENTIFIER
|
|
3008
4635
|
}
|
|
3009
4636
|
}
|
|
3010
4637
|
}
|
|
@@ -3034,7 +4661,7 @@
|
|
|
3034
4661
|
value: 0
|
|
3035
4662
|
}]
|
|
3036
4663
|
};
|
|
3037
|
-
const RAMDA_IMPORT_PATTERN = {
|
|
4664
|
+
const RAMDA_IMPORT_PATTERN$1 = {
|
|
3038
4665
|
type: TYPES.IMPORT_DECLARATION,
|
|
3039
4666
|
source: {
|
|
3040
4667
|
type: TYPES.LITERAL,
|
|
@@ -3080,9 +4707,35 @@
|
|
|
3080
4707
|
type: TYPES.UNARY_EXPRESSION,
|
|
3081
4708
|
operator: "!",
|
|
3082
4709
|
prefix: true,
|
|
3083
|
-
argument: matchesAny([ARRAY_LENGTH_PATTERN, OBJ_KEY_LENGTH_PATTERN])
|
|
4710
|
+
argument: matchesAny([ARRAY_LENGTH_PATTERN, OBJ_KEY_LENGTH_PATTERN]),
|
|
4711
|
+
parent: {
|
|
4712
|
+
type: notEquals(TYPES.UNARY_EXPRESSION),
|
|
4713
|
+
operator: notEquals("!")
|
|
4714
|
+
}
|
|
3084
4715
|
}];
|
|
3085
|
-
|
|
4716
|
+
|
|
4717
|
+
const replacer = nodeReplacerWithImports(RAMDA_IMPORT_PATTERN$1);
|
|
4718
|
+
const reportSuggestion = ({
|
|
4719
|
+
context,
|
|
4720
|
+
node,
|
|
4721
|
+
fix,
|
|
4722
|
+
functions,
|
|
4723
|
+
message = "",
|
|
4724
|
+
importNullSafe = false
|
|
4725
|
+
}) => context.report({
|
|
4726
|
+
node,
|
|
4727
|
+
message: message || canBeReplacedWith(fix),
|
|
4728
|
+
suggest: [{
|
|
4729
|
+
desc: `Replace with ${Array.isArray(functions) ? functions[0] : functions} function`,
|
|
4730
|
+
fix: replacer.replaceNode({
|
|
4731
|
+
context,
|
|
4732
|
+
node,
|
|
4733
|
+
fix,
|
|
4734
|
+
functions,
|
|
4735
|
+
importNullSafe
|
|
4736
|
+
})
|
|
4737
|
+
}]
|
|
4738
|
+
});
|
|
3086
4739
|
|
|
3087
4740
|
var arrayInsertsLintCheck = {
|
|
3088
4741
|
operateOn: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
@@ -3101,18 +4754,11 @@
|
|
|
3101
4754
|
|
|
3102
4755
|
if (!fix) return;
|
|
3103
4756
|
const funcName = fix.split("(")[0];
|
|
3104
|
-
|
|
4757
|
+
reportSuggestion({
|
|
4758
|
+
context,
|
|
3105
4759
|
node,
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
desc: `Replace with ${funcName} function`,
|
|
3109
|
-
fix: replacer.replaceNode({
|
|
3110
|
-
context,
|
|
3111
|
-
node,
|
|
3112
|
-
fix,
|
|
3113
|
-
functions: funcName
|
|
3114
|
-
})
|
|
3115
|
-
}]
|
|
4760
|
+
fix,
|
|
4761
|
+
functions: funcName
|
|
3116
4762
|
});
|
|
3117
4763
|
}
|
|
3118
4764
|
};
|
|
@@ -3134,18 +4780,11 @@
|
|
|
3134
4780
|
};
|
|
3135
4781
|
if (patternExistsDeep(selfReferencingPattern, property.value)) return;
|
|
3136
4782
|
const fix = convertToAssoc(context, node);
|
|
3137
|
-
|
|
4783
|
+
reportSuggestion({
|
|
4784
|
+
context,
|
|
3138
4785
|
node,
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
desc: "Replace with assoc function",
|
|
3142
|
-
fix: replacer.replaceNode({
|
|
3143
|
-
context,
|
|
3144
|
-
node,
|
|
3145
|
-
fix,
|
|
3146
|
-
functions: "assoc"
|
|
3147
|
-
})
|
|
3148
|
-
}]
|
|
4786
|
+
fix,
|
|
4787
|
+
functions: "assoc"
|
|
3149
4788
|
});
|
|
3150
4789
|
}
|
|
3151
4790
|
};
|
|
@@ -3155,18 +4794,11 @@
|
|
|
3155
4794
|
check: (context, node) => {
|
|
3156
4795
|
if (matches(JSON_EQUALS_PATTERN, node)) {
|
|
3157
4796
|
const fix = `equals(${getCode$1(context, node.left.arguments[0])}, ${getCode$1(context, node.right.arguments[0])})`;
|
|
3158
|
-
|
|
4797
|
+
reportSuggestion({
|
|
4798
|
+
context,
|
|
3159
4799
|
node,
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
desc: "Replace with equals function",
|
|
3163
|
-
fix: replacer.replaceNode({
|
|
3164
|
-
context,
|
|
3165
|
-
node,
|
|
3166
|
-
fix,
|
|
3167
|
-
functions: "equals"
|
|
3168
|
-
})
|
|
3169
|
-
}]
|
|
4800
|
+
fix,
|
|
4801
|
+
functions: "equals"
|
|
3170
4802
|
});
|
|
3171
4803
|
}
|
|
3172
4804
|
}
|
|
@@ -3176,18 +4808,11 @@
|
|
|
3176
4808
|
operateOn: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
3177
4809
|
check: (context, node) => {
|
|
3178
4810
|
if (matches(IDENTITY_PATTERN, node)) {
|
|
3179
|
-
|
|
4811
|
+
reportSuggestion({
|
|
4812
|
+
context,
|
|
3180
4813
|
node,
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
desc: "Replace with identity function",
|
|
3184
|
-
fix: replacer.replaceNode({
|
|
3185
|
-
context,
|
|
3186
|
-
node,
|
|
3187
|
-
fix: "identity",
|
|
3188
|
-
functions: "identity"
|
|
3189
|
-
})
|
|
3190
|
-
}]
|
|
4814
|
+
fix: "identity",
|
|
4815
|
+
functions: "identity"
|
|
3191
4816
|
});
|
|
3192
4817
|
}
|
|
3193
4818
|
}
|
|
@@ -3198,7 +4823,7 @@
|
|
|
3198
4823
|
check: (context, node) => {
|
|
3199
4824
|
if (!matchesAny(EMPTY_PATTERN, node)) return;
|
|
3200
4825
|
let fix = null;
|
|
3201
|
-
let message = "";
|
|
4826
|
+
let message = "Can be replaced with isEmpty function";
|
|
3202
4827
|
const isBinaryExp = node.type === TYPES.BINARY_EXPRESSION;
|
|
3203
4828
|
const expNode = isBinaryExp ? node.left : node.argument;
|
|
3204
4829
|
const isObjLenCheck = matches(OBJ_KEY_LENGTH_PATTERN, expNode);
|
|
@@ -3215,9 +4840,9 @@
|
|
|
3215
4840
|
reportSuggestion({
|
|
3216
4841
|
context,
|
|
3217
4842
|
node,
|
|
4843
|
+
message,
|
|
3218
4844
|
fix,
|
|
3219
|
-
|
|
3220
|
-
message
|
|
4845
|
+
functions: "isEmpty"
|
|
3221
4846
|
});
|
|
3222
4847
|
}
|
|
3223
4848
|
};
|
|
@@ -3231,7 +4856,7 @@
|
|
|
3231
4856
|
context,
|
|
3232
4857
|
node,
|
|
3233
4858
|
fix,
|
|
3234
|
-
|
|
4859
|
+
functions: "isNil"
|
|
3235
4860
|
});
|
|
3236
4861
|
}
|
|
3237
4862
|
};
|
|
@@ -3258,51 +4883,41 @@
|
|
|
3258
4883
|
const properties = node.body.properties.slice(1);
|
|
3259
4884
|
if (patternExistsDeep(selfReferencingPattern, properties)) return;
|
|
3260
4885
|
const fix = convertToMergeLeft(context, node);
|
|
3261
|
-
|
|
4886
|
+
reportSuggestion({
|
|
4887
|
+
context,
|
|
3262
4888
|
node,
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
desc: "Replace with mergeLeft function",
|
|
3266
|
-
fix: replacer.replaceNode({
|
|
3267
|
-
context,
|
|
3268
|
-
node,
|
|
3269
|
-
fix,
|
|
3270
|
-
functions: "mergeLeft"
|
|
3271
|
-
})
|
|
3272
|
-
}]
|
|
4889
|
+
fix,
|
|
4890
|
+
functions: "mergeLeft"
|
|
3273
4891
|
});
|
|
3274
4892
|
}
|
|
3275
4893
|
};
|
|
3276
4894
|
|
|
3277
|
-
const reportViolation = (context, node, fix) => context.report({
|
|
3278
|
-
node,
|
|
3279
|
-
message: canBeReplacedWith(fix),
|
|
3280
|
-
suggest: [{
|
|
3281
|
-
desc: "Replace with pluck function",
|
|
3282
|
-
fix: replacer.replaceNode({
|
|
3283
|
-
context,
|
|
3284
|
-
node,
|
|
3285
|
-
fix,
|
|
3286
|
-
functions: "pluck"
|
|
3287
|
-
})
|
|
3288
|
-
}]
|
|
3289
|
-
});
|
|
3290
|
-
|
|
3291
4895
|
var pluckLintCheck = {
|
|
3292
4896
|
operateOn: TYPES.CALL_EXPRESSION,
|
|
3293
4897
|
check: (context, node) => {
|
|
3294
4898
|
if (matches(PLUCK_PATTERNS.OBJECT_ARROW_FUNCTION, node)) {
|
|
3295
4899
|
const code = getCode$1(context, node.callee.object);
|
|
4900
|
+
const isNullSafeRequired = isOptionalChainingPresent(node.callee);
|
|
4901
|
+
const callee = isNullSafeRequired ? "nullSafe(pluck)" : "pluck";
|
|
3296
4902
|
const func = node.arguments[0];
|
|
4903
|
+
let fix = null;
|
|
3297
4904
|
|
|
3298
4905
|
if (matches(PLUCK_PATTERNS.IDENTIFIER, func)) {
|
|
3299
|
-
const
|
|
3300
|
-
|
|
4906
|
+
const property = func.body.property;
|
|
4907
|
+
const subtitute = property.type === TYPES.IDENTIFIER && func.body.computed ? property.name : `"${func.body.computed ? property.value : property.name}"`;
|
|
4908
|
+
fix = `${callee}(${subtitute}, ${code})`;
|
|
3301
4909
|
} else if (matches(PLUCK_PATTERNS.DESTRUCTURE, func)) {
|
|
3302
4910
|
const propertyName = func.params[0].properties[0].value.name;
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
4911
|
+
fix = `${callee}("${propertyName}", ${code})`;
|
|
4912
|
+
} else return;
|
|
4913
|
+
|
|
4914
|
+
reportSuggestion({
|
|
4915
|
+
context,
|
|
4916
|
+
node,
|
|
4917
|
+
fix,
|
|
4918
|
+
functions: "pluck",
|
|
4919
|
+
importNullSafe: isNullSafeRequired
|
|
4920
|
+
});
|
|
3306
4921
|
}
|
|
3307
4922
|
}
|
|
3308
4923
|
};
|
|
@@ -3316,23 +4931,21 @@
|
|
|
3316
4931
|
if (matches(PROP_PATTERNS.OBJECT, node)) {
|
|
3317
4932
|
fix = `prop("${node.body.name}")`;
|
|
3318
4933
|
} else if (matches(PROP_PATTERNS.IDENTITY, node)) {
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
return;
|
|
3322
|
-
}
|
|
4934
|
+
const isComputed = node.body.computed;
|
|
4935
|
+
const propertyType = node.body.property.type;
|
|
3323
4936
|
|
|
3324
|
-
|
|
4937
|
+
if (isComputed) {
|
|
4938
|
+
fix = propertyType === TYPES.IDENTIFIER ? `prop(${node.body.property.name})` : `prop("${node.body.property.value}")`;
|
|
4939
|
+
} else {
|
|
4940
|
+
fix = `prop("${node.body.property.name}")`;
|
|
4941
|
+
}
|
|
4942
|
+
} else return;
|
|
4943
|
+
|
|
4944
|
+
reportSuggestion({
|
|
4945
|
+
context,
|
|
3325
4946
|
node,
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
desc: "Replace with prop function",
|
|
3329
|
-
fix: replacer.replaceNode({
|
|
3330
|
-
context,
|
|
3331
|
-
node,
|
|
3332
|
-
fix,
|
|
3333
|
-
functions: "prop"
|
|
3334
|
-
})
|
|
3335
|
-
}]
|
|
4947
|
+
fix,
|
|
4948
|
+
functions: "prop"
|
|
3336
4949
|
});
|
|
3337
4950
|
}
|
|
3338
4951
|
};
|
|
@@ -3369,31 +4982,27 @@
|
|
|
3369
4982
|
if (!accumulator || !delta) return;
|
|
3370
4983
|
let fix = null;
|
|
3371
4984
|
let functions = ["sum"];
|
|
4985
|
+
const code = getCode$1(context, node.callee.object);
|
|
4986
|
+
let isNullSafeRequired = false;
|
|
3372
4987
|
|
|
3373
4988
|
if (reduceFunc.params[1].type === TYPES.IDENTIFIER && delta.type === TYPES.IDENTIFIER && delta.name === reduceFunc.params[1].name) {
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
fix =
|
|
4989
|
+
isNullSafeRequired = isOptionalChainingPresent(node.callee);
|
|
4990
|
+
const func = isNullSafeRequired ? "nullSafe(sum)" : "sum";
|
|
4991
|
+
fix = `${func}(${code})`;
|
|
4992
|
+
} else if (reduceFunc.params[1].type === TYPES.OBJECT_PATTERN && delta.type === TYPES.IDENTIFIER && delta.name === reduceFunc.params[1].properties[0].value.name && !isOptionalChainingPresent(node.callee)) {
|
|
4993
|
+
fix = `sum(pluck("${delta.name}", ${code}))`;
|
|
3377
4994
|
functions = ["sum", "pluck"];
|
|
3378
|
-
} else if (reduceFunc.params[1].type === TYPES.IDENTIFIER && delta.type === TYPES.MEMBER_EXPRESSION && delta.property.type === TYPES.IDENTIFIER && delta.object.name === reduceFunc.params[1].name) {
|
|
3379
|
-
fix = `sum(pluck("${delta.property.name}", ${
|
|
4995
|
+
} else if (reduceFunc.params[1].type === TYPES.IDENTIFIER && delta.type === TYPES.MEMBER_EXPRESSION && delta.property.type === TYPES.IDENTIFIER && delta.object.name === reduceFunc.params[1].name && !isOptionalChainingPresent(node.callee)) {
|
|
4996
|
+
fix = `sum(pluck("${delta.property.name}", ${code}))`;
|
|
3380
4997
|
functions = ["sum", "pluck"];
|
|
3381
|
-
} else
|
|
3382
|
-
return;
|
|
3383
|
-
}
|
|
4998
|
+
} else return;
|
|
3384
4999
|
|
|
3385
|
-
|
|
5000
|
+
reportSuggestion({
|
|
5001
|
+
context,
|
|
3386
5002
|
node,
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
fix: replacer.replaceNode({
|
|
3391
|
-
context,
|
|
3392
|
-
node,
|
|
3393
|
-
fix,
|
|
3394
|
-
functions
|
|
3395
|
-
})
|
|
3396
|
-
}]
|
|
5003
|
+
fix,
|
|
5004
|
+
functions,
|
|
5005
|
+
importNullSafe: isNullSafeRequired
|
|
3397
5006
|
});
|
|
3398
5007
|
}
|
|
3399
5008
|
};
|
|
@@ -3419,6 +5028,61 @@
|
|
|
3419
5028
|
}
|
|
3420
5029
|
};
|
|
3421
5030
|
|
|
5031
|
+
const BREAK_STATEMENT_PATTERN = {
|
|
5032
|
+
type: TYPES.BREAK_STATEMENT
|
|
5033
|
+
};
|
|
5034
|
+
const RETURN_STATEMENT_PATTERN = {
|
|
5035
|
+
type: TYPES.RETURN_STATEMENT
|
|
5036
|
+
};
|
|
5037
|
+
const ARRAY_LENGTH_TEST_PATTERN = {
|
|
5038
|
+
test: {
|
|
5039
|
+
right: {
|
|
5040
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
5041
|
+
property: {
|
|
5042
|
+
name: "length"
|
|
5043
|
+
}
|
|
5044
|
+
}
|
|
5045
|
+
}
|
|
5046
|
+
};
|
|
5047
|
+
const CHAR_AT_PATTERN = {
|
|
5048
|
+
type: TYPES.CALL_EXPRESSION,
|
|
5049
|
+
callee: {
|
|
5050
|
+
property: {
|
|
5051
|
+
name: ramda.includes(ramda.__, ["charAt", "charCodeAt"])
|
|
5052
|
+
}
|
|
5053
|
+
}
|
|
5054
|
+
};
|
|
5055
|
+
|
|
5056
|
+
const isForLoopReplacable = node => ramda.not(patternExistsDeep(BREAK_STATEMENT_PATTERN, node.body) || patternExistsDeep(RETURN_STATEMENT_PATTERN, node.body) || patternExistsDeep(CHAR_AT_PATTERN, node.body));
|
|
5057
|
+
|
|
5058
|
+
var useArrayMethods = {
|
|
5059
|
+
meta: {
|
|
5060
|
+
type: "suggestion",
|
|
5061
|
+
docs: {
|
|
5062
|
+
description: "Warns when for loop is used instead of array methods."
|
|
5063
|
+
}
|
|
5064
|
+
},
|
|
5065
|
+
create: context => ({
|
|
5066
|
+
ForStatement(node) {
|
|
5067
|
+
if (!matches(ARRAY_LENGTH_TEST_PATTERN, node)) return;
|
|
5068
|
+
if (!isForLoopReplacable(node)) return;
|
|
5069
|
+
context.report({
|
|
5070
|
+
node,
|
|
5071
|
+
message: USE_ARRAY_METHODS
|
|
5072
|
+
});
|
|
5073
|
+
},
|
|
5074
|
+
|
|
5075
|
+
ForOfStatement(node) {
|
|
5076
|
+
if (!isForLoopReplacable(node)) return;
|
|
5077
|
+
context.report({
|
|
5078
|
+
node,
|
|
5079
|
+
message: USE_ARRAY_METHODS
|
|
5080
|
+
});
|
|
5081
|
+
}
|
|
5082
|
+
|
|
5083
|
+
})
|
|
5084
|
+
};
|
|
5085
|
+
|
|
3422
5086
|
const VALID_URL_TYPES = [TYPES.LITERAL, TYPES.TEMPLATE_LITERAL];
|
|
3423
5087
|
const AXIOS_GET_PATTERN = {
|
|
3424
5088
|
callee: {
|
|
@@ -3517,6 +5181,101 @@
|
|
|
3517
5181
|
})
|
|
3518
5182
|
};
|
|
3519
5183
|
|
|
5184
|
+
const COLORS = ["black", "white", "gray", "red", "yellow", "green", "blue", "indigo", "purple", "pink"];
|
|
5185
|
+
const SIZES = ["none", "sm", "md", "lg", "xl", "2xl", "3xl", "full"];
|
|
5186
|
+
const BORDER_COLOR_PATTERNS = COLORS.map(color => new RegExp(`^((hover|focus|focus-visible):)?border-${color}(-[0-9]{2,3})?$`));
|
|
5187
|
+
const BORDER_RADIUS_PATTERNS = SIZES.map(size => new RegExp(`^rounded(-${size})?$`));
|
|
5188
|
+
const BOX_SHADOW_PATTERNS = SIZES.map(size => new RegExp(`^shadow(-${size})?$`));
|
|
5189
|
+
const TEXT_COLOR_PATTERNS = COLORS.map(color => new RegExp(`^((hover|focus|focus-visible):)?text-${color}(-[0-9]{2,3})?$`));
|
|
5190
|
+
const TAILWIND_CLASS_PATTERNS = {
|
|
5191
|
+
borderColor: {
|
|
5192
|
+
patterns: BORDER_COLOR_PATTERNS,
|
|
5193
|
+
message: USE_NEETOUI_BORDER_COLOR
|
|
5194
|
+
},
|
|
5195
|
+
borderRadius: {
|
|
5196
|
+
patterns: BORDER_RADIUS_PATTERNS,
|
|
5197
|
+
message: USE_NEETOUI_BORDER_RADIUS
|
|
5198
|
+
},
|
|
5199
|
+
boxShadow: {
|
|
5200
|
+
patterns: BOX_SHADOW_PATTERNS,
|
|
5201
|
+
message: USE_NEETOUI_BOX_SHADOW
|
|
5202
|
+
},
|
|
5203
|
+
textColor: {
|
|
5204
|
+
patterns: TEXT_COLOR_PATTERNS,
|
|
5205
|
+
message: USE_NEETOUI_TEXT_COLOR
|
|
5206
|
+
}
|
|
5207
|
+
};
|
|
5208
|
+
|
|
5209
|
+
const getLocation = ({
|
|
5210
|
+
nodeValue,
|
|
5211
|
+
nodeLoc,
|
|
5212
|
+
cssClass
|
|
5213
|
+
}) => {
|
|
5214
|
+
const startCol = nodeLoc.start.column + nodeValue.indexOf(cssClass) + 1;
|
|
5215
|
+
const endCol = startCol + cssClass.length;
|
|
5216
|
+
const line = nodeLoc.start.line;
|
|
5217
|
+
return {
|
|
5218
|
+
start: {
|
|
5219
|
+
line,
|
|
5220
|
+
column: startCol
|
|
5221
|
+
},
|
|
5222
|
+
end: {
|
|
5223
|
+
line,
|
|
5224
|
+
column: endCol
|
|
5225
|
+
}
|
|
5226
|
+
};
|
|
5227
|
+
};
|
|
5228
|
+
|
|
5229
|
+
const getCssProperty = cssClass => {
|
|
5230
|
+
let property = "";
|
|
5231
|
+
if (cssClass.includes("text")) property = "textColor";else if (cssClass.includes("border")) property = "borderColor";else if (cssClass.includes("rounded")) property = "borderRadius";else if (cssClass.includes("shadow")) property = "boxShadow";
|
|
5232
|
+
return property;
|
|
5233
|
+
};
|
|
5234
|
+
|
|
5235
|
+
const checkAndReportTailwindClasses = (context, node) => {
|
|
5236
|
+
const nodeValue = node.type === TYPES.LITERAL ? node.value : node.value.cooked;
|
|
5237
|
+
if (typeof nodeValue !== "string") return;
|
|
5238
|
+
const cssClasses = nodeValue.split(" ");
|
|
5239
|
+
cssClasses.forEach(cssClass => {
|
|
5240
|
+
const cssProperty = getCssProperty(cssClass);
|
|
5241
|
+
if (!cssProperty) return;
|
|
5242
|
+
const {
|
|
5243
|
+
patterns,
|
|
5244
|
+
message
|
|
5245
|
+
} = TAILWIND_CLASS_PATTERNS[cssProperty];
|
|
5246
|
+
const isPatternMatched = patterns.some(pattern => pattern.test(cssClass));
|
|
5247
|
+
if (!isPatternMatched) return;
|
|
5248
|
+
context.report({
|
|
5249
|
+
node,
|
|
5250
|
+
loc: getLocation({
|
|
5251
|
+
nodeValue,
|
|
5252
|
+
nodeLoc: node.loc,
|
|
5253
|
+
cssClass
|
|
5254
|
+
}),
|
|
5255
|
+
message
|
|
5256
|
+
});
|
|
5257
|
+
});
|
|
5258
|
+
};
|
|
5259
|
+
|
|
5260
|
+
var useNeetouiClasses = {
|
|
5261
|
+
meta: {
|
|
5262
|
+
type: "suggestion",
|
|
5263
|
+
docs: {
|
|
5264
|
+
description: "Warns when tailwind classes are used instead of neetoUI classes"
|
|
5265
|
+
}
|
|
5266
|
+
},
|
|
5267
|
+
create: context => ({
|
|
5268
|
+
Literal(node) {
|
|
5269
|
+
checkAndReportTailwindClasses(context, node);
|
|
5270
|
+
},
|
|
5271
|
+
|
|
5272
|
+
TemplateElement(node) {
|
|
5273
|
+
checkAndReportTailwindClasses(context, node);
|
|
5274
|
+
}
|
|
5275
|
+
|
|
5276
|
+
})
|
|
5277
|
+
};
|
|
5278
|
+
|
|
3520
5279
|
const SNAKE_CASE_REGEX = /^[a-z0-9_]+$/;
|
|
3521
5280
|
|
|
3522
5281
|
const isSnakeCase = text => SNAKE_CASE_REGEX.test(text);
|
|
@@ -3566,22 +5325,12 @@
|
|
|
3566
5325
|
const aliases = context.options[0];
|
|
3567
5326
|
if (ramda.isEmpty(aliases) || ramda.isNil(aliases)) return;
|
|
3568
5327
|
const importPath = node.source.value;
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
if (
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
if (matches.length === 0) return;
|
|
3576
|
-
const aliasMatch = matches[matches.length - 1];
|
|
3577
|
-
importPathWithAlias = importFullPath.replace(aliasMatch[1], aliasMatch[0]);
|
|
3578
|
-
if (importPath.length < importPathWithAlias.length) return;
|
|
3579
|
-
} else {
|
|
3580
|
-
const aliasMatch = Object.entries(aliases).find(([, path]) => importPath.startsWith(path));
|
|
3581
|
-
if (!aliasMatch) return;
|
|
3582
|
-
importPathWithAlias = importPath.replace(aliasMatch[1], aliasMatch[0]);
|
|
3583
|
-
}
|
|
3584
|
-
|
|
5328
|
+
const importFullPath = importPath.startsWith("../") ? path__default["default"].resolve(context.getFilename(), "../", importPath) : importPath;
|
|
5329
|
+
const matches = Object.entries(aliases).filter(([, path]) => importFullPath.startsWith(path) && ["/", undefined].includes(importFullPath.split(path)[1][0])).sort((first, second) => first.length - second.length);
|
|
5330
|
+
if (matches.length === 0) return;
|
|
5331
|
+
const aliasMatch = matches[matches.length - 1];
|
|
5332
|
+
const importPathWithAlias = importFullPath.replace(aliasMatch[1], aliasMatch[0]);
|
|
5333
|
+
if (importPath.length < importPathWithAlias.length) return;
|
|
3585
5334
|
context.report({
|
|
3586
5335
|
node,
|
|
3587
5336
|
message: canBeReplacedWith(importPathWithAlias),
|
|
@@ -3609,14 +5358,14 @@
|
|
|
3609
5358
|
},
|
|
3610
5359
|
create: context => ({
|
|
3611
5360
|
Property(node) {
|
|
3612
|
-
var _node$parent, _node$parent$parent, _node$parent$parent$k, _jsconfigData$compile;
|
|
5361
|
+
var _context$options, _context$options$, _node$parent, _node$parent$parent, _node$parent$parent$k, _context$options2, _context$options2$, _jsconfigData$compile;
|
|
3613
5362
|
|
|
3614
5363
|
const filename = context.getFilename();
|
|
3615
|
-
const isInsideAliasFile = filename.
|
|
5364
|
+
const isInsideAliasFile = filename === ((_context$options = context.options) === null || _context$options === void 0 ? void 0 : (_context$options$ = _context$options[0]) === null || _context$options$ === void 0 ? void 0 : _context$options$.aliasFilePath);
|
|
3616
5365
|
if (!isInsideAliasFile) return;
|
|
3617
5366
|
const isInsideAliasProperty = ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : (_node$parent$parent = _node$parent.parent) === null || _node$parent$parent === void 0 ? void 0 : (_node$parent$parent$k = _node$parent$parent.key) === null || _node$parent$parent$k === void 0 ? void 0 : _node$parent$parent$k.name) === "alias";
|
|
3618
5367
|
if (!isInsideAliasProperty) return;
|
|
3619
|
-
const jsconfigData = parseJsconfigData(context.options[0]);
|
|
5368
|
+
const jsconfigData = parseJsconfigData((_context$options2 = context.options) === null || _context$options2 === void 0 ? void 0 : (_context$options2$ = _context$options2[0]) === null || _context$options2$ === void 0 ? void 0 : _context$options2$.jsconfigFilePath);
|
|
3620
5369
|
const jsconfigPaths = jsconfigData === null || jsconfigData === void 0 ? void 0 : (_jsconfigData$compile = jsconfigData.compilerOptions) === null || _jsconfigData$compile === void 0 ? void 0 : _jsconfigData$compile.paths;
|
|
3621
5370
|
if (!jsconfigPaths) return;
|
|
3622
5371
|
const aliasName = node.key.name;
|
|
@@ -3631,12 +5380,182 @@
|
|
|
3631
5380
|
})
|
|
3632
5381
|
};
|
|
3633
5382
|
|
|
5383
|
+
const PICK_PATTERN$1 = [{
|
|
5384
|
+
type: TYPES.CALL_EXPRESSION,
|
|
5385
|
+
callee: {
|
|
5386
|
+
type: TYPES.IDENTIFIER,
|
|
5387
|
+
name: "pick"
|
|
5388
|
+
},
|
|
5389
|
+
optional: false
|
|
5390
|
+
}]; // const { order, user } = useSampleStore((state) => ({ order: state.order, user: state.user }));
|
|
5391
|
+
// const [ order, user ] = useSampleStore((state) => [state.order, state.user]);
|
|
5392
|
+
|
|
5393
|
+
const ARROW_FUNCTION_PATTERN = [{
|
|
5394
|
+
type: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
5395
|
+
params: [{
|
|
5396
|
+
type: TYPES.IDENTIFIER
|
|
5397
|
+
}]
|
|
5398
|
+
}];
|
|
5399
|
+
const ZUSTAND_HOOK_USAGE_PATTERN = {
|
|
5400
|
+
kind: "const",
|
|
5401
|
+
declarations: [{
|
|
5402
|
+
type: TYPES.VARIABLE_DECLARATOR,
|
|
5403
|
+
init: {
|
|
5404
|
+
type: TYPES.CALL_EXPRESSION,
|
|
5405
|
+
callee: {
|
|
5406
|
+
type: TYPES.IDENTIFIER,
|
|
5407
|
+
name: name => name.match(/use[a-zA-z0-9].+Store/)
|
|
5408
|
+
},
|
|
5409
|
+
arguments: args => args.length === 1 && (matches(PICK_PATTERN$1, args) || matches(ARROW_FUNCTION_PATTERN, args))
|
|
5410
|
+
}
|
|
5411
|
+
}]
|
|
5412
|
+
};
|
|
5413
|
+
|
|
5414
|
+
var zustandRecommendComparatorFunctionUsage = {
|
|
5415
|
+
meta: {
|
|
5416
|
+
type: "warn",
|
|
5417
|
+
docs: {
|
|
5418
|
+
description: "Warn about the usage of picking multiple state items without comparator function from inside zustand store hooks"
|
|
5419
|
+
}
|
|
5420
|
+
},
|
|
5421
|
+
create: context => ({
|
|
5422
|
+
VariableDeclaration(node) {
|
|
5423
|
+
if (!matches(ZUSTAND_HOOK_USAGE_PATTERN, node)) return;
|
|
5424
|
+
context.report({
|
|
5425
|
+
node,
|
|
5426
|
+
message: DONT_USE_ZUSTAND_STORE_WITHOUT_COMPARATOR_FUNCTION
|
|
5427
|
+
});
|
|
5428
|
+
}
|
|
5429
|
+
|
|
5430
|
+
})
|
|
5431
|
+
};
|
|
5432
|
+
|
|
5433
|
+
// const order = useSampleStore(pick(["order"]), shallow);
|
|
5434
|
+
// const order = useSampleStore(pick([order]));
|
|
5435
|
+
// const order = useSampleStore(pick([order]), shallow);
|
|
5436
|
+
|
|
5437
|
+
const PICK_PATTERN = [{
|
|
5438
|
+
type: TYPES.CALL_EXPRESSION,
|
|
5439
|
+
callee: {
|
|
5440
|
+
type: TYPES.IDENTIFIER,
|
|
5441
|
+
name: "pick"
|
|
5442
|
+
},
|
|
5443
|
+
arguments: [{
|
|
5444
|
+
type: TYPES.ARRAY_EXPRESSION,
|
|
5445
|
+
elements: elements => elements.length === 1 && (matches([{
|
|
5446
|
+
type: TYPES.LITERAL
|
|
5447
|
+
}], elements) || matches([{
|
|
5448
|
+
type: TYPES.IDENTIFIER
|
|
5449
|
+
}], elements))
|
|
5450
|
+
}]
|
|
5451
|
+
}];
|
|
5452
|
+
const ZUSTAND_PICK_USAGE_PATTERN = {
|
|
5453
|
+
init: {
|
|
5454
|
+
type: TYPES.CALL_EXPRESSION,
|
|
5455
|
+
callee: {
|
|
5456
|
+
type: TYPES.IDENTIFIER,
|
|
5457
|
+
name: name => name.match(/use[a-zA-z0-9].+Store/)
|
|
5458
|
+
},
|
|
5459
|
+
arguments: PICK_PATTERN,
|
|
5460
|
+
optional: false
|
|
5461
|
+
}
|
|
5462
|
+
}; // import { ... } from 'ramda';
|
|
5463
|
+
|
|
5464
|
+
const RAMDA_IMPORT_PATTERN = {
|
|
5465
|
+
type: TYPES.IMPORT_DECLARATION,
|
|
5466
|
+
specifiers: [{
|
|
5467
|
+
type: TYPES.IMPORT_SPECIFIER,
|
|
5468
|
+
local: {
|
|
5469
|
+
type: TYPES.IDENTIFIER
|
|
5470
|
+
}
|
|
5471
|
+
}],
|
|
5472
|
+
source: {
|
|
5473
|
+
type: TYPES.LITERAL,
|
|
5474
|
+
value: "ramda"
|
|
5475
|
+
}
|
|
5476
|
+
}; // pick()
|
|
5477
|
+
|
|
5478
|
+
const PICK_PATTERN_SHORT = {
|
|
5479
|
+
type: TYPES.CALL_EXPRESSION,
|
|
5480
|
+
callee: {
|
|
5481
|
+
type: TYPES.IDENTIFIER,
|
|
5482
|
+
name: "pick"
|
|
5483
|
+
}
|
|
5484
|
+
}; // import { prop }
|
|
5485
|
+
|
|
5486
|
+
const PROP_IMPORT_PATTERN = {
|
|
5487
|
+
type: TYPES.IMPORT_SPECIFIER,
|
|
5488
|
+
imported: {
|
|
5489
|
+
type: TYPES.IDENTIFIER,
|
|
5490
|
+
name: "prop"
|
|
5491
|
+
}
|
|
5492
|
+
}; // useCurrentUserStore()
|
|
5493
|
+
|
|
5494
|
+
const findProgramNode = node => {
|
|
5495
|
+
const parentNode = node === null || node === void 0 ? void 0 : node.parent;
|
|
5496
|
+
if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.type) === TYPES.PROGRAM) return parentNode;
|
|
5497
|
+
return findProgramNode(parentNode);
|
|
5498
|
+
};
|
|
5499
|
+
const findRamdaSpecifiers = programNode => {
|
|
5500
|
+
const ramdaImportDeclaration = programNode.body.find(matches(RAMDA_IMPORT_PATTERN));
|
|
5501
|
+
const {
|
|
5502
|
+
specifiers: specifiersNode
|
|
5503
|
+
} = ramdaImportDeclaration;
|
|
5504
|
+
return specifiersNode[0];
|
|
5505
|
+
};
|
|
5506
|
+
|
|
5507
|
+
var zustandUsePropToPickSingleItem = {
|
|
5508
|
+
meta: {
|
|
5509
|
+
type: "error",
|
|
5510
|
+
docs: {
|
|
5511
|
+
description: "Throw error if pick function is used to pick a single item"
|
|
5512
|
+
},
|
|
5513
|
+
fixable: "code"
|
|
5514
|
+
},
|
|
5515
|
+
create: context => ({
|
|
5516
|
+
VariableDeclarator(node) {
|
|
5517
|
+
if (!matches(ZUSTAND_PICK_USAGE_PATTERN, node)) return;
|
|
5518
|
+
const pickNode = findMatchingNodesDeep(node, PICK_PATTERN_SHORT)[0];
|
|
5519
|
+
const item = pickNode.arguments[0].elements[0];
|
|
5520
|
+
const substitute = item.type === TYPES.IDENTIFIER ? item.name : `"${item.value}"`;
|
|
5521
|
+
const fix = `prop(${substitute})`;
|
|
5522
|
+
const programNode = findProgramNode(node);
|
|
5523
|
+
const importSpecifierNode = findRamdaSpecifiers(programNode);
|
|
5524
|
+
const comparatorFunctionNode = node.init.arguments[1];
|
|
5525
|
+
const propImportNode = findMatchingNodesDeep(context.getSourceCode().ast.body, PROP_IMPORT_PATTERN);
|
|
5526
|
+
context.report({
|
|
5527
|
+
node,
|
|
5528
|
+
message: USE_PROP_FOR_PICKING_SINGLE_ITEM,
|
|
5529
|
+
fix: fixer => {
|
|
5530
|
+
const fixerArray = [];
|
|
5531
|
+
fixerArray.push(fixer.replaceText(pickNode, fix));
|
|
5532
|
+
|
|
5533
|
+
if (propImportNode.length === 0) {
|
|
5534
|
+
fixerArray.push(fixer.insertTextAfter(importSpecifierNode, ", prop"));
|
|
5535
|
+
}
|
|
5536
|
+
|
|
5537
|
+
if (comparatorFunctionNode) {
|
|
5538
|
+
fixerArray.push(fixer.remove(comparatorFunctionNode));
|
|
5539
|
+
}
|
|
5540
|
+
|
|
5541
|
+
return fixerArray;
|
|
5542
|
+
}
|
|
5543
|
+
});
|
|
5544
|
+
}
|
|
5545
|
+
|
|
5546
|
+
})
|
|
5547
|
+
};
|
|
5548
|
+
|
|
3634
5549
|
var index = {
|
|
3635
5550
|
rules: {
|
|
5551
|
+
"minimize-zustand-store-access-scope": minimizeZustandStoreAccessScope,
|
|
3636
5552
|
"api-connector-name-should-match-filename": apiConnectorNameShouldMatchFilename,
|
|
3637
5553
|
"api-connector-should-use-default-export": apiConnectorShouldUseDefaultExport,
|
|
3638
5554
|
"combine-multiple-independent-awaits": combineMultipleIndependentAwaits,
|
|
3639
5555
|
"consistent-button-link-anchor": consistentButtonLinkAnchor,
|
|
5556
|
+
"ensure-zustand-stores-are-type-annotated": ensureZustandStoresAreTypeAnnotated,
|
|
5557
|
+
"ensure-zustand-import-names-are-consistent": ensureZustandImportNamesAreConsistent,
|
|
5558
|
+
"file-name-and-export-name-standards": fileNameAndExportNameStandards,
|
|
3640
5559
|
"neetocommons-tips": neetocommonsTips,
|
|
3641
5560
|
"no-blacklisted-imports": noBlacklistedImports,
|
|
3642
5561
|
"no-axios-import-outside-apis": noAxiosImportOutsideApis,
|
|
@@ -3654,12 +5573,15 @@
|
|
|
3654
5573
|
"ramda-tips": ramdaTips,
|
|
3655
5574
|
"routes-should-be-declared-and-default-exported": routesShouldBeDeclaredAndDefaultExported,
|
|
3656
5575
|
"routes-should-match-object-path": routesShouldMatchObjectPath,
|
|
5576
|
+
"use-array-methods": useArrayMethods,
|
|
3657
5577
|
"use-axios-config-for-passing-query-parameters": useAxiosConfigForPassingQueryParameters,
|
|
3658
|
-
"use-constant-case": useConstantCase,
|
|
3659
5578
|
"use-common-routes": useCommonRoutes,
|
|
5579
|
+
"use-neetoui-classes": useNeetouiClasses,
|
|
3660
5580
|
"use-snake-case-for-api-connector-filename": useSnakeCaseForApiConnectorFilename,
|
|
3661
5581
|
"use-webpack-alias": useWebpackAlias,
|
|
3662
|
-
"webpack-aliases-and-jsconfig-paths-should-be-in-sync": webpackAliasesAndJsconfigPathsShouldBeInSync
|
|
5582
|
+
"webpack-aliases-and-jsconfig-paths-should-be-in-sync": webpackAliasesAndJsconfigPathsShouldBeInSync,
|
|
5583
|
+
"zustand-recommend-comparator-function-usage": zustandRecommendComparatorFunctionUsage,
|
|
5584
|
+
"zustand-use-prop-to-pick-single-item": zustandUsePropToPickSingleItem
|
|
3663
5585
|
}
|
|
3664
5586
|
};
|
|
3665
5587
|
|