@bigbinary/eslint-plugin-neeto 1.0.14 → 1.0.15

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.
Files changed (3) hide show
  1. package/README.md +15 -13
  2. package/dist/index.js +2152 -506
  3. 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 isNotEmpty$1 = /*#__PURE__*/ramda.complement(ramda.isEmpty);
105
- var notEquals = /*#__PURE__*/ramda.curry(function (x, y) {
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
178
  const ROUTES_FILE_PATH = "app/javascript/src/common/routes.js";
111
- const WEBPACK_ALIAS_PATH = "config/webpack/alias.js";
112
- const BLACKLISTED_PACKAGES = ["moment", "bootstrap", "blueprint", "react-spinners", "react-table", "remixicon", "mjml", "react-select", "antd"];
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
- const addFunctionImport = (context, fixer, functions) => {
208
- const root = context.getAncestors()[0];
209
- const packageImport = root.body.find(node => matches(importPattern, node));
210
-
211
- if (packageImport) {
212
- const extraImports = functions.filter(func => !packageImport.specifiers.some(ramda.pathEq(["imported", "name"], func)));
213
- if (ramda.isEmpty(extraImports)) return undefined;
214
- return fixer.insertTextBefore(packageImport.specifiers[0], `${extraImports.join(", ")}, `);
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
- const packageName = importPattern.source.value;
218
- return fixer.insertTextBefore(root.body[0], `import { ${functions.join(", ")} } from "${packageName}";\n`);
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
- return {
222
- replaceNode: ({
223
- context,
224
- node,
225
- fix,
226
- functions
227
- }) => function* (fixer) {
228
- const imports = addFunctionImport(context, fixer, Array.isArray(functions) ? functions : [functions]);
229
- if (imports) yield imports;
230
- yield fixer.replaceText(node, fix);
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 arrayFuncParam = root => root.arguments[0].params[0];
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://github.com/bigbinary/eslint-plugin-neeto/blob/master/docs/src/rules/webpack-aliases-and-jsconfig-paths-should-be-in-sync.md for more details.`;
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,17 @@
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";
274
429
 
275
430
  const toCamelCase = text => {
276
431
  const capitalized = text.split(/[^0-9a-z]/i).map(part => `${part[0].toUpperCase()}${part.slice(1)}`).join("");
@@ -332,49 +487,6 @@
332
487
  })
333
488
  };
334
489
 
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
490
  const AWAIT_DECLARATION_PATTERN = {
379
491
  type: TYPES.VARIABLE_DECLARATOR,
380
492
  init: {
@@ -1081,183 +1193,1515 @@
1081
1193
  })
1082
1194
  };
1083
1195
 
1084
- const toConstantCase = text => text.replace(/([A-Z0-9][a-z])/g, "_$1").replace(/([a-z0-9])([A-Z0-9])/g, "$1_$2").toUpperCase().replace(/[^A-Z0-9_]/g, "").replace(/^_/g, "");
1196
+ const isWindows = typeof process === 'object' &&
1197
+ process &&
1198
+ process.platform === 'win32';
1199
+ var path$1 = isWindows ? { sep: '\\' } : { sep: '/' };
1085
1200
 
1086
- const checkCaseAndReport = ({
1087
- context,
1088
- name,
1089
- node
1090
- }) => {
1091
- if (CONSTANT_CASE_PATTERN.test(name)) return;
1092
- context.report({
1093
- node,
1094
- message: useConstantCaseFor(name),
1095
- suggest: [{
1096
- desc: `Replace ${getCode$1(context, node)} with ${toConstantCase(name)}`,
1097
- fix: fixer => fixer.replaceText(node, toConstantCase(name))
1098
- }]
1099
- });
1100
- };
1201
+ var balancedMatch = balanced$1;
1202
+ function balanced$1(a, b, str) {
1203
+ if (a instanceof RegExp) a = maybeMatch(a, str);
1204
+ if (b instanceof RegExp) b = maybeMatch(b, str);
1101
1205
 
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
- }
1206
+ var r = range(a, b, str);
1121
1207
 
1122
- if (local.name === newName) {
1123
- return fixer.replaceText(statement, local.name);
1124
- }
1208
+ return r && {
1209
+ start: r[0],
1210
+ end: r[1],
1211
+ pre: str.slice(0, r[0]),
1212
+ body: str.slice(r[0] + a.length, r[1]),
1213
+ post: str.slice(r[1] + b.length)
1214
+ };
1215
+ }
1125
1216
 
1126
- return fixer.replaceText(exported, newName);
1127
- }
1128
- }]
1129
- });
1130
- };
1217
+ function maybeMatch(reg, str) {
1218
+ var m = str.match(reg);
1219
+ return m ? m[0] : null;
1220
+ }
1131
1221
 
1132
- var useConstantCase = {
1133
- meta: {
1134
- type: "suggestion",
1135
- docs: {
1136
- description: "Enforces constants in constants.js file to be named using constant-case."
1137
- },
1138
- hasSuggestions: true
1139
- },
1140
- create: context => ({
1141
- ExportNamedDeclaration(node) {
1142
- var _node$declaration;
1143
-
1144
- if (!isConstantsFile(context)) return;
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
- }
1222
+ balanced$1.range = range;
1223
+ function range(a, b, str) {
1224
+ var begs, beg, left, right, result;
1225
+ var ai = str.indexOf(a);
1226
+ var bi = str.indexOf(b, ai + 1);
1227
+ var i = ai;
1160
1228
 
1161
- id.properties.forEach(statement => {
1162
- checkExportAndReport({
1163
- context,
1164
- exported: statement.value,
1165
- local: statement.key,
1166
- node,
1167
- statement
1168
- });
1169
- });
1170
- });
1229
+ if (ai >= 0 && bi > 0) {
1230
+ if(a===b) {
1231
+ return [ai, bi];
1232
+ }
1233
+ begs = [];
1234
+ left = str.length;
1235
+
1236
+ while (i >= 0 && !result) {
1237
+ if (i == ai) {
1238
+ begs.push(i);
1239
+ ai = str.indexOf(a, i + 1);
1240
+ } else if (begs.length == 1) {
1241
+ result = [ begs.pop(), bi ];
1171
1242
  } else {
1172
- node.specifiers.forEach(statement => {
1173
- const {
1174
- exported,
1175
- local
1176
- } = statement;
1177
- checkExportAndReport({
1178
- context,
1179
- exported,
1180
- local,
1181
- node,
1182
- statement
1183
- });
1184
- });
1243
+ beg = begs.pop();
1244
+ if (beg < left) {
1245
+ left = beg;
1246
+ right = bi;
1247
+ }
1248
+
1249
+ bi = str.indexOf(b, i + 1);
1185
1250
  }
1186
- }
1187
1251
 
1188
- })
1189
- };
1252
+ i = ai < bi && ai >= 0 ? ai : bi;
1253
+ }
1190
1254
 
1191
- const ASSIGNMENT_PATTERNS = [{
1192
- id: {
1193
- type: TYPES.OBJECT_PATTERN
1194
- }
1195
- }, {
1196
- id: {
1197
- type: TYPES.IDENTIFIER
1198
- }
1199
- }];
1200
- const IDENTIFIER_INITIALIZATION_PATTERN = {
1201
- type: TYPES.IDENTIFIER,
1202
- name: "globalProps"
1203
- };
1204
- const MEMBER_EXPRESSION_INITIALIZATION_PATTERN = {
1205
- type: TYPES.MEMBER_EXPRESSION,
1206
- object: {
1207
- type: TYPES.IDENTIFIER,
1208
- name: "globalProps"
1255
+ if (begs.length) {
1256
+ result = [ left, right ];
1257
+ }
1209
1258
  }
1210
- };
1211
- const GLOBALPROPS_REASSIGNMENT_PATTERN = {
1212
- type: TYPES.IDENTIFIER,
1213
- name: "globalProps"
1214
- };
1215
1259
 
1216
- const checkAssignment = (context, node) => {
1217
- if (matches(IDENTIFIER_INITIALIZATION_PATTERN, node)) {
1218
- context.report(node, GLOBALPROPS_NO_ASSIGNMENT_MESSAGE);
1219
- } else if (matches(MEMBER_EXPRESSION_INITIALIZATION_PATTERN, node)) {
1220
- context.report(node, NESTED_GLOBALPROPS_NO_ASSIGNMENT_MESSAGE);
1260
+ return result;
1261
+ }
1262
+
1263
+ var balanced = balancedMatch;
1264
+
1265
+ var braceExpansion = expandTop;
1266
+
1267
+ var escSlash = '\0SLASH'+Math.random()+'\0';
1268
+ var escOpen = '\0OPEN'+Math.random()+'\0';
1269
+ var escClose = '\0CLOSE'+Math.random()+'\0';
1270
+ var escComma = '\0COMMA'+Math.random()+'\0';
1271
+ var escPeriod = '\0PERIOD'+Math.random()+'\0';
1272
+
1273
+ function numeric(str) {
1274
+ return parseInt(str, 10) == str
1275
+ ? parseInt(str, 10)
1276
+ : str.charCodeAt(0);
1277
+ }
1278
+
1279
+ function escapeBraces(str) {
1280
+ return str.split('\\\\').join(escSlash)
1281
+ .split('\\{').join(escOpen)
1282
+ .split('\\}').join(escClose)
1283
+ .split('\\,').join(escComma)
1284
+ .split('\\.').join(escPeriod);
1285
+ }
1286
+
1287
+ function unescapeBraces(str) {
1288
+ return str.split(escSlash).join('\\')
1289
+ .split(escOpen).join('{')
1290
+ .split(escClose).join('}')
1291
+ .split(escComma).join(',')
1292
+ .split(escPeriod).join('.');
1293
+ }
1294
+
1295
+
1296
+ // Basically just str.split(","), but handling cases
1297
+ // where we have nested braced sections, which should be
1298
+ // treated as individual members, like {a,{b,c},d}
1299
+ function parseCommaParts(str) {
1300
+ if (!str)
1301
+ return [''];
1302
+
1303
+ var parts = [];
1304
+ var m = balanced('{', '}', str);
1305
+
1306
+ if (!m)
1307
+ return str.split(',');
1308
+
1309
+ var pre = m.pre;
1310
+ var body = m.body;
1311
+ var post = m.post;
1312
+ var p = pre.split(',');
1313
+
1314
+ p[p.length-1] += '{' + body + '}';
1315
+ var postParts = parseCommaParts(post);
1316
+ if (post.length) {
1317
+ p[p.length-1] += postParts.shift();
1318
+ p.push.apply(p, postParts);
1221
1319
  }
1222
- };
1223
1320
 
1224
- var noGlobalPropsDestructure = {
1225
- meta: {
1226
- type: "problem",
1227
- docs: {
1228
- description: "Disallows destructuring of globalProps."
1229
- }
1230
- },
1231
- create: context => ({
1232
- VariableDeclarator(node) {
1233
- if (!matchesAny(ASSIGNMENT_PATTERNS, node)) return;
1234
- checkAssignment(context, node.init);
1235
- },
1321
+ parts.push.apply(parts, p);
1236
1322
 
1237
- AssignmentExpression: node => checkAssignment(context, node.right)
1238
- })
1239
- };
1323
+ return parts;
1324
+ }
1240
1325
 
1241
- var noGlobalPropsReassignment = {
1242
- meta: {
1243
- type: "problem",
1244
- docs: {
1245
- description: "Disallows re-assignment of globalProps."
1246
- }
1247
- },
1248
- create: context => ({
1249
- AssignmentExpression(node) {
1250
- if (patternExistsDeep(GLOBALPROPS_REASSIGNMENT_PATTERN, node.left)) {
1251
- context.report(node, NO_GLOBALPROPS_REASSIGNMENT_MESSAGE);
1252
- }
1253
- }
1326
+ function expandTop(str) {
1327
+ if (!str)
1328
+ return [];
1329
+
1330
+ // I don't know why Bash 4.3 does this, but it does.
1331
+ // Anything starting with {} will have the first two bytes preserved
1332
+ // but *only* at the top level, so {},a}b will not expand to anything,
1333
+ // but a{},b}c will be expanded to [a}c,abc].
1334
+ // One could argue that this is a bug in Bash, but since the goal of
1335
+ // this module is to match Bash's rules, we escape a leading {}
1336
+ if (str.substr(0, 2) === '{}') {
1337
+ str = '\\{\\}' + str.substr(2);
1338
+ }
1254
1339
 
1255
- })
1256
- };
1340
+ return expand$1(escapeBraces(str), true).map(unescapeBraces);
1341
+ }
1257
1342
 
1258
- const reportSuggestion = ({
1259
- context,
1260
- node,
1343
+ function embrace(str) {
1344
+ return '{' + str + '}';
1345
+ }
1346
+ function isPadded(el) {
1347
+ return /^-?0\d/.test(el);
1348
+ }
1349
+
1350
+ function lte(i, y) {
1351
+ return i <= y;
1352
+ }
1353
+ function gte(i, y) {
1354
+ return i >= y;
1355
+ }
1356
+
1357
+ function expand$1(str, isTop) {
1358
+ var expansions = [];
1359
+
1360
+ var m = balanced('{', '}', str);
1361
+ if (!m) return [str];
1362
+
1363
+ // no need to expand pre, since it is guaranteed to be free of brace-sets
1364
+ var pre = m.pre;
1365
+ var post = m.post.length
1366
+ ? expand$1(m.post, false)
1367
+ : [''];
1368
+
1369
+ if (/\$$/.test(m.pre)) {
1370
+ for (var k = 0; k < post.length; k++) {
1371
+ var expansion = pre+ '{' + m.body + '}' + post[k];
1372
+ expansions.push(expansion);
1373
+ }
1374
+ } else {
1375
+ var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
1376
+ var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
1377
+ var isSequence = isNumericSequence || isAlphaSequence;
1378
+ var isOptions = m.body.indexOf(',') >= 0;
1379
+ if (!isSequence && !isOptions) {
1380
+ // {a},b}
1381
+ if (m.post.match(/,.*\}/)) {
1382
+ str = m.pre + '{' + m.body + escClose + m.post;
1383
+ return expand$1(str);
1384
+ }
1385
+ return [str];
1386
+ }
1387
+
1388
+ var n;
1389
+ if (isSequence) {
1390
+ n = m.body.split(/\.\./);
1391
+ } else {
1392
+ n = parseCommaParts(m.body);
1393
+ if (n.length === 1) {
1394
+ // x{{a,b}}y ==> x{a}y x{b}y
1395
+ n = expand$1(n[0], false).map(embrace);
1396
+ if (n.length === 1) {
1397
+ return post.map(function(p) {
1398
+ return m.pre + n[0] + p;
1399
+ });
1400
+ }
1401
+ }
1402
+ }
1403
+
1404
+ // at this point, n is the parts, and we know it's not a comma set
1405
+ // with a single entry.
1406
+ var N;
1407
+
1408
+ if (isSequence) {
1409
+ var x = numeric(n[0]);
1410
+ var y = numeric(n[1]);
1411
+ var width = Math.max(n[0].length, n[1].length);
1412
+ var incr = n.length == 3
1413
+ ? Math.abs(numeric(n[2]))
1414
+ : 1;
1415
+ var test = lte;
1416
+ var reverse = y < x;
1417
+ if (reverse) {
1418
+ incr *= -1;
1419
+ test = gte;
1420
+ }
1421
+ var pad = n.some(isPadded);
1422
+
1423
+ N = [];
1424
+
1425
+ for (var i = x; test(i, y); i += incr) {
1426
+ var c;
1427
+ if (isAlphaSequence) {
1428
+ c = String.fromCharCode(i);
1429
+ if (c === '\\')
1430
+ c = '';
1431
+ } else {
1432
+ c = String(i);
1433
+ if (pad) {
1434
+ var need = width - c.length;
1435
+ if (need > 0) {
1436
+ var z = new Array(need + 1).join('0');
1437
+ if (i < 0)
1438
+ c = '-' + z + c.slice(1);
1439
+ else
1440
+ c = z + c;
1441
+ }
1442
+ }
1443
+ }
1444
+ N.push(c);
1445
+ }
1446
+ } else {
1447
+ N = [];
1448
+
1449
+ for (var j = 0; j < n.length; j++) {
1450
+ N.push.apply(N, expand$1(n[j], false));
1451
+ }
1452
+ }
1453
+
1454
+ for (var j = 0; j < N.length; j++) {
1455
+ for (var k = 0; k < post.length; k++) {
1456
+ var expansion = pre + N[j] + post[k];
1457
+ if (!isTop || isSequence || expansion)
1458
+ expansions.push(expansion);
1459
+ }
1460
+ }
1461
+ }
1462
+
1463
+ return expansions;
1464
+ }
1465
+
1466
+ const minimatch = minimatch_1 = (p, pattern, options = {}) => {
1467
+ assertValidPattern(pattern);
1468
+
1469
+ // shortcut: comments match nothing.
1470
+ if (!options.nocomment && pattern.charAt(0) === '#') {
1471
+ return false
1472
+ }
1473
+
1474
+ return new Minimatch(pattern, options).match(p)
1475
+ };
1476
+
1477
+ var minimatch_1 = minimatch;
1478
+
1479
+ const path = path$1;
1480
+ minimatch.sep = path.sep;
1481
+
1482
+ const GLOBSTAR = Symbol('globstar **');
1483
+ minimatch.GLOBSTAR = GLOBSTAR;
1484
+ const expand = braceExpansion;
1485
+
1486
+ const plTypes = {
1487
+ '!': { open: '(?:(?!(?:', close: '))[^/]*?)'},
1488
+ '?': { open: '(?:', close: ')?' },
1489
+ '+': { open: '(?:', close: ')+' },
1490
+ '*': { open: '(?:', close: ')*' },
1491
+ '@': { open: '(?:', close: ')' }
1492
+ };
1493
+
1494
+ // any single thing other than /
1495
+ // don't need to escape / when using new RegExp()
1496
+ const qmark = '[^/]';
1497
+
1498
+ // * => any number of characters
1499
+ const star = qmark + '*?';
1500
+
1501
+ // ** when dots are allowed. Anything goes, except .. and .
1502
+ // not (^ or / followed by one or two dots followed by $ or /),
1503
+ // followed by anything, any number of times.
1504
+ const twoStarDot = '(?:(?!(?:\\\/|^)(?:\\.{1,2})($|\\\/)).)*?';
1505
+
1506
+ // not a ^ or / followed by a dot,
1507
+ // followed by anything, any number of times.
1508
+ const twoStarNoDot = '(?:(?!(?:\\\/|^)\\.).)*?';
1509
+
1510
+ // "abc" -> { a:true, b:true, c:true }
1511
+ const charSet = s => s.split('').reduce((set, c) => {
1512
+ set[c] = true;
1513
+ return set
1514
+ }, {});
1515
+
1516
+ // characters that need to be escaped in RegExp.
1517
+ const reSpecials = charSet('().*{}+?[]^$\\!');
1518
+
1519
+ // characters that indicate we have to add the pattern start
1520
+ const addPatternStartSet = charSet('[.(');
1521
+
1522
+ // normalizes slashes.
1523
+ const slashSplit = /\/+/;
1524
+
1525
+ minimatch.filter = (pattern, options = {}) =>
1526
+ (p, i, list) => minimatch(p, pattern, options);
1527
+
1528
+ const ext = (a, b = {}) => {
1529
+ const t = {};
1530
+ Object.keys(a).forEach(k => t[k] = a[k]);
1531
+ Object.keys(b).forEach(k => t[k] = b[k]);
1532
+ return t
1533
+ };
1534
+
1535
+ minimatch.defaults = def => {
1536
+ if (!def || typeof def !== 'object' || !Object.keys(def).length) {
1537
+ return minimatch
1538
+ }
1539
+
1540
+ const orig = minimatch;
1541
+
1542
+ const m = (p, pattern, options) => orig(p, pattern, ext(def, options));
1543
+ m.Minimatch = class Minimatch extends orig.Minimatch {
1544
+ constructor (pattern, options) {
1545
+ super(pattern, ext(def, options));
1546
+ }
1547
+ };
1548
+ m.Minimatch.defaults = options => orig.defaults(ext(def, options)).Minimatch;
1549
+ m.filter = (pattern, options) => orig.filter(pattern, ext(def, options));
1550
+ m.defaults = options => orig.defaults(ext(def, options));
1551
+ m.makeRe = (pattern, options) => orig.makeRe(pattern, ext(def, options));
1552
+ m.braceExpand = (pattern, options) => orig.braceExpand(pattern, ext(def, options));
1553
+ m.match = (list, pattern, options) => orig.match(list, pattern, ext(def, options));
1554
+
1555
+ return m
1556
+ };
1557
+
1558
+
1559
+
1560
+
1561
+
1562
+ // Brace expansion:
1563
+ // a{b,c}d -> abd acd
1564
+ // a{b,}c -> abc ac
1565
+ // a{0..3}d -> a0d a1d a2d a3d
1566
+ // a{b,c{d,e}f}g -> abg acdfg acefg
1567
+ // a{b,c}d{e,f}g -> abdeg acdeg abdeg abdfg
1568
+ //
1569
+ // Invalid sets are not expanded.
1570
+ // a{2..}b -> a{2..}b
1571
+ // a{b}c -> a{b}c
1572
+ minimatch.braceExpand = (pattern, options) => braceExpand(pattern, options);
1573
+
1574
+ const braceExpand = (pattern, options = {}) => {
1575
+ assertValidPattern(pattern);
1576
+
1577
+ // Thanks to Yeting Li <https://github.com/yetingli> for
1578
+ // improving this regexp to avoid a ReDOS vulnerability.
1579
+ if (options.nobrace || !/\{(?:(?!\{).)*\}/.test(pattern)) {
1580
+ // shortcut. no need to expand.
1581
+ return [pattern]
1582
+ }
1583
+
1584
+ return expand(pattern)
1585
+ };
1586
+
1587
+ const MAX_PATTERN_LENGTH = 1024 * 64;
1588
+ const assertValidPattern = pattern => {
1589
+ if (typeof pattern !== 'string') {
1590
+ throw new TypeError('invalid pattern')
1591
+ }
1592
+
1593
+ if (pattern.length > MAX_PATTERN_LENGTH) {
1594
+ throw new TypeError('pattern is too long')
1595
+ }
1596
+ };
1597
+
1598
+ // parse a component of the expanded set.
1599
+ // At this point, no pattern may contain "/" in it
1600
+ // so we're going to return a 2d array, where each entry is the full
1601
+ // pattern, split on '/', and then turned into a regular expression.
1602
+ // A regexp is made at the end which joins each array with an
1603
+ // escaped /, and another full one which joins each regexp with |.
1604
+ //
1605
+ // Following the lead of Bash 4.1, note that "**" only has special meaning
1606
+ // when it is the *only* thing in a path portion. Otherwise, any series
1607
+ // of * is equivalent to a single *. Globstar behavior is enabled by
1608
+ // default, and can be disabled by setting options.noglobstar.
1609
+ const SUBPARSE = Symbol('subparse');
1610
+
1611
+ minimatch.makeRe = (pattern, options) =>
1612
+ new Minimatch(pattern, options || {}).makeRe();
1613
+
1614
+ minimatch.match = (list, pattern, options = {}) => {
1615
+ const mm = new Minimatch(pattern, options);
1616
+ list = list.filter(f => mm.match(f));
1617
+ if (mm.options.nonull && !list.length) {
1618
+ list.push(pattern);
1619
+ }
1620
+ return list
1621
+ };
1622
+
1623
+ // replace stuff like \* with *
1624
+ const globUnescape = s => s.replace(/\\(.)/g, '$1');
1625
+ const regExpEscape = s => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
1626
+
1627
+ class Minimatch {
1628
+ constructor (pattern, options) {
1629
+ assertValidPattern(pattern);
1630
+
1631
+ if (!options) options = {};
1632
+
1633
+ this.options = options;
1634
+ this.set = [];
1635
+ this.pattern = pattern;
1636
+ this.windowsPathsNoEscape = !!options.windowsPathsNoEscape ||
1637
+ options.allowWindowsEscape === false;
1638
+ if (this.windowsPathsNoEscape) {
1639
+ this.pattern = this.pattern.replace(/\\/g, '/');
1640
+ }
1641
+ this.regexp = null;
1642
+ this.negate = false;
1643
+ this.comment = false;
1644
+ this.empty = false;
1645
+ this.partial = !!options.partial;
1646
+
1647
+ // make the set of regexps etc.
1648
+ this.make();
1649
+ }
1650
+
1651
+ debug () {}
1652
+
1653
+ make () {
1654
+ const pattern = this.pattern;
1655
+ const options = this.options;
1656
+
1657
+ // empty patterns and comments match nothing.
1658
+ if (!options.nocomment && pattern.charAt(0) === '#') {
1659
+ this.comment = true;
1660
+ return
1661
+ }
1662
+ if (!pattern) {
1663
+ this.empty = true;
1664
+ return
1665
+ }
1666
+
1667
+ // step 1: figure out negation, etc.
1668
+ this.parseNegate();
1669
+
1670
+ // step 2: expand braces
1671
+ let set = this.globSet = this.braceExpand();
1672
+
1673
+ if (options.debug) this.debug = (...args) => console.error(...args);
1674
+
1675
+ this.debug(this.pattern, set);
1676
+
1677
+ // step 3: now we have a set, so turn each one into a series of path-portion
1678
+ // matching patterns.
1679
+ // These will be regexps, except in the case of "**", which is
1680
+ // set to the GLOBSTAR object for globstar behavior,
1681
+ // and will not contain any / characters
1682
+ set = this.globParts = set.map(s => s.split(slashSplit));
1683
+
1684
+ this.debug(this.pattern, set);
1685
+
1686
+ // glob --> regexps
1687
+ set = set.map((s, si, set) => s.map(this.parse, this));
1688
+
1689
+ this.debug(this.pattern, set);
1690
+
1691
+ // filter out everything that didn't compile properly.
1692
+ set = set.filter(s => s.indexOf(false) === -1);
1693
+
1694
+ this.debug(this.pattern, set);
1695
+
1696
+ this.set = set;
1697
+ }
1698
+
1699
+ parseNegate () {
1700
+ if (this.options.nonegate) return
1701
+
1702
+ const pattern = this.pattern;
1703
+ let negate = false;
1704
+ let negateOffset = 0;
1705
+
1706
+ for (let i = 0; i < pattern.length && pattern.charAt(i) === '!'; i++) {
1707
+ negate = !negate;
1708
+ negateOffset++;
1709
+ }
1710
+
1711
+ if (negateOffset) this.pattern = pattern.substr(negateOffset);
1712
+ this.negate = negate;
1713
+ }
1714
+
1715
+ // set partial to true to test if, for example,
1716
+ // "/a/b" matches the start of "/*/b/*/d"
1717
+ // Partial means, if you run out of file before you run
1718
+ // out of pattern, then that's fine, as long as all
1719
+ // the parts match.
1720
+ matchOne (file, pattern, partial) {
1721
+ var options = this.options;
1722
+
1723
+ this.debug('matchOne',
1724
+ { 'this': this, file: file, pattern: pattern });
1725
+
1726
+ this.debug('matchOne', file.length, pattern.length);
1727
+
1728
+ for (var fi = 0,
1729
+ pi = 0,
1730
+ fl = file.length,
1731
+ pl = pattern.length
1732
+ ; (fi < fl) && (pi < pl)
1733
+ ; fi++, pi++) {
1734
+ this.debug('matchOne loop');
1735
+ var p = pattern[pi];
1736
+ var f = file[fi];
1737
+
1738
+ this.debug(pattern, p, f);
1739
+
1740
+ // should be impossible.
1741
+ // some invalid regexp stuff in the set.
1742
+ /* istanbul ignore if */
1743
+ if (p === false) return false
1744
+
1745
+ if (p === GLOBSTAR) {
1746
+ this.debug('GLOBSTAR', [pattern, p, f]);
1747
+
1748
+ // "**"
1749
+ // a/**/b/**/c would match the following:
1750
+ // a/b/x/y/z/c
1751
+ // a/x/y/z/b/c
1752
+ // a/b/x/b/x/c
1753
+ // a/b/c
1754
+ // To do this, take the rest of the pattern after
1755
+ // the **, and see if it would match the file remainder.
1756
+ // If so, return success.
1757
+ // If not, the ** "swallows" a segment, and try again.
1758
+ // This is recursively awful.
1759
+ //
1760
+ // a/**/b/**/c matching a/b/x/y/z/c
1761
+ // - a matches a
1762
+ // - doublestar
1763
+ // - matchOne(b/x/y/z/c, b/**/c)
1764
+ // - b matches b
1765
+ // - doublestar
1766
+ // - matchOne(x/y/z/c, c) -> no
1767
+ // - matchOne(y/z/c, c) -> no
1768
+ // - matchOne(z/c, c) -> no
1769
+ // - matchOne(c, c) yes, hit
1770
+ var fr = fi;
1771
+ var pr = pi + 1;
1772
+ if (pr === pl) {
1773
+ this.debug('** at the end');
1774
+ // a ** at the end will just swallow the rest.
1775
+ // We have found a match.
1776
+ // however, it will not swallow /.x, unless
1777
+ // options.dot is set.
1778
+ // . and .. are *never* matched by **, for explosively
1779
+ // exponential reasons.
1780
+ for (; fi < fl; fi++) {
1781
+ if (file[fi] === '.' || file[fi] === '..' ||
1782
+ (!options.dot && file[fi].charAt(0) === '.')) return false
1783
+ }
1784
+ return true
1785
+ }
1786
+
1787
+ // ok, let's see if we can swallow whatever we can.
1788
+ while (fr < fl) {
1789
+ var swallowee = file[fr];
1790
+
1791
+ this.debug('\nglobstar while', file, fr, pattern, pr, swallowee);
1792
+
1793
+ // XXX remove this slice. Just pass the start index.
1794
+ if (this.matchOne(file.slice(fr), pattern.slice(pr), partial)) {
1795
+ this.debug('globstar found match!', fr, fl, swallowee);
1796
+ // found a match.
1797
+ return true
1798
+ } else {
1799
+ // can't swallow "." or ".." ever.
1800
+ // can only swallow ".foo" when explicitly asked.
1801
+ if (swallowee === '.' || swallowee === '..' ||
1802
+ (!options.dot && swallowee.charAt(0) === '.')) {
1803
+ this.debug('dot detected!', file, fr, pattern, pr);
1804
+ break
1805
+ }
1806
+
1807
+ // ** swallows a segment, and continue.
1808
+ this.debug('globstar swallow a segment, and continue');
1809
+ fr++;
1810
+ }
1811
+ }
1812
+
1813
+ // no match was found.
1814
+ // However, in partial mode, we can't say this is necessarily over.
1815
+ // If there's more *pattern* left, then
1816
+ /* istanbul ignore if */
1817
+ if (partial) {
1818
+ // ran out of file
1819
+ this.debug('\n>>> no match, partial?', file, fr, pattern, pr);
1820
+ if (fr === fl) return true
1821
+ }
1822
+ return false
1823
+ }
1824
+
1825
+ // something other than **
1826
+ // non-magic patterns just have to match exactly
1827
+ // patterns with magic have been turned into regexps.
1828
+ var hit;
1829
+ if (typeof p === 'string') {
1830
+ hit = f === p;
1831
+ this.debug('string match', p, f, hit);
1832
+ } else {
1833
+ hit = f.match(p);
1834
+ this.debug('pattern match', p, f, hit);
1835
+ }
1836
+
1837
+ if (!hit) return false
1838
+ }
1839
+
1840
+ // Note: ending in / means that we'll get a final ""
1841
+ // at the end of the pattern. This can only match a
1842
+ // corresponding "" at the end of the file.
1843
+ // If the file ends in /, then it can only match a
1844
+ // a pattern that ends in /, unless the pattern just
1845
+ // doesn't have any more for it. But, a/b/ should *not*
1846
+ // match "a/b/*", even though "" matches against the
1847
+ // [^/]*? pattern, except in partial mode, where it might
1848
+ // simply not be reached yet.
1849
+ // However, a/b/ should still satisfy a/*
1850
+
1851
+ // now either we fell off the end of the pattern, or we're done.
1852
+ if (fi === fl && pi === pl) {
1853
+ // ran out of pattern and filename at the same time.
1854
+ // an exact hit!
1855
+ return true
1856
+ } else if (fi === fl) {
1857
+ // ran out of file, but still had pattern left.
1858
+ // this is ok if we're doing the match as part of
1859
+ // a glob fs traversal.
1860
+ return partial
1861
+ } else /* istanbul ignore else */ if (pi === pl) {
1862
+ // ran out of pattern, still have file left.
1863
+ // this is only acceptable if we're on the very last
1864
+ // empty segment of a file with a trailing slash.
1865
+ // a/* should match a/b/
1866
+ return (fi === fl - 1) && (file[fi] === '')
1867
+ }
1868
+
1869
+ // should be unreachable.
1870
+ /* istanbul ignore next */
1871
+ throw new Error('wtf?')
1872
+ }
1873
+
1874
+ braceExpand () {
1875
+ return braceExpand(this.pattern, this.options)
1876
+ }
1877
+
1878
+ parse (pattern, isSub) {
1879
+ assertValidPattern(pattern);
1880
+
1881
+ const options = this.options;
1882
+
1883
+ // shortcuts
1884
+ if (pattern === '**') {
1885
+ if (!options.noglobstar)
1886
+ return GLOBSTAR
1887
+ else
1888
+ pattern = '*';
1889
+ }
1890
+ if (pattern === '') return ''
1891
+
1892
+ let re = '';
1893
+ let hasMagic = !!options.nocase;
1894
+ let escaping = false;
1895
+ // ? => one single character
1896
+ const patternListStack = [];
1897
+ const negativeLists = [];
1898
+ let stateChar;
1899
+ let inClass = false;
1900
+ let reClassStart = -1;
1901
+ let classStart = -1;
1902
+ let cs;
1903
+ let pl;
1904
+ let sp;
1905
+ // . and .. never match anything that doesn't start with .,
1906
+ // even when options.dot is set.
1907
+ const patternStart = pattern.charAt(0) === '.' ? '' // anything
1908
+ // not (start or / followed by . or .. followed by / or end)
1909
+ : options.dot ? '(?!(?:^|\\\/)\\.{1,2}(?:$|\\\/))'
1910
+ : '(?!\\.)';
1911
+
1912
+ const clearStateChar = () => {
1913
+ if (stateChar) {
1914
+ // we had some state-tracking character
1915
+ // that wasn't consumed by this pass.
1916
+ switch (stateChar) {
1917
+ case '*':
1918
+ re += star;
1919
+ hasMagic = true;
1920
+ break
1921
+ case '?':
1922
+ re += qmark;
1923
+ hasMagic = true;
1924
+ break
1925
+ default:
1926
+ re += '\\' + stateChar;
1927
+ break
1928
+ }
1929
+ this.debug('clearStateChar %j %j', stateChar, re);
1930
+ stateChar = false;
1931
+ }
1932
+ };
1933
+
1934
+ for (let i = 0, c; (i < pattern.length) && (c = pattern.charAt(i)); i++) {
1935
+ this.debug('%s\t%s %s %j', pattern, i, re, c);
1936
+
1937
+ // skip over any that are escaped.
1938
+ if (escaping) {
1939
+ /* istanbul ignore next - completely not allowed, even escaped. */
1940
+ if (c === '/') {
1941
+ return false
1942
+ }
1943
+
1944
+ if (reSpecials[c]) {
1945
+ re += '\\';
1946
+ }
1947
+ re += c;
1948
+ escaping = false;
1949
+ continue
1950
+ }
1951
+
1952
+ switch (c) {
1953
+ /* istanbul ignore next */
1954
+ case '/': {
1955
+ // Should already be path-split by now.
1956
+ return false
1957
+ }
1958
+
1959
+ case '\\':
1960
+ clearStateChar();
1961
+ escaping = true;
1962
+ continue
1963
+
1964
+ // the various stateChar values
1965
+ // for the "extglob" stuff.
1966
+ case '?':
1967
+ case '*':
1968
+ case '+':
1969
+ case '@':
1970
+ case '!':
1971
+ this.debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c);
1972
+
1973
+ // all of those are literals inside a class, except that
1974
+ // the glob [!a] means [^a] in regexp
1975
+ if (inClass) {
1976
+ this.debug(' in class');
1977
+ if (c === '!' && i === classStart + 1) c = '^';
1978
+ re += c;
1979
+ continue
1980
+ }
1981
+
1982
+ // if we already have a stateChar, then it means
1983
+ // that there was something like ** or +? in there.
1984
+ // Handle the stateChar, then proceed with this one.
1985
+ this.debug('call clearStateChar %j', stateChar);
1986
+ clearStateChar();
1987
+ stateChar = c;
1988
+ // if extglob is disabled, then +(asdf|foo) isn't a thing.
1989
+ // just clear the statechar *now*, rather than even diving into
1990
+ // the patternList stuff.
1991
+ if (options.noext) clearStateChar();
1992
+ continue
1993
+
1994
+ case '(':
1995
+ if (inClass) {
1996
+ re += '(';
1997
+ continue
1998
+ }
1999
+
2000
+ if (!stateChar) {
2001
+ re += '\\(';
2002
+ continue
2003
+ }
2004
+
2005
+ patternListStack.push({
2006
+ type: stateChar,
2007
+ start: i - 1,
2008
+ reStart: re.length,
2009
+ open: plTypes[stateChar].open,
2010
+ close: plTypes[stateChar].close
2011
+ });
2012
+ // negation is (?:(?!js)[^/]*)
2013
+ re += stateChar === '!' ? '(?:(?!(?:' : '(?:';
2014
+ this.debug('plType %j %j', stateChar, re);
2015
+ stateChar = false;
2016
+ continue
2017
+
2018
+ case ')':
2019
+ if (inClass || !patternListStack.length) {
2020
+ re += '\\)';
2021
+ continue
2022
+ }
2023
+
2024
+ clearStateChar();
2025
+ hasMagic = true;
2026
+ pl = patternListStack.pop();
2027
+ // negation is (?:(?!js)[^/]*)
2028
+ // The others are (?:<pattern>)<type>
2029
+ re += pl.close;
2030
+ if (pl.type === '!') {
2031
+ negativeLists.push(pl);
2032
+ }
2033
+ pl.reEnd = re.length;
2034
+ continue
2035
+
2036
+ case '|':
2037
+ if (inClass || !patternListStack.length) {
2038
+ re += '\\|';
2039
+ continue
2040
+ }
2041
+
2042
+ clearStateChar();
2043
+ re += '|';
2044
+ continue
2045
+
2046
+ // these are mostly the same in regexp and glob
2047
+ case '[':
2048
+ // swallow any state-tracking char before the [
2049
+ clearStateChar();
2050
+
2051
+ if (inClass) {
2052
+ re += '\\' + c;
2053
+ continue
2054
+ }
2055
+
2056
+ inClass = true;
2057
+ classStart = i;
2058
+ reClassStart = re.length;
2059
+ re += c;
2060
+ continue
2061
+
2062
+ case ']':
2063
+ // a right bracket shall lose its special
2064
+ // meaning and represent itself in
2065
+ // a bracket expression if it occurs
2066
+ // first in the list. -- POSIX.2 2.8.3.2
2067
+ if (i === classStart + 1 || !inClass) {
2068
+ re += '\\' + c;
2069
+ continue
2070
+ }
2071
+
2072
+ // handle the case where we left a class open.
2073
+ // "[z-a]" is valid, equivalent to "\[z-a\]"
2074
+ // split where the last [ was, make sure we don't have
2075
+ // an invalid re. if so, re-walk the contents of the
2076
+ // would-be class to re-translate any characters that
2077
+ // were passed through as-is
2078
+ // TODO: It would probably be faster to determine this
2079
+ // without a try/catch and a new RegExp, but it's tricky
2080
+ // to do safely. For now, this is safe and works.
2081
+ cs = pattern.substring(classStart + 1, i);
2082
+ try {
2083
+ RegExp('[' + cs + ']');
2084
+ } catch (er) {
2085
+ // not a valid class!
2086
+ sp = this.parse(cs, SUBPARSE);
2087
+ re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]';
2088
+ hasMagic = hasMagic || sp[1];
2089
+ inClass = false;
2090
+ continue
2091
+ }
2092
+
2093
+ // finish up the class.
2094
+ hasMagic = true;
2095
+ inClass = false;
2096
+ re += c;
2097
+ continue
2098
+
2099
+ default:
2100
+ // swallow any state char that wasn't consumed
2101
+ clearStateChar();
2102
+
2103
+ if (reSpecials[c] && !(c === '^' && inClass)) {
2104
+ re += '\\';
2105
+ }
2106
+
2107
+ re += c;
2108
+ break
2109
+
2110
+ } // switch
2111
+ } // for
2112
+
2113
+ // handle the case where we left a class open.
2114
+ // "[abc" is valid, equivalent to "\[abc"
2115
+ if (inClass) {
2116
+ // split where the last [ was, and escape it
2117
+ // this is a huge pita. We now have to re-walk
2118
+ // the contents of the would-be class to re-translate
2119
+ // any characters that were passed through as-is
2120
+ cs = pattern.substr(classStart + 1);
2121
+ sp = this.parse(cs, SUBPARSE);
2122
+ re = re.substr(0, reClassStart) + '\\[' + sp[0];
2123
+ hasMagic = hasMagic || sp[1];
2124
+ }
2125
+
2126
+ // handle the case where we had a +( thing at the *end*
2127
+ // of the pattern.
2128
+ // each pattern list stack adds 3 chars, and we need to go through
2129
+ // and escape any | chars that were passed through as-is for the regexp.
2130
+ // Go through and escape them, taking care not to double-escape any
2131
+ // | chars that were already escaped.
2132
+ for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
2133
+ let tail;
2134
+ tail = re.slice(pl.reStart + pl.open.length);
2135
+ this.debug('setting tail', re, pl);
2136
+ // maybe some even number of \, then maybe 1 \, followed by a |
2137
+ tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, (_, $1, $2) => {
2138
+ /* istanbul ignore else - should already be done */
2139
+ if (!$2) {
2140
+ // the | isn't already escaped, so escape it.
2141
+ $2 = '\\';
2142
+ }
2143
+
2144
+ // need to escape all those slashes *again*, without escaping the
2145
+ // one that we need for escaping the | character. As it works out,
2146
+ // escaping an even number of slashes can be done by simply repeating
2147
+ // it exactly after itself. That's why this trick works.
2148
+ //
2149
+ // I am sorry that you have to see this.
2150
+ return $1 + $1 + $2 + '|'
2151
+ });
2152
+
2153
+ this.debug('tail=%j\n %s', tail, tail, pl, re);
2154
+ const t = pl.type === '*' ? star
2155
+ : pl.type === '?' ? qmark
2156
+ : '\\' + pl.type;
2157
+
2158
+ hasMagic = true;
2159
+ re = re.slice(0, pl.reStart) + t + '\\(' + tail;
2160
+ }
2161
+
2162
+ // handle trailing things that only matter at the very end.
2163
+ clearStateChar();
2164
+ if (escaping) {
2165
+ // trailing \\
2166
+ re += '\\\\';
2167
+ }
2168
+
2169
+ // only need to apply the nodot start if the re starts with
2170
+ // something that could conceivably capture a dot
2171
+ const addPatternStart = addPatternStartSet[re.charAt(0)];
2172
+
2173
+ // Hack to work around lack of negative lookbehind in JS
2174
+ // A pattern like: *.!(x).!(y|z) needs to ensure that a name
2175
+ // like 'a.xyz.yz' doesn't match. So, the first negative
2176
+ // lookahead, has to look ALL the way ahead, to the end of
2177
+ // the pattern.
2178
+ for (let n = negativeLists.length - 1; n > -1; n--) {
2179
+ const nl = negativeLists[n];
2180
+
2181
+ const nlBefore = re.slice(0, nl.reStart);
2182
+ const nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
2183
+ let nlAfter = re.slice(nl.reEnd);
2184
+ const nlLast = re.slice(nl.reEnd - 8, nl.reEnd) + nlAfter;
2185
+
2186
+ // Handle nested stuff like *(*.js|!(*.json)), where open parens
2187
+ // mean that we should *not* include the ) in the bit that is considered
2188
+ // "after" the negated section.
2189
+ const openParensBefore = nlBefore.split('(').length - 1;
2190
+ let cleanAfter = nlAfter;
2191
+ for (let i = 0; i < openParensBefore; i++) {
2192
+ cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
2193
+ }
2194
+ nlAfter = cleanAfter;
2195
+
2196
+ const dollar = nlAfter === '' && isSub !== SUBPARSE ? '$' : '';
2197
+ re = nlBefore + nlFirst + nlAfter + dollar + nlLast;
2198
+ }
2199
+
2200
+ // if the re is not "" at this point, then we need to make sure
2201
+ // it doesn't match against an empty path part.
2202
+ // Otherwise a/* will match a/, which it should not.
2203
+ if (re !== '' && hasMagic) {
2204
+ re = '(?=.)' + re;
2205
+ }
2206
+
2207
+ if (addPatternStart) {
2208
+ re = patternStart + re;
2209
+ }
2210
+
2211
+ // parsing just a piece of a larger pattern.
2212
+ if (isSub === SUBPARSE) {
2213
+ return [re, hasMagic]
2214
+ }
2215
+
2216
+ // skip the regexp for non-magical patterns
2217
+ // unescape anything in it, though, so that it'll be
2218
+ // an exact match against a file etc.
2219
+ if (!hasMagic) {
2220
+ return globUnescape(pattern)
2221
+ }
2222
+
2223
+ const flags = options.nocase ? 'i' : '';
2224
+ try {
2225
+ return Object.assign(new RegExp('^' + re + '$', flags), {
2226
+ _glob: pattern,
2227
+ _src: re,
2228
+ })
2229
+ } catch (er) /* istanbul ignore next - should be impossible */ {
2230
+ // If it was an invalid regular expression, then it can't match
2231
+ // anything. This trick looks for a character after the end of
2232
+ // the string, which is of course impossible, except in multi-line
2233
+ // mode, but it's not a /m regex.
2234
+ return new RegExp('$.')
2235
+ }
2236
+ }
2237
+
2238
+ makeRe () {
2239
+ if (this.regexp || this.regexp === false) return this.regexp
2240
+
2241
+ // at this point, this.set is a 2d array of partial
2242
+ // pattern strings, or "**".
2243
+ //
2244
+ // It's better to use .match(). This function shouldn't
2245
+ // be used, really, but it's pretty convenient sometimes,
2246
+ // when you just want to work with a regex.
2247
+ const set = this.set;
2248
+
2249
+ if (!set.length) {
2250
+ this.regexp = false;
2251
+ return this.regexp
2252
+ }
2253
+ const options = this.options;
2254
+
2255
+ const twoStar = options.noglobstar ? star
2256
+ : options.dot ? twoStarDot
2257
+ : twoStarNoDot;
2258
+ const flags = options.nocase ? 'i' : '';
2259
+
2260
+ // coalesce globstars and regexpify non-globstar patterns
2261
+ // if it's the only item, then we just do one twoStar
2262
+ // if it's the first, and there are more, prepend (\/|twoStar\/)? to next
2263
+ // if it's the last, append (\/twoStar|) to previous
2264
+ // if it's in the middle, append (\/|\/twoStar\/) to previous
2265
+ // then filter out GLOBSTAR symbols
2266
+ let re = set.map(pattern => {
2267
+ pattern = pattern.map(p =>
2268
+ typeof p === 'string' ? regExpEscape(p)
2269
+ : p === GLOBSTAR ? GLOBSTAR
2270
+ : p._src
2271
+ ).reduce((set, p) => {
2272
+ if (!(set[set.length - 1] === GLOBSTAR && p === GLOBSTAR)) {
2273
+ set.push(p);
2274
+ }
2275
+ return set
2276
+ }, []);
2277
+ pattern.forEach((p, i) => {
2278
+ if (p !== GLOBSTAR || pattern[i-1] === GLOBSTAR) {
2279
+ return
2280
+ }
2281
+ if (i === 0) {
2282
+ if (pattern.length > 1) {
2283
+ pattern[i+1] = '(?:\\\/|' + twoStar + '\\\/)?' + pattern[i+1];
2284
+ } else {
2285
+ pattern[i] = twoStar;
2286
+ }
2287
+ } else if (i === pattern.length - 1) {
2288
+ pattern[i-1] += '(?:\\\/|' + twoStar + ')?';
2289
+ } else {
2290
+ pattern[i-1] += '(?:\\\/|\\\/' + twoStar + '\\\/)' + pattern[i+1];
2291
+ pattern[i+1] = GLOBSTAR;
2292
+ }
2293
+ });
2294
+ return pattern.filter(p => p !== GLOBSTAR).join('/')
2295
+ }).join('|');
2296
+
2297
+ // must match entire pattern
2298
+ // ending in a * or ** will make it less strict.
2299
+ re = '^(?:' + re + ')$';
2300
+
2301
+ // can match anything, as long as it's not this.
2302
+ if (this.negate) re = '^(?!' + re + ').*$';
2303
+
2304
+ try {
2305
+ this.regexp = new RegExp(re, flags);
2306
+ } catch (ex) /* istanbul ignore next - should be impossible */ {
2307
+ this.regexp = false;
2308
+ }
2309
+ return this.regexp
2310
+ }
2311
+
2312
+ match (f, partial = this.partial) {
2313
+ this.debug('match', f, this.pattern);
2314
+ // short-circuit in the case of busted things.
2315
+ // comments, etc.
2316
+ if (this.comment) return false
2317
+ if (this.empty) return f === ''
2318
+
2319
+ if (f === '/' && partial) return true
2320
+
2321
+ const options = this.options;
2322
+
2323
+ // windows: need to use /, not \
2324
+ if (path.sep !== '/') {
2325
+ f = f.split(path.sep).join('/');
2326
+ }
2327
+
2328
+ // treat the test path as a set of pathparts.
2329
+ f = f.split(slashSplit);
2330
+ this.debug(this.pattern, 'split', f);
2331
+
2332
+ // just ONE of the pattern sets in this.set needs to match
2333
+ // in order for it to be valid. If negating, then just one
2334
+ // match means that we have failed.
2335
+ // Either way, return on the first hit.
2336
+
2337
+ const set = this.set;
2338
+ this.debug(this.pattern, 'set', set);
2339
+
2340
+ // Find the basename of the path by looking for the last non-empty segment
2341
+ let filename;
2342
+ for (let i = f.length - 1; i >= 0; i--) {
2343
+ filename = f[i];
2344
+ if (filename) break
2345
+ }
2346
+
2347
+ for (let i = 0; i < set.length; i++) {
2348
+ const pattern = set[i];
2349
+ let file = f;
2350
+ if (options.matchBase && pattern.length === 1) {
2351
+ file = [filename];
2352
+ }
2353
+ const hit = this.matchOne(file, pattern, partial);
2354
+ if (hit) {
2355
+ if (options.flipNegate) return true
2356
+ return !this.negate
2357
+ }
2358
+ }
2359
+
2360
+ // didn't get any hits. this is success if it's a negative
2361
+ // pattern, failure otherwise.
2362
+ if (options.flipNegate) return false
2363
+ return this.negate
2364
+ }
2365
+
2366
+ static defaults (def) {
2367
+ return minimatch.defaults(def).Minimatch
2368
+ }
2369
+ }
2370
+
2371
+ minimatch.Minimatch = Minimatch;
2372
+
2373
+ var minimatch$1 = minimatch_1;
2374
+
2375
+ const CAMEL_CASE_REGEX = /^[a-z][A-Za-z0-9]*$/;
2376
+ const CONSTANT_CASE_REGEX = /^[A-Z_]+$/;
2377
+ const PASCAL_CASE_REGEX = /^[A-Z][A-Za-z0-9]*$/;
2378
+ const SNAKE_CASE_REGEX$1 = /^[a-z0-9_]+$/;
2379
+ const EXPORT_PATTERN = {
2380
+ type: ramda.includes(ramda.__, [TYPES.EXPORT_DEFAULT_DECLARATION, TYPES.EXPORT_NAMED_DECLARATION])
2381
+ };
2382
+
2383
+ const isInsideBaseDirectory = context => context.getFilename().startsWith(context.options[0].basePath);
2384
+
2385
+ const asArray = item => {
2386
+ if (!item) return [];
2387
+ return Array.isArray(item) ? item : new Array(item);
2388
+ };
2389
+
2390
+ const isCaseMatching = (text, caseStyle) => {
2391
+ var _regexes$caseStyle;
2392
+
2393
+ if (!text) return true;
2394
+ const regexes = {
2395
+ camelCase: CAMEL_CASE_REGEX,
2396
+ CONSTANT_CASE: CONSTANT_CASE_REGEX,
2397
+ PascalCase: PASCAL_CASE_REGEX,
2398
+ snake_case: SNAKE_CASE_REGEX$1
2399
+ };
2400
+ return ((_regexes$caseStyle = regexes[caseStyle]) === null || _regexes$caseStyle === void 0 ? void 0 : _regexes$caseStyle.test(text)) ?? true;
2401
+ };
2402
+
2403
+ const findMatchedConfig = (context, configs) => {
2404
+ const fullFilePath = context.getFilename();
2405
+ const matchedConfig = configs.find(config => {
2406
+ const isIncluded = asArray(config.includes).some(pathPattern => minimatch$1(fullFilePath, pathPattern));
2407
+ if (config.includes && !isIncluded) return false;
2408
+ const isExcluded = asArray(config.excludes).some(pathPattern => minimatch$1(fullFilePath, pathPattern));
2409
+ if (config.excludes && isExcluded) return false;
2410
+ return true;
2411
+ });
2412
+ return matchedConfig;
2413
+ };
2414
+
2415
+ const checkFilenameCase = (context, node, filenameCase) => {
2416
+ const [filename] = getFilenameAndExtension(context);
2417
+ if (filename === "index") return;
2418
+
2419
+ if (!isCaseMatching(filename, filenameCase)) {
2420
+ context.report({
2421
+ node,
2422
+ message: filenameShouldBe(filenameCase)
2423
+ });
2424
+ }
2425
+ };
2426
+
2427
+ const reportExportCaseMismatch = ({
2428
+ context,
2429
+ node,
2430
+ exportnameCase,
2431
+ objectName
2432
+ }) => {
2433
+ if (objectName && !isCaseMatching(objectName, exportnameCase)) {
2434
+ context.report({
2435
+ node,
2436
+ message: exportedObjectShouldBe(exportnameCase)
2437
+ });
2438
+ }
2439
+ };
2440
+
2441
+ const checkExportItemsCase = ({
2442
+ context,
2443
+ items,
2444
+ itemsType,
2445
+ exportnameCase
2446
+ }) => {
2447
+ items === null || items === void 0 ? void 0 : items.forEach(item => {
2448
+ const objectName = itemsType === "specifiers" ? item.exported.name : item.value.name;
2449
+ reportExportCaseMismatch({
2450
+ context,
2451
+ node: item,
2452
+ exportnameCase,
2453
+ objectName
2454
+ });
2455
+ });
2456
+ };
2457
+
2458
+ const checkNamedExportCase = (context, node, exportnameCase) => {
2459
+ var _node$declaration;
2460
+
2461
+ if (((_node$declaration = node.declaration) === null || _node$declaration === void 0 ? void 0 : _node$declaration.kind) === "const") {
2462
+ node.declaration.declarations.forEach(({
2463
+ id
2464
+ }) => {
2465
+ if (id.type === TYPES.IDENTIFIER) {
2466
+ reportExportCaseMismatch({
2467
+ context,
2468
+ node: id,
2469
+ exportnameCase,
2470
+ objectName: id.name
2471
+ });
2472
+ } else {
2473
+ checkExportItemsCase({
2474
+ context,
2475
+ items: id.properties,
2476
+ itemsType: "properties",
2477
+ exportnameCase
2478
+ });
2479
+ }
2480
+ });
2481
+ } else {
2482
+ checkExportItemsCase({
2483
+ context,
2484
+ items: node.specifiers,
2485
+ itemsType: "specifiers",
2486
+ exportnameCase
2487
+ });
2488
+ }
2489
+ };
2490
+
2491
+ const checkDefaultExportCase = (context, node, exportnameCase) => {
2492
+ var _declaration$id;
2493
+
2494
+ const declaration = node.declaration;
2495
+
2496
+ if (declaration.type === TYPES.OBJECT_EXPRESSION) {
2497
+ checkExportItemsCase({
2498
+ context,
2499
+ items: declaration.properties,
2500
+ itemsType: "properties",
2501
+ exportnameCase
2502
+ });
2503
+ return;
2504
+ }
2505
+
2506
+ const objectName = declaration.type === TYPES.IDENTIFIER ? declaration.name : (_declaration$id = declaration.id) === null || _declaration$id === void 0 ? void 0 : _declaration$id.name;
2507
+ reportExportCaseMismatch({
2508
+ context,
2509
+ node,
2510
+ exportnameCase,
2511
+ objectName
2512
+ });
2513
+ };
2514
+
2515
+ const checkExportnameCase = (context, exportNodes, exportnameCase) => {
2516
+ exportNodes.forEach(node => {
2517
+ const isNamedExport = node.type === TYPES.EXPORT_NAMED_DECLARATION;
2518
+
2519
+ if (isNamedExport) {
2520
+ checkNamedExportCase(context, node, exportnameCase);
2521
+ } else {
2522
+ checkDefaultExportCase(context, node, exportnameCase);
2523
+ }
2524
+ });
2525
+ };
2526
+
2527
+ const checkFilenameAndExportname = (context, exportNodes) => {
2528
+ var _defaultExportNode$de;
2529
+
2530
+ const [filename] = getFilenameAndExtension(context);
2531
+ const defaultExportNode = exportNodes.find(node => node.type === TYPES.EXPORT_DEFAULT_DECLARATION);
2532
+ if (!defaultExportNode) return;
2533
+ const exportedObjectName = (_defaultExportNode$de = defaultExportNode.declaration) === null || _defaultExportNode$de === void 0 ? void 0 : _defaultExportNode$de.name;
2534
+ if (!exportedObjectName) return;
2535
+ const pathKeys = context.getFilename().split(/\.|\//g).slice(0, -1);
2536
+ const pathString = filename === "index" ? pathKeys.slice(0, -1).join("") : pathKeys.join("");
2537
+ const isNameMatches = pathString.endsWith(exportedObjectName);
2538
+ if (isNameMatches) return;
2539
+ context.report({
2540
+ node: defaultExportNode,
2541
+ message: EXPORTED_OBJECT_AND_FILENAME_SHOULD_MATCH_MESSAGE
2542
+ });
2543
+ };
2544
+
2545
+ var fileNameAndExportNameStandards = {
2546
+ meta: {
2547
+ type: "suggestion",
2548
+ docs: {
2549
+ description: "Allows you to enforce a consistent naming pattern for the filenames and exports."
2550
+ }
2551
+ },
2552
+ create: context => ({
2553
+ Program(node) {
2554
+ if (!isInsideBaseDirectory(context)) return;
2555
+ const defaultConfig = context.options[0].default;
2556
+ const configs = context.options[0].configs;
2557
+ const {
2558
+ filenameCase,
2559
+ exportnameCase,
2560
+ matchFileNameAndExportName
2561
+ } = findMatchedConfig(context, configs) || defaultConfig;
2562
+
2563
+ if (filenameCase) {
2564
+ checkFilenameCase(context, node, filenameCase);
2565
+ }
2566
+
2567
+ if (exportnameCase || matchFileNameAndExportName) {
2568
+ const exportNodes = findMatchingNodesDeep(node, EXPORT_PATTERN);
2569
+
2570
+ if (exportnameCase) {
2571
+ checkExportnameCase(context, exportNodes, exportnameCase);
2572
+ }
2573
+
2574
+ if (matchFileNameAndExportName) {
2575
+ checkFilenameAndExportname(context, exportNodes);
2576
+ }
2577
+ }
2578
+ }
2579
+
2580
+ })
2581
+ };
2582
+
2583
+ const ASSIGNMENT_PATTERNS = [{
2584
+ id: {
2585
+ type: TYPES.OBJECT_PATTERN
2586
+ }
2587
+ }, {
2588
+ id: {
2589
+ type: TYPES.IDENTIFIER
2590
+ }
2591
+ }];
2592
+ const IDENTIFIER_INITIALIZATION_PATTERN = {
2593
+ type: TYPES.IDENTIFIER,
2594
+ name: "globalProps"
2595
+ };
2596
+ const MEMBER_EXPRESSION_INITIALIZATION_PATTERN = {
2597
+ type: TYPES.MEMBER_EXPRESSION,
2598
+ object: {
2599
+ type: TYPES.IDENTIFIER,
2600
+ name: "globalProps"
2601
+ }
2602
+ };
2603
+ const GLOBALPROPS_REASSIGNMENT_PATTERN = {
2604
+ type: TYPES.IDENTIFIER,
2605
+ name: "globalProps"
2606
+ };
2607
+
2608
+ const checkAssignment = (context, node) => {
2609
+ if (matches(IDENTIFIER_INITIALIZATION_PATTERN, node)) {
2610
+ context.report(node, GLOBALPROPS_NO_ASSIGNMENT_MESSAGE);
2611
+ } else if (matches(MEMBER_EXPRESSION_INITIALIZATION_PATTERN, node)) {
2612
+ context.report(node, NESTED_GLOBALPROPS_NO_ASSIGNMENT_MESSAGE);
2613
+ }
2614
+ };
2615
+
2616
+ var noGlobalPropsDestructure = {
2617
+ meta: {
2618
+ type: "problem",
2619
+ docs: {
2620
+ description: "Disallows destructuring of globalProps."
2621
+ }
2622
+ },
2623
+ create: context => ({
2624
+ VariableDeclarator(node) {
2625
+ if (!matchesAny(ASSIGNMENT_PATTERNS, node)) return;
2626
+ checkAssignment(context, node.init);
2627
+ },
2628
+
2629
+ AssignmentExpression: node => checkAssignment(context, node.right)
2630
+ })
2631
+ };
2632
+
2633
+ var noGlobalPropsReassignment = {
2634
+ meta: {
2635
+ type: "problem",
2636
+ docs: {
2637
+ description: "Disallows re-assignment of globalProps."
2638
+ }
2639
+ },
2640
+ create: context => ({
2641
+ AssignmentExpression(node) {
2642
+ if (patternExistsDeep(GLOBALPROPS_REASSIGNMENT_PATTERN, node.left)) {
2643
+ context.report(node, NO_GLOBALPROPS_REASSIGNMENT_MESSAGE);
2644
+ }
2645
+ }
2646
+
2647
+ })
2648
+ };
2649
+
2650
+ const storeImportPattern = name => ({
2651
+ specifiers: [{
2652
+ type: "ImportDefaultSpecifier",
2653
+ local: {
2654
+ type: TYPES.IDENTIFIER,
2655
+ name
2656
+ }
2657
+ }],
2658
+ source: {
2659
+ type: TYPES.LITERAL,
2660
+ value: ramda.startsWith("stores/")
2661
+ }
2662
+ }); // import useSampleStore from "stores/sampleStore";
2663
+ // .....
2664
+ // const { order } = useSampleStore();
2665
+
2666
+
2667
+ const ZUSTAND_HOOK_USAGE_PATTERN = {
2668
+ kind: "const",
2669
+ declarations: [{
2670
+ type: TYPES.VARIABLE_DECLARATOR,
2671
+ init: {
2672
+ type: TYPES.CALL_EXPRESSION,
2673
+ callee: {
2674
+ type: TYPES.IDENTIFIER,
2675
+ name: (name, root) => name.match(/use[a-zA-z0-9].+Store/) && existsBy$1(storeImportPattern(name), getAllImports(root))
2676
+ },
2677
+ arguments: ramda.isEmpty,
2678
+ optional: false
2679
+ }
2680
+ }]
2681
+ };
2682
+
2683
+ var minimizeZustandStoreAccessScope = {
2684
+ meta: {
2685
+ type: "problem",
2686
+ docs: {
2687
+ description: "Use function based accessor for obtaining values from zustand stores. Using state as a whole is not recommended."
2688
+ }
2689
+ },
2690
+ create: context => ({
2691
+ VariableDeclaration(node) {
2692
+ if (!matches(ZUSTAND_HOOK_USAGE_PATTERN, node)) return;
2693
+ context.report({
2694
+ node,
2695
+ message: DONT_USE_ZUSTAND_STORE_WITHOUT_SELECTOR
2696
+ });
2697
+ }
2698
+
2699
+ })
2700
+ };
2701
+
2702
+ const reportSuggestion$1 = ({
2703
+ context,
2704
+ node,
1261
2705
  fix,
1262
2706
  func,
1263
2707
  message = ""
@@ -1351,6 +2795,57 @@
1351
2795
  type: TYPES.IDENTIFIER,
1352
2796
  name: "length"
1353
2797
  }
2798
+ }; // string.charAt(0).toUpperCase()
2799
+
2800
+ const CAPITALIZE_LEFT_PATTERN = {
2801
+ type: TYPES.CALL_EXPRESSION,
2802
+ callee: {
2803
+ type: TYPES.MEMBER_EXPRESSION,
2804
+ object: {
2805
+ type: TYPES.CALL_EXPRESSION,
2806
+ callee: {
2807
+ type: TYPES.MEMBER_EXPRESSION,
2808
+ object: {
2809
+ type: TYPES.IDENTIFIER,
2810
+ name: (name, root) => {
2811
+ var _root$right$callee, _root$right$callee$ob, _root$right$expressio, _root$right$expressio2, _root$right$expressio3;
2812
+
2813
+ 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);
2814
+ }
2815
+ },
2816
+ property: {
2817
+ type: TYPES.IDENTIFIER,
2818
+ name: "charAt"
2819
+ }
2820
+ },
2821
+ arguments: args => args.length === 1 && matches([{
2822
+ type: TYPES.LITERAL,
2823
+ value: 0
2824
+ }], args)
2825
+ },
2826
+ property: {
2827
+ type: TYPES.IDENTIFIER,
2828
+ name: "toUpperCase"
2829
+ }
2830
+ }
2831
+ }; // string.slice(1)
2832
+
2833
+ const CAPITALIZE_RIGHT_PATTERN = {
2834
+ type: TYPES.CALL_EXPRESSION,
2835
+ callee: {
2836
+ type: TYPES.MEMBER_EXPRESSION,
2837
+ object: {
2838
+ type: TYPES.IDENTIFIER
2839
+ },
2840
+ property: {
2841
+ type: TYPES.IDENTIFIER,
2842
+ name: "slice"
2843
+ }
2844
+ },
2845
+ arguments: args => args.length === 1 && matches([{
2846
+ type: TYPES.LITERAL,
2847
+ value: 1
2848
+ }], args)
1354
2849
  };
1355
2850
  const OBJ_KEY_LENGTH_PATTERN$1 = {
1356
2851
  type: TYPES.MEMBER_EXPRESSION,
@@ -1378,8 +2873,11 @@
1378
2873
  async: false,
1379
2874
  expression: false,
1380
2875
  body: {
1381
- type: "BlockStatement",
2876
+ type: TYPES.BLOCK_STATEMENT,
1382
2877
  body: body => ramda.isEmpty(body)
2878
+ },
2879
+ parent: {
2880
+ type: notEquals(TYPES.EXPORT_DEFAULT_DECLARATION)
1383
2881
  }
1384
2882
  };
1385
2883
  const LABEL_AND_VALUE_PATTERN = {
@@ -1470,6 +2968,17 @@
1470
2968
  type: matchesAny([TYPES.IF_STATEMENT, TYPES.WHILE_STATEMENT]),
1471
2969
  test: matchesAny([ARRAY_LENGTH_PATTERN$1, OBJ_KEY_LENGTH_PATTERN$1])
1472
2970
  },
2971
+ // !!array.length, !!Object.keys(obj).length
2972
+ UNARY_EXP: {
2973
+ type: TYPES.UNARY_EXPRESSION,
2974
+ operator: "!",
2975
+ prefix: true,
2976
+ argument: matchesAny([ARRAY_LENGTH_PATTERN$1, OBJ_KEY_LENGTH_PATTERN$1]),
2977
+ parent: {
2978
+ type: TYPES.UNARY_EXPRESSION,
2979
+ operator: "!"
2980
+ }
2981
+ },
1473
2982
  // x => !isEmpty(x)
1474
2983
  ARROW_FUNC: {
1475
2984
  type: TYPES.ARROW_FUNCTION_EXPRESSION,
@@ -1504,11 +3013,15 @@
1504
3013
  expression: true,
1505
3014
  params: params => params.length === 1 && params[0].type === TYPES.IDENTIFIER,
1506
3015
  body: {
1507
- type: "ConditionalExpression",
3016
+ type: TYPES.CONDITIONAL_EXPRESSION,
1508
3017
  test: (test, root) => areAllChecksWithParams(test, arrayFuncParam(root), {
1509
3018
  compare: "===",
1510
3019
  join: "&&"
1511
3020
  }),
3021
+ consequent: (consq, root) => ramda.not(ramda.any(patternExistsDeep({
3022
+ type: TYPES.IDENTIFIER,
3023
+ name: name => name === arrayFuncParam(root).name
3024
+ }), consq.type === TYPES.OBJECT_EXPRESSION ? consq.properties : [consq])),
1512
3025
  alternate: {
1513
3026
  type: TYPES.IDENTIFIER,
1514
3027
  name: (name, root) => name === arrayFuncParam(root).name
@@ -1517,7 +3030,7 @@
1517
3030
  }]
1518
3031
  };
1519
3032
  const REPLACE_BY_NEGATED_PATTERN = ramda.assocPath(["arguments", 0, "body"], {
1520
- type: "ConditionalExpression",
3033
+ type: TYPES.CONDITIONAL_EXPRESSION,
1521
3034
  test: (test, root) => areAllChecksWithParams(test, arrayFuncParam(root), {
1522
3035
  compare: "!==",
1523
3036
  join: "||"
@@ -1525,36 +3038,56 @@
1525
3038
  consequent: {
1526
3039
  type: TYPES.IDENTIFIER,
1527
3040
  name: (name, root) => name === arrayFuncParam(root).name
1528
- }
3041
+ },
3042
+ alternate: (alt, root) => ramda.not(ramda.any(patternExistsDeep({
3043
+ type: TYPES.IDENTIFIER,
3044
+ name: name => name === arrayFuncParam(root).name
3045
+ }), alt.type === TYPES.OBJECT_EXPRESSION ? alt.properties : [alt]))
1529
3046
  }, REPLACE_BY_PATTERN);
1530
3047
  const COPY_KEYS_PATTERN = {
1531
- properties: props => props.length > 1 && matches({
1532
- type: TYPES.SPREAD_ELEMENT,
1533
- argument: {
1534
- type: TYPES.IDENTIFIER
3048
+ type: TYPES.CALL_EXPRESSION,
3049
+ callee: {
3050
+ type: TYPES.MEMBER_EXPRESSION,
3051
+ property: {
3052
+ type: TYPES.IDENTIFIER,
3053
+ name: "map"
1535
3054
  }
1536
- }, props[0]) && props.slice(1).every(matches({
1537
- type: TYPES.PROPERTY,
1538
- kind: "init",
1539
- method: false,
1540
- computed: false,
1541
- shorthand: false,
1542
- key: {
1543
- type: TYPES.IDENTIFIER
1544
- },
1545
- value: {
1546
- type: TYPES.MEMBER_EXPRESSION,
1547
- computed: false,
1548
- optional: false,
1549
- object: {
1550
- type: TYPES.IDENTIFIER,
1551
- name: props[0].argument.name
1552
- },
1553
- property: {
1554
- type: TYPES.IDENTIFIER
1555
- }
3055
+ },
3056
+ arguments: [{
3057
+ type: TYPES.ARROW_FUNCTION_EXPRESSION,
3058
+ params: params => params.length === 1 && params[0].type === TYPES.IDENTIFIER,
3059
+ body: {
3060
+ type: TYPES.OBJECT_EXPRESSION,
3061
+ properties: (props, root) => props.length > 1 && matches({
3062
+ type: TYPES.SPREAD_ELEMENT,
3063
+ argument: {
3064
+ type: TYPES.IDENTIFIER,
3065
+ name: root.arguments[0].params[0].name
3066
+ }
3067
+ }, props[0]) && props.slice(1).every(matches({
3068
+ type: TYPES.PROPERTY,
3069
+ kind: "init",
3070
+ method: false,
3071
+ computed: false,
3072
+ shorthand: false,
3073
+ key: {
3074
+ type: TYPES.IDENTIFIER
3075
+ },
3076
+ value: {
3077
+ type: TYPES.MEMBER_EXPRESSION,
3078
+ computed: false,
3079
+ optional: false,
3080
+ object: {
3081
+ type: TYPES.IDENTIFIER,
3082
+ name: props[0].argument.name
3083
+ },
3084
+ property: {
3085
+ type: TYPES.IDENTIFIER
3086
+ }
3087
+ }
3088
+ }))
1556
3089
  }
1557
- }))
3090
+ }]
1558
3091
  };
1559
3092
  const NOT_EQUALS_PATTERNS = {
1560
3093
  // !Object.is(item1, item2)
@@ -1611,60 +3144,23 @@
1611
3144
  }
1612
3145
  }
1613
3146
  };
1614
- const CAPITALIZE_PATTERN = {
1615
- // string.charAt(0).toUpperCase() + string.slice(1)
1616
- type: TYPES.BINARY_EXPRESSION,
3147
+ const CAPITALIZE_PATTERNS = [// string.charAt(0).toUpperCase() + string.slice(1)
3148
+ {
3149
+ operator: "+",
3150
+ left: CAPITALIZE_LEFT_PATTERN,
3151
+ right: CAPITALIZE_RIGHT_PATTERN
3152
+ }, // string?.charAt(0).toUpperCase() + string?.slice(1)
3153
+ {
1617
3154
  operator: "+",
1618
3155
  left: {
1619
- type: TYPES.CALL_EXPRESSION,
1620
- callee: {
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
- }
3156
+ type: TYPES.CHAIN_EXPRESSION,
3157
+ expression: CAPITALIZE_LEFT_PATTERN
1649
3158
  },
1650
3159
  right: {
1651
- type: TYPES.CALL_EXPRESSION,
1652
- callee: {
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)
3160
+ type: TYPES.CHAIN_EXPRESSION,
3161
+ expression: CAPITALIZE_RIGHT_PATTERN
1666
3162
  }
1667
- };
3163
+ }];
1668
3164
  const COUNT_BY_PATTERN = {
1669
3165
  type: TYPES.MEMBER_EXPRESSION,
1670
3166
  computed: false,
@@ -1711,11 +3207,14 @@
1711
3207
  array = getCode$1(context, node.callee.object);
1712
3208
  } else if (matches(genericPatterns.RAMDA, node)) {
1713
3209
  array = getCode$1(context, node.arguments[1]);
1714
- } else return; // arr.filter(x => x.prop === something).length
3210
+ } else return;
1715
3211
 
3212
+ const byIdFunc = optionalChainingOptimizedName(functions.byId, node.callee);
3213
+ const byFunc = optionalChainingOptimizedName(functions.by, node.callee); // arr.filter(x => x.prop === something).length
1716
3214
 
1717
3215
  if (functions.by === "filterBy" && matches(COUNT_BY_PATTERN, node.parent)) {
1718
- const message = canBeShortenedWithCommons("countBy");
3216
+ const func = optionalChainingOptimizedName("countBy", node.callee);
3217
+ const message = canBeShortenedWithCommons(func);
1719
3218
  context.report({
1720
3219
  node: node.parent,
1721
3220
  message
@@ -1735,15 +3234,15 @@
1735
3234
 
1736
3235
  if (idUsagePattern) {
1737
3236
  const id = matches(idUsagePattern, predicate.body.left) ? getCode$1(context, predicate.body.right) : getCode$1(context, predicate.body.left);
1738
- const fix = `${functions.byId}(${id}, ${array})`;
1739
- reportSuggestion({
3237
+ const fix = `${byIdFunc}(${id}, ${array})`;
3238
+ reportSuggestion$1({
1740
3239
  context,
1741
3240
  node,
1742
3241
  fix,
1743
- func: functions.byId
3242
+ func: byIdFunc
1744
3243
  });
1745
3244
  } else {
1746
- const message = canBeShortenedWithCommons(functions.by);
3245
+ const message = canBeShortenedWithCommons(byFunc);
1747
3246
  context.report({
1748
3247
  node,
1749
3248
  message
@@ -1752,7 +3251,7 @@
1752
3251
  } else {
1753
3252
  context.report({
1754
3253
  node,
1755
- message: canBeShortenedWithCommons(functions.by)
3254
+ message: canBeShortenedWithCommons(byFunc)
1756
3255
  });
1757
3256
  }
1758
3257
  };
@@ -1885,30 +3384,33 @@
1885
3384
  var capitalize = {
1886
3385
  operateOn: TYPES.BINARY_EXPRESSION,
1887
3386
  check: (context, node) => {
1888
- if (!matches(CAPITALIZE_PATTERN, node)) return;
1889
- const fix = `capitalize(${getCode$1(context, node.right.callee.object)})`;
1890
- reportSuggestion({
3387
+ if (!matchesAny(CAPITALIZE_PATTERNS, node)) return;
3388
+ const stringNode = node.right.type === TYPES.CHAIN_EXPRESSION ? node.right.expression.callee.object : node.right.callee.object;
3389
+ const func = optionalChainingOptimizedName("capitalize", node.right);
3390
+ const fix = `${func}(${getCode$1(context, stringNode)})`;
3391
+ reportSuggestion$1({
1891
3392
  context,
1892
3393
  node,
1893
3394
  fix,
1894
- func: "capitalize"
3395
+ func
1895
3396
  });
1896
3397
  }
1897
3398
  };
1898
3399
 
1899
3400
  var copyKeys = {
1900
- operateOn: TYPES.OBJECT_EXPRESSION,
3401
+ operateOn: TYPES.CALL_EXPRESSION,
1901
3402
  check: (context, node) => {
1902
3403
  if (!matches(COPY_KEYS_PATTERN, node)) return;
1903
- const keyValuePairs = node.properties.slice(1).map(prop => [prop.value.property.name, prop.key.name]);
3404
+ const keyValuePairs = node.arguments[0].body.properties.slice(1).map(prop => [prop.value.property.name, prop.key.name]);
1904
3405
  const keyMap = JSON.stringify(ramda.fromPairs(keyValuePairs));
1905
- const sourceObject = getCode$1(context, node.properties[0].argument);
1906
- const fix = `copyKeys(${keyMap}, ${sourceObject})`;
1907
- reportSuggestion({
3406
+ const sourceObject = getCode$1(context, node.callee.object);
3407
+ const func = optionalChainingOptimizedName("copyKeys", node.callee);
3408
+ const fix = `${func}(${keyMap}, ${sourceObject})`;
3409
+ reportSuggestion$1({
1908
3410
  context,
1909
3411
  node,
1910
3412
  fix,
1911
- func: "copyKeys"
3413
+ func
1912
3414
  });
1913
3415
  }
1914
3416
  };
@@ -1920,10 +3422,12 @@
1920
3422
 
1921
3423
  if (!matches(DYNAMIC_ARRAY_PATTERN, node)) return;
1922
3424
  const length = getCode$1(context, node.arguments[0].properties[0].value);
1923
- const elementGenIndexParam = (_node$arguments$1$par = node.arguments[1].params[1]) === null || _node$arguments$1$par === void 0 ? void 0 : _node$arguments$1$par.name;
1924
- const elementGenBody = getCode$1(context, node.arguments[1].body);
1925
- const fix = `dynamicArray(${length}, ${elementGenIndexParam || "()"} => ${elementGenBody})`;
1926
- reportSuggestion({
3425
+ 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;
3426
+ const generatorBody = getCode$1(context, node.arguments[1].body);
3427
+ const isArrOrObjExp = [TYPES.ARRAY_EXPRESSION, TYPES.OBJECT_EXPRESSION].includes(node.arguments[1].body.type);
3428
+ const generator = `${indexParam || "()"} => ${isArrOrObjExp ? `(${generatorBody})` : generatorBody}`;
3429
+ const fix = `dynamicArray(${length}, ${generator})`;
3430
+ reportSuggestion$1({
1927
3431
  context,
1928
3432
  node,
1929
3433
  fix,
@@ -1951,11 +3455,18 @@
1951
3455
  externalValueNode = node.body.left;
1952
3456
  } else return;
1953
3457
 
3458
+ if (patternExistsDeep({
3459
+ type: TYPES.IDENTIFIER,
3460
+ name: argumentName
3461
+ }, externalValueNode)) {
3462
+ return;
3463
+ }
3464
+
1954
3465
  const externalValue = getCode$1(context, externalValueNode);
1955
3466
  fix = `isNot(${externalValue})`;
1956
3467
  } else return;
1957
3468
 
1958
- reportSuggestion({
3469
+ reportSuggestion$1({
1959
3470
  context,
1960
3471
  node,
1961
3472
  fix,
@@ -1965,7 +3476,7 @@
1965
3476
  };
1966
3477
 
1967
3478
  var isNotEmpty = {
1968
- operateOn: [TYPES.IF_STATEMENT, TYPES.WHILE_STATEMENT, TYPES.BINARY_EXPRESSION, TYPES.ARROW_FUNCTION_EXPRESSION],
3479
+ operateOn: [TYPES.IF_STATEMENT, TYPES.WHILE_STATEMENT, TYPES.BINARY_EXPRESSION, TYPES.ARROW_FUNCTION_EXPRESSION, TYPES.UNARY_EXPRESSION],
1969
3480
  check: (context, node) => {
1970
3481
  let fix = null;
1971
3482
  let message = "";
@@ -1973,11 +3484,20 @@
1973
3484
 
1974
3485
  if (matches(NOT_EMPTY_PATTERNS.ARROW_FUNC, node)) {
1975
3486
  fix = "isNotEmpty";
1976
- } else if (matchesAny([NOT_EMPTY_PATTERNS.BINARY_EXP, NOT_EMPTY_PATTERNS.CONDT_STAT], node)) {
1977
- const isBinaryExp = node.type === TYPES.BINARY_EXPRESSION;
1978
- const expNode = isBinaryExp ? node.left : node.test;
3487
+ } else if (matchesAny([NOT_EMPTY_PATTERNS.BINARY_EXP, NOT_EMPTY_PATTERNS.CONDT_STAT, NOT_EMPTY_PATTERNS.UNARY_EXP], node)) {
3488
+ const expNode = {
3489
+ [TYPES.BINARY_EXPRESSION]: node.left,
3490
+ [TYPES.UNARY_EXPRESSION]: node.argument,
3491
+ [TYPES.IF_STATEMENT]: node.test,
3492
+ [TYPES.WHILE_STATEMENT]: node.test
3493
+ }[node.type];
1979
3494
  const isObjLenCheck = matches(OBJ_KEY_LENGTH_PATTERN$1, expNode);
1980
- nodeToBeReplaced = isBinaryExp ? node : node.test;
3495
+ nodeToBeReplaced = {
3496
+ [TYPES.BINARY_EXPRESSION]: node,
3497
+ [TYPES.UNARY_EXPRESSION]: node.parent,
3498
+ [TYPES.IF_STATEMENT]: node.test,
3499
+ [TYPES.WHILE_STATEMENT]: node.test
3500
+ }[node.type];
1981
3501
 
1982
3502
  if (isObjLenCheck) {
1983
3503
  const objName = getCode$1(context, expNode.object.arguments[0]);
@@ -1989,7 +3509,7 @@
1989
3509
  }
1990
3510
  } else return;
1991
3511
 
1992
- reportSuggestion({
3512
+ reportSuggestion$1({
1993
3513
  context,
1994
3514
  node: nodeToBeReplaced,
1995
3515
  fix,
@@ -2022,7 +3542,7 @@
2022
3542
  fix = `isNotEqualDeep(${externalValue})`;
2023
3543
  } else return;
2024
3544
 
2025
- reportSuggestion({
3545
+ reportSuggestion$1({
2026
3546
  context,
2027
3547
  node,
2028
3548
  fix,
@@ -2040,10 +3560,10 @@
2040
3560
  if (node.type === TYPES.ARROW_FUNCTION_EXPRESSION) {
2041
3561
  fix = `isNotNil`;
2042
3562
  } else if (node.type === TYPES.LOGICAL_EXPRESSION) {
2043
- fix = `isNotNil(${node.left.left.name})`;
3563
+ fix = `isNotNil(${getCode$1(context, node.left.left)})`;
2044
3564
  }
2045
3565
 
2046
- reportSuggestion({
3566
+ reportSuggestion$1({
2047
3567
  context,
2048
3568
  node,
2049
3569
  fix,
@@ -2055,14 +3575,23 @@
2055
3575
  var noop = {
2056
3576
  operateOn: [TYPES.FUNCTION_EXPRESSION, TYPES.ARROW_FUNCTION_EXPRESSION, TYPES.FUNCTION_DECLARATION],
2057
3577
  check: (context, node) => {
2058
- if (matches(NOOP_PATTERN, node)) {
2059
- reportSuggestion({
2060
- context,
2061
- node,
2062
- fix: "noop",
2063
- func: "noop"
2064
- });
3578
+ if (!matches(NOOP_PATTERN, node)) return;
3579
+ let fix = "noop";
3580
+ let nodeToBeReplaced = node;
3581
+
3582
+ if (node.type === TYPES.FUNCTION_DECLARATION) {
3583
+ fix = `const ${node.id.name} = noop`;
3584
+ } else if (node.type === TYPES.FUNCTION_EXPRESSION && node.parent.type === TYPES.PROPERTY) {
3585
+ nodeToBeReplaced = node.parent;
3586
+ fix = `${node.parent.key.name}: noop`;
2065
3587
  }
3588
+
3589
+ reportSuggestion$1({
3590
+ context,
3591
+ node: nodeToBeReplaced,
3592
+ fix,
3593
+ func: "noop"
3594
+ });
2066
3595
  }
2067
3596
  };
2068
3597
 
@@ -2109,9 +3638,10 @@
2109
3638
  } else return;
2110
3639
 
2111
3640
  if (!matches(binaryExpressionPattern, comparison)) {
3641
+ const func = optionalChainingOptimizedName("replaceBy", node.callee);
2112
3642
  context.report({
2113
3643
  node,
2114
- message: canBeShortenedWithCommons("replaceBy")
3644
+ message: canBeShortenedWithCommons(func)
2115
3645
  });
2116
3646
  return;
2117
3647
  }
@@ -2129,12 +3659,13 @@
2129
3659
  const id = getCode$1(context, externalId);
2130
3660
  const replacement = getCode$1(context, replaceNode);
2131
3661
  const array = getCode$1(context, node.callee.object);
2132
- const fix = `replaceById(${id}, ${replacement}, ${array})`;
2133
- reportSuggestion({
3662
+ const func = optionalChainingOptimizedName("replaceById", node.callee);
3663
+ const fix = `${func}(${id}, ${replacement}, ${array})`;
3664
+ reportSuggestion$1({
2134
3665
  context,
2135
3666
  node,
2136
3667
  fix,
2137
- func: "replaceById"
3668
+ func
2138
3669
  });
2139
3670
  }
2140
3671
  };
@@ -2147,7 +3678,7 @@
2147
3678
 
2148
3679
  if (label !== value) return;
2149
3680
  const fix = `toLabelAndValue(${label})`;
2150
- reportSuggestion({
3681
+ reportSuggestion$1({
2151
3682
  context,
2152
3683
  node,
2153
3684
  fix,
@@ -2207,10 +3738,11 @@
2207
3738
  create: context => ({
2208
3739
  ImportDeclaration(node) {
2209
3740
  const disallowSources = getPackagesAndAliases(context, BLACKLISTED_PACKAGES);
2210
- if (!disallowSources.includes(node.source.value)) return;
2211
- context.report({
3741
+ const impSrc = node.source.value;
3742
+ const pkgName = disallowSources.find(src => impSrc === src || impSrc.startsWith(`${src}/`));
3743
+ if (pkgName) context.report({
2212
3744
  node,
2213
- message: disallowUse(node.source.value)
3745
+ message: disallowUse(pkgName)
2214
3746
  });
2215
3747
  }
2216
3748
 
@@ -2701,9 +4233,7 @@
2701
4233
  const ARRAY_INSERTS_PATTERN = {
2702
4234
  APPEND: {
2703
4235
  // x => [...x, y]
2704
- params: [{
2705
- type: TYPES.IDENTIFIER
2706
- }],
4236
+ params: params => params.length === 1 && params[0].type === TYPES.IDENTIFIER,
2707
4237
  body: {
2708
4238
  type: TYPES.ARRAY_EXPRESSION,
2709
4239
  elements: [{
@@ -2723,9 +4253,7 @@
2723
4253
  },
2724
4254
  PREPEND: {
2725
4255
  // x => [y, ...x]
2726
- params: [{
2727
- type: TYPES.IDENTIFIER
2728
- }],
4256
+ params: params => params.length === 1 && params[0].type === TYPES.IDENTIFIER,
2729
4257
  body: {
2730
4258
  type: TYPES.ARRAY_EXPRESSION,
2731
4259
  elements: [{
@@ -2745,9 +4273,7 @@
2745
4273
  },
2746
4274
  CONCAT: {
2747
4275
  // x => [...x, ...y]
2748
- params: [{
2749
- type: TYPES.IDENTIFIER
2750
- }],
4276
+ params: params => params.length === 1 && params[0].type === TYPES.IDENTIFIER,
2751
4277
  body: {
2752
4278
  type: TYPES.ARRAY_EXPRESSION,
2753
4279
  elements: [{
@@ -3002,9 +4528,6 @@
3002
4528
 
3003
4529
  return name === ((_root$params$10 = root.params[0]) === null || _root$params$10 === void 0 ? void 0 : _root$params$10.name);
3004
4530
  }
3005
- },
3006
- property: {
3007
- type: TYPES.IDENTIFIER
3008
4531
  }
3009
4532
  }
3010
4533
  }
@@ -3080,9 +4603,35 @@
3080
4603
  type: TYPES.UNARY_EXPRESSION,
3081
4604
  operator: "!",
3082
4605
  prefix: true,
3083
- argument: matchesAny([ARRAY_LENGTH_PATTERN, OBJ_KEY_LENGTH_PATTERN])
4606
+ argument: matchesAny([ARRAY_LENGTH_PATTERN, OBJ_KEY_LENGTH_PATTERN]),
4607
+ parent: {
4608
+ type: notEquals(TYPES.UNARY_EXPRESSION),
4609
+ operator: notEquals("!")
4610
+ }
3084
4611
  }];
4612
+
3085
4613
  const replacer = nodeReplacerWithImports(RAMDA_IMPORT_PATTERN);
4614
+ const reportSuggestion = ({
4615
+ context,
4616
+ node,
4617
+ fix,
4618
+ functions,
4619
+ message = "",
4620
+ importNullSafe = false
4621
+ }) => context.report({
4622
+ node,
4623
+ message: message || canBeReplacedWith(fix),
4624
+ suggest: [{
4625
+ desc: `Replace with ${Array.isArray(functions) ? functions[0] : functions} function`,
4626
+ fix: replacer.replaceNode({
4627
+ context,
4628
+ node,
4629
+ fix,
4630
+ functions,
4631
+ importNullSafe
4632
+ })
4633
+ }]
4634
+ });
3086
4635
 
3087
4636
  var arrayInsertsLintCheck = {
3088
4637
  operateOn: TYPES.ARROW_FUNCTION_EXPRESSION,
@@ -3101,18 +4650,11 @@
3101
4650
 
3102
4651
  if (!fix) return;
3103
4652
  const funcName = fix.split("(")[0];
3104
- context.report({
4653
+ reportSuggestion({
4654
+ context,
3105
4655
  node,
3106
- message: canBeReplacedWith(fix),
3107
- suggest: [{
3108
- desc: `Replace with ${funcName} function`,
3109
- fix: replacer.replaceNode({
3110
- context,
3111
- node,
3112
- fix,
3113
- functions: funcName
3114
- })
3115
- }]
4656
+ fix,
4657
+ functions: funcName
3116
4658
  });
3117
4659
  }
3118
4660
  };
@@ -3134,18 +4676,11 @@
3134
4676
  };
3135
4677
  if (patternExistsDeep(selfReferencingPattern, property.value)) return;
3136
4678
  const fix = convertToAssoc(context, node);
3137
- context.report({
4679
+ reportSuggestion({
4680
+ context,
3138
4681
  node,
3139
- message: canBeReplacedWith(fix),
3140
- suggest: [{
3141
- desc: "Replace with assoc function",
3142
- fix: replacer.replaceNode({
3143
- context,
3144
- node,
3145
- fix,
3146
- functions: "assoc"
3147
- })
3148
- }]
4682
+ fix,
4683
+ functions: "assoc"
3149
4684
  });
3150
4685
  }
3151
4686
  };
@@ -3155,18 +4690,11 @@
3155
4690
  check: (context, node) => {
3156
4691
  if (matches(JSON_EQUALS_PATTERN, node)) {
3157
4692
  const fix = `equals(${getCode$1(context, node.left.arguments[0])}, ${getCode$1(context, node.right.arguments[0])})`;
3158
- context.report({
4693
+ reportSuggestion({
4694
+ context,
3159
4695
  node,
3160
- message: canBeReplacedWith(fix),
3161
- suggest: [{
3162
- desc: "Replace with equals function",
3163
- fix: replacer.replaceNode({
3164
- context,
3165
- node,
3166
- fix,
3167
- functions: "equals"
3168
- })
3169
- }]
4696
+ fix,
4697
+ functions: "equals"
3170
4698
  });
3171
4699
  }
3172
4700
  }
@@ -3176,18 +4704,11 @@
3176
4704
  operateOn: TYPES.ARROW_FUNCTION_EXPRESSION,
3177
4705
  check: (context, node) => {
3178
4706
  if (matches(IDENTITY_PATTERN, node)) {
3179
- context.report({
4707
+ reportSuggestion({
4708
+ context,
3180
4709
  node,
3181
- message: canBeReplacedWith("identity"),
3182
- suggest: [{
3183
- desc: "Replace with identity function",
3184
- fix: replacer.replaceNode({
3185
- context,
3186
- node,
3187
- fix: "identity",
3188
- functions: "identity"
3189
- })
3190
- }]
4710
+ fix: "identity",
4711
+ functions: "identity"
3191
4712
  });
3192
4713
  }
3193
4714
  }
@@ -3198,7 +4719,7 @@
3198
4719
  check: (context, node) => {
3199
4720
  if (!matchesAny(EMPTY_PATTERN, node)) return;
3200
4721
  let fix = null;
3201
- let message = "";
4722
+ let message = "Can be replaced with isEmpty function";
3202
4723
  const isBinaryExp = node.type === TYPES.BINARY_EXPRESSION;
3203
4724
  const expNode = isBinaryExp ? node.left : node.argument;
3204
4725
  const isObjLenCheck = matches(OBJ_KEY_LENGTH_PATTERN, expNode);
@@ -3215,9 +4736,9 @@
3215
4736
  reportSuggestion({
3216
4737
  context,
3217
4738
  node,
4739
+ message,
3218
4740
  fix,
3219
- func: "isEmpty",
3220
- message
4741
+ functions: "isEmpty"
3221
4742
  });
3222
4743
  }
3223
4744
  };
@@ -3231,7 +4752,7 @@
3231
4752
  context,
3232
4753
  node,
3233
4754
  fix,
3234
- func: "isNil"
4755
+ functions: "isNil"
3235
4756
  });
3236
4757
  }
3237
4758
  };
@@ -3258,51 +4779,39 @@
3258
4779
  const properties = node.body.properties.slice(1);
3259
4780
  if (patternExistsDeep(selfReferencingPattern, properties)) return;
3260
4781
  const fix = convertToMergeLeft(context, node);
3261
- context.report({
4782
+ reportSuggestion({
4783
+ context,
3262
4784
  node,
3263
- message: canBeReplacedWith(fix),
3264
- suggest: [{
3265
- desc: "Replace with mergeLeft function",
3266
- fix: replacer.replaceNode({
3267
- context,
3268
- node,
3269
- fix,
3270
- functions: "mergeLeft"
3271
- })
3272
- }]
4785
+ fix,
4786
+ functions: "mergeLeft"
3273
4787
  });
3274
4788
  }
3275
4789
  };
3276
4790
 
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
4791
  var pluckLintCheck = {
3292
4792
  operateOn: TYPES.CALL_EXPRESSION,
3293
4793
  check: (context, node) => {
3294
4794
  if (matches(PLUCK_PATTERNS.OBJECT_ARROW_FUNCTION, node)) {
3295
4795
  const code = getCode$1(context, node.callee.object);
4796
+ const isNullSafeRequired = isOptionalChainingPresent(node.callee);
4797
+ const callee = isNullSafeRequired ? "nullSafe(pluck)" : "pluck";
3296
4798
  const func = node.arguments[0];
4799
+ let fix = null;
3297
4800
 
3298
4801
  if (matches(PLUCK_PATTERNS.IDENTIFIER, func)) {
3299
- const fix = `pluck("${func.body.property.name}", ${code})`;
3300
- reportViolation(context, node, fix);
4802
+ fix = `${callee}("${func.body.property.name}", ${code})`;
3301
4803
  } else if (matches(PLUCK_PATTERNS.DESTRUCTURE, func)) {
3302
4804
  const propertyName = func.params[0].properties[0].value.name;
3303
- const fix = `pluck("${propertyName}", ${code})`;
3304
- reportViolation(context, node, fix);
3305
- }
4805
+ fix = `${callee}("${propertyName}", ${code})`;
4806
+ } else return;
4807
+
4808
+ reportSuggestion({
4809
+ context,
4810
+ node,
4811
+ fix,
4812
+ functions: "pluck",
4813
+ importNullSafe: isNullSafeRequired
4814
+ });
3306
4815
  }
3307
4816
  }
3308
4817
  };
@@ -3316,23 +4825,21 @@
3316
4825
  if (matches(PROP_PATTERNS.OBJECT, node)) {
3317
4826
  fix = `prop("${node.body.name}")`;
3318
4827
  } else if (matches(PROP_PATTERNS.IDENTITY, node)) {
3319
- fix = `prop("${node.body.property.name}")`;
3320
- } else {
3321
- return;
3322
- }
4828
+ const isComputed = node.body.computed;
4829
+ const propertyType = node.body.property.type;
3323
4830
 
3324
- context.report({
4831
+ if (isComputed) {
4832
+ fix = propertyType === TYPES.IDENTIFIER ? `prop(${node.body.property.name})` : `prop("${node.body.property.value}")`;
4833
+ } else {
4834
+ fix = `prop("${node.body.property.name}")`;
4835
+ }
4836
+ } else return;
4837
+
4838
+ reportSuggestion({
4839
+ context,
3325
4840
  node,
3326
- message: canBeReplacedWith(fix),
3327
- suggest: [{
3328
- desc: "Replace with prop function",
3329
- fix: replacer.replaceNode({
3330
- context,
3331
- node,
3332
- fix,
3333
- functions: "prop"
3334
- })
3335
- }]
4841
+ fix,
4842
+ functions: "prop"
3336
4843
  });
3337
4844
  }
3338
4845
  };
@@ -3369,31 +4876,27 @@
3369
4876
  if (!accumulator || !delta) return;
3370
4877
  let fix = null;
3371
4878
  let functions = ["sum"];
4879
+ const code = getCode$1(context, node.callee.object);
4880
+ let isNullSafeRequired = false;
3372
4881
 
3373
4882
  if (reduceFunc.params[1].type === TYPES.IDENTIFIER && delta.type === TYPES.IDENTIFIER && delta.name === reduceFunc.params[1].name) {
3374
- fix = `sum(${getCode$1(context, node.callee.object)})`;
3375
- } else if (reduceFunc.params[1].type === TYPES.OBJECT_PATTERN && delta.type === TYPES.IDENTIFIER && delta.name === reduceFunc.params[1].properties[0].value.name) {
3376
- fix = `sum(pluck("${delta.name}", ${getCode$1(context, node.callee.object)}))`;
4883
+ isNullSafeRequired = isOptionalChainingPresent(node.callee);
4884
+ const func = isNullSafeRequired ? "nullSafe(sum)" : "sum";
4885
+ fix = `${func}(${code})`;
4886
+ } 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)) {
4887
+ fix = `sum(pluck("${delta.name}", ${code}))`;
3377
4888
  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}", ${getCode$1(context, node.callee.object)}))`;
4889
+ } 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)) {
4890
+ fix = `sum(pluck("${delta.property.name}", ${code}))`;
3380
4891
  functions = ["sum", "pluck"];
3381
- } else {
3382
- return;
3383
- }
4892
+ } else return;
3384
4893
 
3385
- context.report({
4894
+ reportSuggestion({
4895
+ context,
3386
4896
  node,
3387
- message: canBeReplacedWith(fix),
3388
- suggest: [{
3389
- desc: "Replace with sum function",
3390
- fix: replacer.replaceNode({
3391
- context,
3392
- node,
3393
- fix,
3394
- functions
3395
- })
3396
- }]
4897
+ fix,
4898
+ functions,
4899
+ importNullSafe: isNullSafeRequired
3397
4900
  });
3398
4901
  }
3399
4902
  };
@@ -3419,6 +4922,61 @@
3419
4922
  }
3420
4923
  };
3421
4924
 
4925
+ const BREAK_STATEMENT_PATTERN = {
4926
+ type: TYPES.BREAK_STATEMENT
4927
+ };
4928
+ const RETURN_STATEMENT_PATTERN = {
4929
+ type: TYPES.RETURN_STATEMENT
4930
+ };
4931
+ const ARRAY_LENGTH_TEST_PATTERN = {
4932
+ test: {
4933
+ right: {
4934
+ type: TYPES.MEMBER_EXPRESSION,
4935
+ property: {
4936
+ name: "length"
4937
+ }
4938
+ }
4939
+ }
4940
+ };
4941
+ const CHAR_AT_PATTERN = {
4942
+ type: TYPES.CALL_EXPRESSION,
4943
+ callee: {
4944
+ property: {
4945
+ name: ramda.includes(ramda.__, ["charAt", "charCodeAt"])
4946
+ }
4947
+ }
4948
+ };
4949
+
4950
+ const isForLoopReplacable = node => ramda.not(patternExistsDeep(BREAK_STATEMENT_PATTERN, node.body) || patternExistsDeep(RETURN_STATEMENT_PATTERN, node.body) || patternExistsDeep(CHAR_AT_PATTERN, node.body));
4951
+
4952
+ var useArrayMethods = {
4953
+ meta: {
4954
+ type: "suggestion",
4955
+ docs: {
4956
+ description: "Warns when for loop is used instead of array methods."
4957
+ }
4958
+ },
4959
+ create: context => ({
4960
+ ForStatement(node) {
4961
+ if (!matches(ARRAY_LENGTH_TEST_PATTERN, node)) return;
4962
+ if (!isForLoopReplacable(node)) return;
4963
+ context.report({
4964
+ node,
4965
+ message: USE_ARRAY_METHODS
4966
+ });
4967
+ },
4968
+
4969
+ ForOfStatement(node) {
4970
+ if (!isForLoopReplacable(node)) return;
4971
+ context.report({
4972
+ node,
4973
+ message: USE_ARRAY_METHODS
4974
+ });
4975
+ }
4976
+
4977
+ })
4978
+ };
4979
+
3422
4980
  const VALID_URL_TYPES = [TYPES.LITERAL, TYPES.TEMPLATE_LITERAL];
3423
4981
  const AXIOS_GET_PATTERN = {
3424
4982
  callee: {
@@ -3517,6 +5075,101 @@
3517
5075
  })
3518
5076
  };
3519
5077
 
5078
+ const COLORS = ["black", "white", "gray", "red", "yellow", "green", "blue", "indigo", "purple", "pink"];
5079
+ const SIZES = ["none", "sm", "md", "lg", "xl", "2xl", "3xl", "full"];
5080
+ const BORDER_COLOR_PATTERNS = COLORS.map(color => new RegExp(`^((hover|focus|focus-visible):)?border-${color}(-[0-9]{2,3})?$`));
5081
+ const BORDER_RADIUS_PATTERNS = SIZES.map(size => new RegExp(`^rounded(-${size})?$`));
5082
+ const BOX_SHADOW_PATTERNS = SIZES.map(size => new RegExp(`^shadow(-${size})?$`));
5083
+ const TEXT_COLOR_PATTERNS = COLORS.map(color => new RegExp(`^((hover|focus|focus-visible):)?text-${color}(-[0-9]{2,3})?$`));
5084
+ const TAILWIND_CLASS_PATTERNS = {
5085
+ borderColor: {
5086
+ patterns: BORDER_COLOR_PATTERNS,
5087
+ message: USE_NEETOUI_BORDER_COLOR
5088
+ },
5089
+ borderRadius: {
5090
+ patterns: BORDER_RADIUS_PATTERNS,
5091
+ message: USE_NEETOUI_BORDER_RADIUS
5092
+ },
5093
+ boxShadow: {
5094
+ patterns: BOX_SHADOW_PATTERNS,
5095
+ message: USE_NEETOUI_BOX_SHADOW
5096
+ },
5097
+ textColor: {
5098
+ patterns: TEXT_COLOR_PATTERNS,
5099
+ message: USE_NEETOUI_TEXT_COLOR
5100
+ }
5101
+ };
5102
+
5103
+ const getLocation = ({
5104
+ nodeValue,
5105
+ nodeLoc,
5106
+ cssClass
5107
+ }) => {
5108
+ const startCol = nodeLoc.start.column + nodeValue.indexOf(cssClass) + 1;
5109
+ const endCol = startCol + cssClass.length;
5110
+ const line = nodeLoc.start.line;
5111
+ return {
5112
+ start: {
5113
+ line,
5114
+ column: startCol
5115
+ },
5116
+ end: {
5117
+ line,
5118
+ column: endCol
5119
+ }
5120
+ };
5121
+ };
5122
+
5123
+ const getCssProperty = cssClass => {
5124
+ let property = "";
5125
+ 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";
5126
+ return property;
5127
+ };
5128
+
5129
+ const checkAndReportTailwindClasses = (context, node) => {
5130
+ const nodeValue = node.type === TYPES.LITERAL ? node.value : node.value.cooked;
5131
+ if (typeof nodeValue !== "string") return;
5132
+ const cssClasses = nodeValue.split(" ");
5133
+ cssClasses.forEach(cssClass => {
5134
+ const cssProperty = getCssProperty(cssClass);
5135
+ if (!cssProperty) return;
5136
+ const {
5137
+ patterns,
5138
+ message
5139
+ } = TAILWIND_CLASS_PATTERNS[cssProperty];
5140
+ const isPatternMatched = patterns.some(pattern => pattern.test(cssClass));
5141
+ if (!isPatternMatched) return;
5142
+ context.report({
5143
+ node,
5144
+ loc: getLocation({
5145
+ nodeValue,
5146
+ nodeLoc: node.loc,
5147
+ cssClass
5148
+ }),
5149
+ message
5150
+ });
5151
+ });
5152
+ };
5153
+
5154
+ var useNeetouiClasses = {
5155
+ meta: {
5156
+ type: "suggestion",
5157
+ docs: {
5158
+ description: "Warns when tailwind classes are used instead of neetoUI classes"
5159
+ }
5160
+ },
5161
+ create: context => ({
5162
+ Literal(node) {
5163
+ checkAndReportTailwindClasses(context, node);
5164
+ },
5165
+
5166
+ TemplateElement(node) {
5167
+ checkAndReportTailwindClasses(context, node);
5168
+ }
5169
+
5170
+ })
5171
+ };
5172
+
3520
5173
  const SNAKE_CASE_REGEX = /^[a-z0-9_]+$/;
3521
5174
 
3522
5175
  const isSnakeCase = text => SNAKE_CASE_REGEX.test(text);
@@ -3566,22 +5219,12 @@
3566
5219
  const aliases = context.options[0];
3567
5220
  if (ramda.isEmpty(aliases) || ramda.isNil(aliases)) return;
3568
5221
  const importPath = node.source.value;
3569
- let importPathWithAlias = "";
3570
-
3571
- if (importPath.startsWith("../")) {
3572
- const filename = context.getFilename();
3573
- const importFullPath = path__default["default"].resolve(filename, "../", importPath);
3574
- const matches = Object.entries(aliases).filter(([, path]) => importFullPath.startsWith(path)).sort((first, second) => first.length - second.length);
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
-
5222
+ const importFullPath = importPath.startsWith("../") ? path__default["default"].resolve(context.getFilename(), "../", importPath) : importPath;
5223
+ const matches = Object.entries(aliases).filter(([, path]) => importFullPath.startsWith(path) && ["/", undefined].includes(importFullPath.split(path)[1][0])).sort((first, second) => first.length - second.length);
5224
+ if (matches.length === 0) return;
5225
+ const aliasMatch = matches[matches.length - 1];
5226
+ const importPathWithAlias = importFullPath.replace(aliasMatch[1], aliasMatch[0]);
5227
+ if (importPath.length < importPathWithAlias.length) return;
3585
5228
  context.report({
3586
5229
  node,
3587
5230
  message: canBeReplacedWith(importPathWithAlias),
@@ -3609,14 +5252,14 @@
3609
5252
  },
3610
5253
  create: context => ({
3611
5254
  Property(node) {
3612
- var _node$parent, _node$parent$parent, _node$parent$parent$k, _jsconfigData$compile;
5255
+ var _context$options, _context$options$, _node$parent, _node$parent$parent, _node$parent$parent$k, _context$options2, _context$options2$, _jsconfigData$compile;
3613
5256
 
3614
5257
  const filename = context.getFilename();
3615
- const isInsideAliasFile = filename.endsWith(WEBPACK_ALIAS_PATH);
5258
+ 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
5259
  if (!isInsideAliasFile) return;
3617
5260
  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
5261
  if (!isInsideAliasProperty) return;
3619
- const jsconfigData = parseJsconfigData(context.options[0]);
5262
+ 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
5263
  const jsconfigPaths = jsconfigData === null || jsconfigData === void 0 ? void 0 : (_jsconfigData$compile = jsconfigData.compilerOptions) === null || _jsconfigData$compile === void 0 ? void 0 : _jsconfigData$compile.paths;
3621
5264
  if (!jsconfigPaths) return;
3622
5265
  const aliasName = node.key.name;
@@ -3633,10 +5276,12 @@
3633
5276
 
3634
5277
  var index = {
3635
5278
  rules: {
5279
+ "minimize-zustand-store-access-scope": minimizeZustandStoreAccessScope,
3636
5280
  "api-connector-name-should-match-filename": apiConnectorNameShouldMatchFilename,
3637
5281
  "api-connector-should-use-default-export": apiConnectorShouldUseDefaultExport,
3638
5282
  "combine-multiple-independent-awaits": combineMultipleIndependentAwaits,
3639
5283
  "consistent-button-link-anchor": consistentButtonLinkAnchor,
5284
+ "file-name-and-export-name-standards": fileNameAndExportNameStandards,
3640
5285
  "neetocommons-tips": neetocommonsTips,
3641
5286
  "no-blacklisted-imports": noBlacklistedImports,
3642
5287
  "no-axios-import-outside-apis": noAxiosImportOutsideApis,
@@ -3654,9 +5299,10 @@
3654
5299
  "ramda-tips": ramdaTips,
3655
5300
  "routes-should-be-declared-and-default-exported": routesShouldBeDeclaredAndDefaultExported,
3656
5301
  "routes-should-match-object-path": routesShouldMatchObjectPath,
5302
+ "use-array-methods": useArrayMethods,
3657
5303
  "use-axios-config-for-passing-query-parameters": useAxiosConfigForPassingQueryParameters,
3658
- "use-constant-case": useConstantCase,
3659
5304
  "use-common-routes": useCommonRoutes,
5305
+ "use-neetoui-classes": useNeetouiClasses,
3660
5306
  "use-snake-case-for-api-connector-filename": useSnakeCaseForApiConnectorFilename,
3661
5307
  "use-webpack-alias": useWebpackAlias,
3662
5308
  "webpack-aliases-and-jsconfig-paths-should-be-in-sync": webpackAliasesAndJsconfigPathsShouldBeInSync