@bigbinary/eslint-plugin-neeto 1.0.11 → 1.0.12

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 +63 -39
  2. package/dist/index.js +1436 -561
  3. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -2,177 +2,11 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('path'), require('ramda')) :
3
3
  typeof define === 'function' && define.amd ? define(['path', 'ramda'], factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global["@bigbinary/eslint-plugin-neeto"] = factory(global.path, global.ramda));
5
- })(this, (function (path, require$$0) { 'use strict';
5
+ })(this, (function (path, ramda) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
9
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
10
- var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
11
-
12
- const APIS_DIRECTORY = "app/javascript/src/apis";
13
- const BLACKLISTED_PACKAGES = ["moment", "bootstrap", "blueprint", "react-spinners", "react-table", "remixicon", "mjml", "react-select", "antd"];
14
- const TYPES = {
15
- ARRAY_EXPRESSION: "ArrayExpression",
16
- ASSIGNMENT_PATTERN: "AssignmentPattern",
17
- AWAIT_EXPRESSION: "AwaitExpression",
18
- EXPORT_NAMED_DECLARATION: "ExportNamedDeclaration",
19
- IDENTIFIER: "Identifier",
20
- LITERAL: "Literal",
21
- MEMBER_EXPRESSION: "MemberExpression",
22
- OBJECT_EXPRESSION: "ObjectExpression",
23
- OBJECT_PATTERN: "ObjectPattern",
24
- PROGRAM: "Program",
25
- PROPERTY: "Property",
26
- SPREAD_ELEMENT: "SpreadElement",
27
- TEMPLATE_LITERAL: "TemplateLiteral",
28
- VARIABLE_DECLARATOR: "VariableDeclarator",
29
- JSX_ATTRIBUTE: "JSXAttribute",
30
- JSX_ELEMENT: "JSXElement",
31
- JSX_EXPRESSION_CONTAINER: "JSXExpressionContainer"
32
- };
33
-
34
- /**
35
- * @param {Object} context - ESLint context
36
- * @param {Object} node - AST node
37
- * @returns the source code corresponding to the supplied node.
38
- */
39
-
40
- const getCode = (context, node) => context.getSourceCode().text.substr(node.range[0], node.range[1] - node.range[0]);
41
- /**
42
- * Checks if the specified package is imported or not
43
- * using the package name or any alias
44
- * @param {Object} context eslint context
45
- * @returns an array containing the filename and the extension
46
- */
47
-
48
- const getFilenameAndExtension = context => {
49
- const fullFilename = context.getFilename().replace(/.*\//, "");
50
- const splitFilename = fullFilename.split(".");
51
- const extension = splitFilename.pop();
52
- return [splitFilename.join("."), extension];
53
- };
54
- /**
55
- * @param {Object} context eslint context
56
- * @param {string[]} packages list of npm packages to check
57
- * @returns the supplied list of packages and all aliases pointing to
58
- * those packages or their subdirectories.
59
- */
60
-
61
- const getPackagesAndAliases = (context, packages) => Object.entries(context.options[0] ?? {}).reduce((acc, [key, value]) => packages.some(pckg => value === pckg || value.startsWith(`${pckg}/`)) ? require$$0.append(key, acc) : acc, packages);
62
- /**
63
- * Checks if the file is inside the `apis` directory or not
64
- * @param {Object} context eslint context
65
- * @returns true if file is inside the `apis` directory
66
- */
67
-
68
- const isInsideApisDirectory = context => {
69
- const filename = context.getFilename();
70
- const apisDirectory = path__default["default"].resolve(APIS_DIRECTORY);
71
- return filename.startsWith(apisDirectory) && filename !== `${apisDirectory}/axios.js`;
72
- };
73
- /**
74
- * Checks if the specified package is imported or not
75
- * using the package name or any alias
76
- * @param {Object} context eslint context
77
- * @param {Object} node ImportDeclaration node to be checked
78
- * @param {string} packageName name of the package to be checked
79
- * @returns true if the specified package is imported
80
- */
81
-
82
- const isPackageImported = (context, node, packageName) => getPackagesAndAliases(context, [packageName]).includes(node.source.value);
83
-
84
- const ARGUMENT_LIMIT = 3;
85
- const API_ACTIONS_ARGUMENT_LIMIT = 2;
86
- const FIXABLE_PARAMETER_TYPES = [TYPES.IDENTIFIER, TYPES.ASSIGNMENT_PATTERN];
87
-
88
- const canBeReplacedWith = fix => `Can be replaced with: ${fix}`;
89
- const disallowUse = packageName => `Do not use the package ${packageName}`;
90
- const moveToConstantsJs = constantName => `Move the constant ${constantName} to a constants.js file.`;
91
- const renameFile = filename => `Rename this file to ${filename}`;
92
- const replaceWith = fix => `Replace this with: ${fix}`;
93
- const unableToResolveKey = ({
94
- key,
95
- fileName
96
- }) => `Unable to resolve localized string '${key}' in ${fileName}`;
97
- const useConstantCaseFor = constantName => `Use constant-case for naming the constant - ${constantName}.`;
98
- const API_CONNECTOR_SHOULD_USE_DEFAULT_EXPORT_MESSAGE = "API Connector should be exported using the default export method";
99
- const COMBINE_MULTIPLE_INDEPENDENT_AWAITS_MESSAGE = "Combine independent awaits to a single `Promise.all` call.";
100
- const GLOBALPROPS_NO_ASSIGNMENT_MESSAGE = "globalProps should not be assigned to other variables";
101
- const NESTED_GLOBALPROPS_NO_ASSIGNMENT_MESSAGE = "Nested properties of globalProps should not be assigned to other variables";
102
- const NO_AXIOS_IMPORT_OUTSIDE_APIS_MESSAGE = "Do not use axios outside `app/javascript/src/apis`";
103
- const NO_DANGLING_FUNCTIONS_MESSAGE = "Exporting functions from this file is not allowed.";
104
- const NO_EXCESS_API_ACTION_ARGUMENTS_MESSAGE = `API actions should use named parameters for more than ${API_ACTIONS_ARGUMENT_LIMIT} parameters`;
105
- const NO_EXCESS_FUNCTION_ARGUMENTS_MESSAGE = `Functions should use named parameters for more than ${ARGUMENT_LIMIT} parameters`;
106
- const NO_GLOBALPROPS_REASSIGNMENT_MESSAGE = "globalProps or its nested properties should not be re-assigned.";
107
- const NO_NAMESPACE_SPECIFIER_IMPORT_FOR_RAMDA_MESSAGE = 'Use `import { methodsToImport } from "ramda"` instead';
108
- const PREFIX_NEETO_UI_IMPORT_ALIAS_MESSAGE = "Aliases for anything imported from neetoUI or neetoIcons should start with `NeetoUI`";
109
- const USE_AXIOS_CONFIG_FOR_PASSING_QUERY_PARAMETERS_MESSAGE = "Use 'params attribute in axios configuration' to pass query parameters.";
110
-
111
- const toCamelCase = text => {
112
- const capitalized = text.split(/[^0-9a-z]/i).map(part => `${part[0].toUpperCase()}${part.slice(1)}`).join("");
113
- return `${capitalized[0].toLowerCase()}${capitalized.slice(1)}`;
114
- };
115
-
116
- var apiConnectorNameShouldMatchFilename = {
117
- meta: {
118
- type: "problem",
119
- docs: {
120
- description: "API Connector should be named after the filename"
121
- },
122
- fixable: "code"
123
- },
124
- create: context => ({
125
- ExportDefaultDeclaration(node) {
126
- if (!isInsideApisDirectory(context)) return;
127
- const {
128
- declaration
129
- } = node;
130
- const [fileName] = getFilenameAndExtension(context);
131
- const validApiConnectorName = `${toCamelCase(fileName)}Api`;
132
- if (validApiConnectorName === declaration.name) return;
133
- context.report({
134
- node: declaration,
135
- message: replaceWith(validApiConnectorName),
136
- fix: fixer => fixer.replaceText(declaration, validApiConnectorName)
137
- });
138
- }
139
-
140
- })
141
- };
142
-
143
- const checkAndReport$5 = (context, node) => {
144
- if (!isInsideApisDirectory(context)) return;
145
- context.report({
146
- node,
147
- message: API_CONNECTOR_SHOULD_USE_DEFAULT_EXPORT_MESSAGE
148
- });
149
- };
150
-
151
- var apiConnectorShouldUseDefaultExport = {
152
- meta: {
153
- type: "problem",
154
- docs: {
155
- description: "API Connector should be exported using the default export method"
156
- }
157
- },
158
- create: context => ({
159
- ExportNamedDeclaration(node) {
160
- checkAndReport$5(context, node);
161
- },
162
-
163
- ExportDefaultDeclaration(node) {
164
- if (node.declaration.type !== TYPES.OBJECT_EXPRESSION) return;
165
- checkAndReport$5(context, node);
166
- }
167
-
168
- })
169
- };
170
-
171
- var pure = {};
172
-
173
- Object.defineProperty(pure, '__esModule', { value: true });
174
-
175
- var ramda = require$$0__default["default"];
176
10
 
177
11
  function _arrayWithHoles(arr) {
178
12
  if (Array.isArray(arr)) return arr;
@@ -244,104 +78,21 @@
244
78
  return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
245
79
  }, _typeof(obj);
246
80
  }
247
-
248
- var slugify = function slugify(string) {
249
- return string.toString().toLowerCase().replace(/\s+/g, "-") // Replace spaces with -
250
- .replace(/&/g, "-and-") // Replace & with 'and'
251
- .replace(/[^\w-]+/g, "") // Remove all non-word characters
252
- .replace(/--+/g, "-") // Replace multiple - with single -
253
- .replace(/^-+/, "") // Trim - from start of text
254
- .replace(/-+$/, "");
255
- }; // Trim - from end of text
256
-
257
- var humanize = function humanize(string) {
258
- 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();
259
- string = string.charAt(0).toUpperCase() + string.slice(1);
260
- return string;
261
- };
262
- var snakeToCamelCase = function snakeToCamelCase(string) {
263
- return string.replace(/(_\w)/g, function (letter) {
264
- return letter[1].toUpperCase();
265
- });
266
- };
267
- var camelToSnakeCase = function camelToSnakeCase(string) {
268
- return string.replace(/[A-Z]/g, function (letter) {
269
- return "_".concat(letter.toLowerCase());
270
- });
271
- };
272
- var capitalize = function capitalize(string) {
273
- return string.charAt(0).toUpperCase() + string.slice(1);
274
- };
275
- var truncate = function truncate() {
276
- var string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
277
- var length = arguments.length > 1 ? arguments[1] : undefined;
278
- return string.length > length ? ramda.concat(ramda.slice(0, length, string), "...") : string;
279
- };
280
-
281
- var transformObjectDeep = function transformObjectDeep(object, keyValueTransformer) {
282
- if (Array.isArray(object)) {
283
- return object.map(function (obj) {
284
- return transformObjectDeep(obj, keyValueTransformer);
285
- });
286
- } else if (object === null || _typeof(object) !== "object") {
287
- return object;
288
- }
289
-
290
- return Object.fromEntries(Object.entries(object).map(function (_ref) {
291
- var _ref2 = _slicedToArray(_ref, 2),
292
- key = _ref2[0],
293
- value = _ref2[1];
294
-
295
- return keyValueTransformer(key, transformObjectDeep(value, keyValueTransformer));
296
- }));
297
- };
298
- var keysToCamelCase = function keysToCamelCase(object) {
299
- return transformObjectDeep(object, function (key, value) {
300
- return [snakeToCamelCase(key), value];
301
- });
302
- };
303
- var keysToSnakeCase = function keysToSnakeCase(object) {
304
- return transformObjectDeep(object, function (key, value) {
305
- return [camelToSnakeCase(key), value];
306
- });
307
- };
308
- var deepFreezeObject = function deepFreezeObject(object) {
309
- if (object && _typeof(object) === "object" && !Object.isFrozen(object)) {
310
- Object.keys(object).forEach(function (property) {
311
- return deepFreezeObject(object[property]);
312
- });
313
- Object.freeze(object);
314
- }
315
-
316
- return object;
317
- };
318
81
  var matches = ramda.curry(function (pattern, object) {
82
+ var __parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : object;
83
+
319
84
  if (object === pattern) return true;
320
- if (typeof pattern === "function" && pattern(object)) return true;
85
+ if (typeof pattern === "function" && pattern(object, __parent)) return true;
321
86
  if (ramda.isNil(pattern) || ramda.isNil(object)) return false;
322
87
  if (_typeof(pattern) !== "object") return false;
323
- return Object.entries(pattern).every(function (_ref3) {
324
- var _ref4 = _slicedToArray(_ref3, 2),
325
- key = _ref4[0],
326
- value = _ref4[1];
88
+ return Object.entries(pattern).every(function (_ref5) {
89
+ var _ref6 = _slicedToArray(_ref5, 2),
90
+ key = _ref6[0],
91
+ value = _ref6[1];
327
92
 
328
- return matches(value, object[key]);
93
+ return matches(value, object[key], __parent);
329
94
  });
330
95
  });
331
- var filterNonNull = function filterNonNull(object) {
332
- return Object.fromEntries(Object.entries(object).filter(function (_ref5) {
333
- var _ref6 = _slicedToArray(_ref5, 2),
334
- v = _ref6[1];
335
-
336
- return !ramda.isNil(v);
337
- }).map(function (_ref7) {
338
- var _ref8 = _slicedToArray(_ref7, 2),
339
- k = _ref8[0],
340
- v = _ref8[1];
341
-
342
- return [k, _typeof(v) === "object" && !Array.isArray(v) ? filterNonNull(v) : v];
343
- }));
344
- };
345
96
 
346
97
  function _defineProperty(obj, key, value) {
347
98
  if (key in obj) {
@@ -361,71 +112,71 @@
361
112
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
362
113
 
363
114
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
364
- var removeById = ramda.curry(function (id, array) {
115
+ ramda.curry(function (id, array) {
365
116
  return array.filter(function (item) {
366
117
  return item.id !== id;
367
118
  });
368
119
  });
369
- var findById = ramda.curry(function (id, array) {
120
+ ramda.curry(function (id, array) {
370
121
  return array.find(function (item) {
371
122
  return item.id === id;
372
123
  });
373
124
  });
374
- var replaceById = ramda.curry(function (id, newItem, array) {
125
+ ramda.curry(function (id, newItem, array) {
375
126
  return array.map(function (item) {
376
127
  return item.id === id ? newItem : item;
377
128
  });
378
129
  });
379
- var modifyById = ramda.curry(function (id, modifier, array) {
130
+ ramda.curry(function (id, modifier, array) {
380
131
  return array.map(function (item) {
381
132
  return item.id === id ? modifier(item) : item;
382
133
  });
383
134
  });
384
- var findBy = ramda.curry(function (pattern, array) {
135
+ ramda.curry(function (pattern, array) {
385
136
  return array.find(matches(pattern));
386
137
  });
387
- var removeBy = ramda.curry(function (pattern, array) {
138
+ ramda.curry(function (pattern, array) {
388
139
  return array.filter(ramda.complement(matches(pattern)));
389
140
  });
390
- var replaceBy = ramda.curry(function (pattern, newItem, array) {
141
+ ramda.curry(function (pattern, newItem, array) {
391
142
  return array.map(function (item) {
392
143
  return matches(pattern, item) ? newItem : item;
393
144
  });
394
145
  });
395
- var modifyBy = ramda.curry(function (pattern, modifier, array) {
146
+ ramda.curry(function (pattern, modifier, array) {
396
147
  return array.map(function (item) {
397
148
  return matches(pattern, item) ? modifier(item) : item;
398
149
  });
399
150
  });
400
- var existsById = ramda.curry(function (id, array) {
151
+ ramda.curry(function (id, array) {
401
152
  return array.some(function (item) {
402
153
  return item.id === id;
403
154
  });
404
155
  });
405
- var existsBy = ramda.curry(function (pattern, array) {
156
+ var existsBy$1 = ramda.curry(function (pattern, array) {
406
157
  return array.some(matches(pattern));
407
158
  });
408
- var findLastBy = ramda.curry(function (pattern, array) {
159
+ ramda.curry(function (pattern, array) {
409
160
  return ramda.findLast(matches(pattern), array);
410
161
  });
411
- var findIndexById = ramda.curry(function (id, array) {
162
+ ramda.curry(function (id, array) {
412
163
  return array.findIndex(function (item) {
413
164
  return item.id === id;
414
165
  });
415
166
  });
416
- var findIndexBy = ramda.curry(function (pattern, array) {
167
+ ramda.curry(function (pattern, array) {
417
168
  return array.findIndex(matches(pattern));
418
169
  });
419
- var findLastIndexBy = ramda.curry(function (pattern, array) {
170
+ ramda.curry(function (pattern, array) {
420
171
  return ramda.findLastIndex(matches(pattern), array);
421
172
  });
422
- var filterBy = ramda.curry(function (pattern, array) {
173
+ ramda.curry(function (pattern, array) {
423
174
  return array.filter(matches(pattern));
424
175
  });
425
- var countBy = ramda.curry(function (pattern, array) {
176
+ ramda.curry(function (pattern, array) {
426
177
  return ramda.count(matches(pattern), array);
427
178
  });
428
- var copyKeys = ramda.curry(function (keyMap, objectArray) {
179
+ ramda.curry(function (keyMap, objectArray) {
429
180
  return objectArray.map(function (object) {
430
181
  var shallowCopy = _objectSpread({}, object);
431
182
 
@@ -436,7 +187,7 @@
436
187
  return shallowCopy;
437
188
  });
438
189
  });
439
- var renameKeys = ramda.curry(function (keyMap, objectArray) {
190
+ ramda.curry(function (keyMap, objectArray) {
440
191
  return objectArray.map(function (object) {
441
192
  var shallowCopy = _objectSpread({}, object);
442
193
 
@@ -448,7 +199,7 @@
448
199
  return shallowCopy;
449
200
  });
450
201
  });
451
- var copyKeysDeep = ramda.curry(function (keyMap, objectArray) {
202
+ ramda.curry(function (keyMap, objectArray) {
452
203
  var copyKeysSingleObject = function copyKeysSingleObject(object, keyMap) {
453
204
  var root = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : object;
454
205
  return _objectSpread(_objectSpread({}, object), ramda.fromPairs(ramda.toPairs(keyMap).map(function (_ref) {
@@ -472,121 +223,243 @@
472
223
  return copyKeysSingleObject(object, keyMap);
473
224
  });
474
225
  });
475
-
476
- var noop = function noop() {};
477
- var toLabelAndValue = function toLabelAndValue(string) {
478
- return {
479
- label: string,
480
- value: string
481
- };
482
- };
483
- var getRandomInt = function getRandomInt() {
484
- var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Number.MAX_SAFE_INTEGER;
485
- var b = arguments.length > 1 ? arguments[1] : undefined;
486
-
487
- if (b) {
488
- a = Math.ceil(a);
489
- b = Math.floor(b);
490
- } else {
491
- b = a;
492
- a = 0;
493
- }
494
-
495
- return Math.floor(Math.random() * (b - a) + a);
496
- };
497
- var randomPick = function randomPick() {
498
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
499
- args[_key] = arguments[_key];
500
- }
501
-
502
- var randomNumber = getRandomInt(0, args.length);
503
- return args[randomNumber];
504
- };
505
- var dynamicArray = function dynamicArray(count, elementGenerator) {
506
- return Array.from({
507
- length: count
508
- }, function (_, index) {
509
- return elementGenerator(index);
510
- });
511
- };
512
- var isNotNil = ramda.complement(ramda.isNil);
513
- var isNotEmpty = ramda.complement(ramda.isEmpty);
514
- var notEquals = ramda.curry(function (x, y) {
226
+ ramda.complement(ramda.isNil);
227
+ ramda.complement(ramda.isEmpty);
228
+ ramda.curry(function (x, y) {
515
229
  return x !== y;
516
230
  });
517
- var isNot = notEquals;
518
- var notEqualsDeep = ramda.complement(ramda.equals);
519
- var isNotEqualDeep = notEqualsDeep;
520
-
521
- pure.camelToSnakeCase = camelToSnakeCase;
522
- pure.capitalize = capitalize;
523
- pure.copyKeys = copyKeys;
524
- pure.copyKeysDeep = copyKeysDeep;
525
- pure.countBy = countBy;
526
- pure.deepFreezeObject = deepFreezeObject;
527
- pure.dynamicArray = dynamicArray;
528
- pure.existsBy = existsBy;
529
- pure.existsById = existsById;
530
- pure.filterBy = filterBy;
531
- pure.filterNonNull = filterNonNull;
532
- pure.findBy = findBy;
533
- pure.findById = findById;
534
- pure.findIndexBy = findIndexBy;
535
- pure.findIndexById = findIndexById;
536
- pure.findLastBy = findLastBy;
537
- pure.findLastIndexBy = findLastIndexBy;
538
- pure.getRandomInt = getRandomInt;
539
- pure.humanize = humanize;
540
- pure.isNot = isNot;
541
- pure.isNotEmpty = isNotEmpty;
542
- pure.isNotEqualDeep = isNotEqualDeep;
543
- pure.isNotNil = isNotNil;
544
- pure.keysToCamelCase = keysToCamelCase;
545
- pure.keysToSnakeCase = keysToSnakeCase;
546
- var matches_1 = pure.matches = matches;
547
- pure.modifyBy = modifyBy;
548
- pure.modifyById = modifyById;
549
- pure.noop = noop;
550
- pure.notEquals = notEquals;
551
- pure.notEqualsDeep = notEqualsDeep;
552
- pure.randomPick = randomPick;
553
- pure.removeBy = removeBy;
554
- pure.removeById = removeById;
555
- pure.renameKeys = renameKeys;
556
- pure.replaceBy = replaceBy;
557
- pure.replaceById = replaceById;
558
- pure.slugify = slugify;
559
- pure.snakeToCamelCase = snakeToCamelCase;
560
- pure.toLabelAndValue = toLabelAndValue;
561
- pure.transformObjectDeep = transformObjectDeep;
562
- pure.truncate = truncate;
563
-
564
- /**
565
- * Returns a list of nodes that matches the pattern
566
- * somewhere deep inside the given object-tree by
567
- * partial object matching.
568
- *
569
- * @param {Object} obj the object tree to check
570
- * @param {Object} pattern the pattern to match partially
571
- * @param {Array} res list of nodes that matches the pattern
572
- */
231
+ ramda.complement(ramda.equals);
573
232
 
574
- const findMatchingNodesDeep = (obj, pattern, res = []) => {
575
- if (typeof obj !== "object" || require$$0.isNil(obj)) return res;
576
- if (matches_1(pattern, obj)) return require$$0.append(obj, res);
577
- return Object.entries(obj).reduce((acc, [key, value]) => {
578
- if (key === "parent") return acc;
579
- return findMatchingNodesDeep(value, pattern, acc);
580
- }, res);
233
+ const APIS_DIRECTORY = "app/javascript/src/apis";
234
+ const BLACKLISTED_PACKAGES = ["moment", "bootstrap", "blueprint", "react-spinners", "react-table", "remixicon", "mjml", "react-select", "antd"];
235
+ const TYPES = {
236
+ ARRAY_EXPRESSION: "ArrayExpression",
237
+ ARROW_FUNCTION_EXPRESSION: "ArrowFunctionExpression",
238
+ ASSIGNMENT_PATTERN: "AssignmentPattern",
239
+ AWAIT_EXPRESSION: "AwaitExpression",
240
+ BINARY_EXPRESSION: "BinaryExpression",
241
+ CALL_EXPRESSION: "CallExpression",
242
+ EXPORT_NAMED_DECLARATION: "ExportNamedDeclaration",
243
+ IDENTIFIER: "Identifier",
244
+ IF_STATEMENT: "IfStatement",
245
+ LITERAL: "Literal",
246
+ LOGICAL_EXPRESSION: "LogicalExpression",
247
+ MEMBER_EXPRESSION: "MemberExpression",
248
+ OBJECT_EXPRESSION: "ObjectExpression",
249
+ OBJECT_PATTERN: "ObjectPattern",
250
+ PROGRAM: "Program",
251
+ PROPERTY: "Property",
252
+ SPREAD_ELEMENT: "SpreadElement",
253
+ TEMPLATE_LITERAL: "TemplateLiteral",
254
+ UNARY_EXPRESSION: "UnaryExpression",
255
+ VARIABLE_DECLARATOR: "VariableDeclarator",
256
+ WHILE_STATEMENT: "WhileStatement",
257
+ JSX_ATTRIBUTE: "JSXAttribute",
258
+ JSX_ELEMENT: "JSXElement",
259
+ JSX_EXPRESSION_CONTAINER: "JSXExpressionContainer"
260
+ };
261
+ const IMPORT_DECLARATION = {
262
+ type: "ImportDeclaration",
263
+ source: {
264
+ type: "Literal"
265
+ },
266
+ specifiers: [{
267
+ type: "ImportSpecifier"
268
+ }]
581
269
  };
270
+
582
271
  /**
583
- * Checks if any of the given pattern matches the object.
584
- * @param {Object} obj The object tree to check.
585
- * @param {Object[]} list The list of patterns to compare against.
586
- * also @see matches
272
+ * @param {Object} context - ESLint context
273
+ * @param {Object} node - AST node
274
+ * @returns the source code corresponding to the supplied node.
587
275
  */
588
276
 
589
- const matchesAny = require$$0.curry((obj, list) => list.some(matches_1(require$$0.__, obj)));
277
+ const getCode = (context, node) => context.getSourceCode().text.substr(node.range[0], node.range[1] - node.range[0]);
278
+ /**
279
+ * Checks if the specified package is imported or not
280
+ * using the package name or any alias
281
+ * @param {Object} context eslint context
282
+ * @returns an array containing the filename and the extension
283
+ */
284
+
285
+ const getFilenameAndExtension = context => {
286
+ const fullFilename = context.getFilename().replace(/.*\//, "");
287
+ const splitFilename = fullFilename.split(".");
288
+ const extension = splitFilename.pop();
289
+ return [splitFilename.join("."), extension];
290
+ };
291
+ /**
292
+ * @param {Object} context eslint context
293
+ * @param {string[]} packages list of npm packages to check
294
+ * @returns the supplied list of packages and all aliases pointing to
295
+ * those packages or their subdirectories.
296
+ */
297
+
298
+ const getPackagesAndAliases = (context, packages) => Object.entries(context.options[0] ?? {}).reduce((acc, [key, value]) => packages.some(pckg => value === pckg || value.startsWith(`${pckg}/`)) ? ramda.append(key, acc) : acc, packages);
299
+ /**
300
+ * Checks if the file is inside the `apis` directory or not
301
+ * @param {Object} context eslint context
302
+ * @returns true if file is inside the `apis` directory
303
+ */
304
+
305
+ const isInsideApisDirectory = context => {
306
+ const filename = context.getFilename();
307
+ const apisDirectory = path__default["default"].resolve(APIS_DIRECTORY);
308
+ return filename.startsWith(apisDirectory) && filename !== `${apisDirectory}/axios.js`;
309
+ };
310
+ /**
311
+ * Checks if the specified package is imported or not
312
+ * using the package name or any alias
313
+ * @param {Object} context eslint context
314
+ * @param {Object} node ImportDeclaration node to be checked
315
+ * @param {string} packageName name of the package to be checked
316
+ * @returns true if the specified package is imported
317
+ */
318
+
319
+ const isPackageImported = (context, node, packageName) => getPackagesAndAliases(context, [packageName]).includes(node.source.value);
320
+ const nodeReplacerWithImports = importPattern => {
321
+ const addFunctionImport = (context, fixer, functions) => {
322
+ const root = context.getAncestors()[0];
323
+ const packageImport = root.body.find(node => matches(importPattern, node));
324
+
325
+ if (packageImport) {
326
+ const extraImports = functions.filter(func => !packageImport.specifiers.some(ramda.pathEq(["imported", "name"], func)));
327
+ if (ramda.isEmpty(extraImports)) return undefined;
328
+ return fixer.insertTextBefore(packageImport.specifiers[0], `${extraImports.join(", ")}, `);
329
+ }
330
+
331
+ const packageName = importPattern.source.value;
332
+ return fixer.insertTextBefore(root.body[0], `import { ${functions.join(", ")} } from "${packageName}";\n`);
333
+ };
334
+
335
+ return {
336
+ replaceNode: ({
337
+ context,
338
+ node,
339
+ fix,
340
+ functions
341
+ }) => function* (fixer) {
342
+ const imports = addFunctionImport(context, fixer, Array.isArray(functions) ? functions : [functions]);
343
+ if (imports) yield imports;
344
+ yield fixer.replaceText(node, fix);
345
+ }
346
+ };
347
+ };
348
+ const arrayFuncParam = root => root.arguments[0].params[0];
349
+
350
+ const ARGUMENT_LIMIT = 3;
351
+ const API_ACTIONS_ARGUMENT_LIMIT = 2;
352
+ const FIXABLE_PARAMETER_TYPES = [TYPES.IDENTIFIER, TYPES.ASSIGNMENT_PATTERN];
353
+
354
+ const canBeReplacedWith = fix => `Can be replaced with: ${fix}`;
355
+ const disallowUse = packageName => `Do not use the package ${packageName}`;
356
+ const moveToConstantsJs = constantName => `Move the constant ${constantName} to a constants.js file.`;
357
+ const renameFile = filename => `Rename this file to ${filename}`;
358
+ const replaceWith = fix => `Replace this with: ${fix}`;
359
+ const unableToResolveKey = ({
360
+ key,
361
+ fileName
362
+ }) => `Unable to resolve localized string '${key}' in ${fileName}`;
363
+ const useConstantCaseFor = constantName => `Use constant-case for naming the constant - ${constantName}.`;
364
+ const API_CONNECTOR_SHOULD_USE_DEFAULT_EXPORT_MESSAGE = "API Connector should be exported using the default export method";
365
+ const COMBINE_MULTIPLE_INDEPENDENT_AWAITS_MESSAGE = "Combine independent awaits to a single `Promise.all` call.";
366
+ const GLOBALPROPS_NO_ASSIGNMENT_MESSAGE = "globalProps should not be assigned to other variables";
367
+ const NESTED_GLOBALPROPS_NO_ASSIGNMENT_MESSAGE = "Nested properties of globalProps should not be assigned to other variables";
368
+ const NO_AXIOS_IMPORT_OUTSIDE_APIS_MESSAGE = "Do not use axios outside `app/javascript/src/apis`";
369
+ const NO_DANGLING_FUNCTIONS_MESSAGE = "Exporting functions from this file is not allowed.";
370
+ const NO_EXCESS_API_ACTION_ARGUMENTS_MESSAGE = `API actions should use named parameters for more than ${API_ACTIONS_ARGUMENT_LIMIT} parameters`;
371
+ const NO_EXCESS_FUNCTION_ARGUMENTS_MESSAGE = `Functions should use named parameters for more than ${ARGUMENT_LIMIT} parameters`;
372
+ const NO_GLOBALPROPS_REASSIGNMENT_MESSAGE = "globalProps or its nested properties should not be re-assigned.";
373
+ const NO_NAMESPACE_SPECIFIER_IMPORT_FOR_RAMDA_MESSAGE = 'Use `import { methodsToImport } from "ramda"` instead';
374
+ const PREFIX_NEETO_UI_IMPORT_ALIAS_MESSAGE = "Aliases for anything imported from neetoUI or neetoIcons should start with `NeetoUI`";
375
+ const USE_AXIOS_CONFIG_FOR_PASSING_QUERY_PARAMETERS_MESSAGE = "Use 'params attribute in axios configuration' to pass query parameters.";
376
+
377
+ const toCamelCase = text => {
378
+ const capitalized = text.split(/[^0-9a-z]/i).map(part => `${part[0].toUpperCase()}${part.slice(1)}`).join("");
379
+ return `${capitalized[0].toLowerCase()}${capitalized.slice(1)}`;
380
+ };
381
+
382
+ var apiConnectorNameShouldMatchFilename = {
383
+ meta: {
384
+ type: "problem",
385
+ docs: {
386
+ description: "API Connector should be named after the filename"
387
+ },
388
+ fixable: "code"
389
+ },
390
+ create: context => ({
391
+ ExportDefaultDeclaration(node) {
392
+ if (!isInsideApisDirectory(context)) return;
393
+ const {
394
+ declaration
395
+ } = node;
396
+ const [fileName] = getFilenameAndExtension(context);
397
+ const validApiConnectorName = `${toCamelCase(fileName)}Api`;
398
+ if (validApiConnectorName === declaration.name) return;
399
+ context.report({
400
+ node: declaration,
401
+ message: replaceWith(validApiConnectorName),
402
+ fix: fixer => fixer.replaceText(declaration, validApiConnectorName)
403
+ });
404
+ }
405
+
406
+ })
407
+ };
408
+
409
+ const checkAndReport$5 = (context, node) => {
410
+ if (!isInsideApisDirectory(context)) return;
411
+ context.report({
412
+ node,
413
+ message: API_CONNECTOR_SHOULD_USE_DEFAULT_EXPORT_MESSAGE
414
+ });
415
+ };
416
+
417
+ var apiConnectorShouldUseDefaultExport = {
418
+ meta: {
419
+ type: "problem",
420
+ docs: {
421
+ description: "API Connector should be exported using the default export method"
422
+ }
423
+ },
424
+ create: context => ({
425
+ ExportNamedDeclaration(node) {
426
+ checkAndReport$5(context, node);
427
+ },
428
+
429
+ ExportDefaultDeclaration(node) {
430
+ if (node.declaration.type !== TYPES.OBJECT_EXPRESSION) return;
431
+ checkAndReport$5(context, node);
432
+ }
433
+
434
+ })
435
+ };
436
+
437
+ /**
438
+ * Returns a list of nodes that matches the pattern
439
+ * somewhere deep inside the given object-tree by
440
+ * partial object matching.
441
+ *
442
+ * @param {Object} obj the object tree to check
443
+ * @param {Object} pattern the pattern to match partially
444
+ * @param {Array} res list of nodes that matches the pattern
445
+ */
446
+
447
+ const findMatchingNodesDeep = (obj, pattern, res = []) => {
448
+ if (typeof obj !== "object" || ramda.isNil(obj)) return res;
449
+ if (matches(pattern, obj)) return ramda.append(obj, res);
450
+ return Object.entries(obj).reduce((acc, [key, value]) => {
451
+ if (key === "parent") return acc;
452
+ return findMatchingNodesDeep(value, pattern, acc);
453
+ }, res);
454
+ };
455
+ /**
456
+ * Checks if any of the given pattern matches the object.
457
+ * @param {Object} obj The object tree to check.
458
+ * @param {Object[]} list The list of patterns to compare against.
459
+ * also @see matches
460
+ */
461
+
462
+ const matchesAny = ramda.curry((list, obj) => list.some(matches(ramda.__, obj)));
590
463
  /**
591
464
  * Checks if the given pattern exists somewhere deep inside
592
465
  * the given object-tree by partial object matching.
@@ -596,8 +469,8 @@
596
469
  */
597
470
 
598
471
  const patternExistsDeep = (obj, pattern) => {
599
- if (typeof obj !== "object" || require$$0.isNil(obj)) return false;
600
- if (matches_1(pattern, obj)) return true;
472
+ if (typeof obj !== "object" || ramda.isNil(obj)) return false;
473
+ if (matches(pattern, obj)) return true;
601
474
  return Object.entries(obj).some(([key, value]) => {
602
475
  if (key === "parent") return false;
603
476
  return patternExistsDeep(value, pattern);
@@ -620,7 +493,7 @@
620
493
  return ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : (_node$parent$right = _node$parent.right) === null || _node$parent$right === void 0 ? void 0 : _node$parent$right.name) === node.name;
621
494
  };
622
495
 
623
- const getChildCode = (context, nodes, pathArray) => nodes.map(node => getCode(context, require$$0.path(pathArray, node))).join(", ");
496
+ const getChildCode = (context, nodes, pathArray) => nodes.map(node => getCode(context, ramda.path(pathArray, node))).join(", ");
624
497
  const getIdentifiersInNode = node => findMatchingNodesDeep(node, IDENTIFIER_PATTERN).filter(node => !(isKeyNode(node) || isDefaultValueNode(node) || node.parent.computed)); // id from const { id : orgID } = ...
625
498
 
626
499
  const isKeyNode = node => {
@@ -634,9 +507,9 @@
634
507
 
635
508
  if (subsequentAwaits.length === 0) return false;
636
509
  const currentNodeIndex = functionBody.findIndex(item => item === awaitParent);
637
- const isPrevLineSameAsLastAwait = functionBody[currentNodeIndex - 1] === ((_last = require$$0.last(subsequentAwaits)) === null || _last === void 0 ? void 0 : _last.parent); // In case of const a = await xf(), b = await yf()
510
+ const isPrevLineSameAsLastAwait = functionBody[currentNodeIndex - 1] === ((_last = ramda.last(subsequentAwaits)) === null || _last === void 0 ? void 0 : _last.parent); // In case of const a = await xf(), b = await yf()
638
511
 
639
- const areBothAwaitsInSameLine = functionBody[currentNodeIndex] === ((_last2 = require$$0.last(subsequentAwaits)) === null || _last2 === void 0 ? void 0 : _last2.parent);
512
+ const areBothAwaitsInSameLine = functionBody[currentNodeIndex] === ((_last2 = ramda.last(subsequentAwaits)) === null || _last2 === void 0 ? void 0 : _last2.parent);
640
513
  return isPrevLineSameAsLastAwait || areBothAwaitsInSameLine;
641
514
  };
642
515
 
@@ -678,11 +551,11 @@
678
551
  const calls = getChildCode(context, nodes, ["init", "argument"]);
679
552
  const ids = getChildCode(context, nodes, ["id"]);
680
553
  const fix = `[${ids}] = await Promise.all([${calls}])`;
681
- const fixRange = [nodes[0].range[0], require$$0.last(nodes).range[1]];
554
+ const fixRange = [nodes[0].range[0], ramda.last(nodes).range[1]];
682
555
  context.report({
683
556
  loc: {
684
557
  start: nodes[0].parent.loc.start,
685
- end: require$$0.last(nodes).loc.end
558
+ end: ramda.last(nodes).loc.end
686
559
  },
687
560
  message: COMBINE_MULTIPLE_INDEPENDENT_AWAITS_MESSAGE,
688
561
  fix: fixer => fixer.replaceTextRange(fixRange, fix)
@@ -749,7 +622,7 @@
749
622
  })
750
623
  };
751
624
 
752
- const isDefinedInFile = (node, levels) => [TYPES.PROGRAM, TYPES.EXPORT_NAMED_DECLARATION].includes(require$$0.path(require$$0.repeat("parent", levels), node).type);
625
+ const isDefinedInFile = (node, levels) => [TYPES.PROGRAM, TYPES.EXPORT_NAMED_DECLARATION].includes(ramda.path(ramda.repeat("parent", levels), node).type);
753
626
 
754
627
  const checkAndReport$3 = (context, node, levels = 3) => {
755
628
  if (!(isConstantsFile(context) && isDefinedInFile(node, levels))) return;
@@ -825,144 +698,1062 @@
825
698
  fix: fixer => {
826
699
  const newName = toConstantCase(exported.name);
827
700
 
828
- if (local.name === exported.name) {
829
- return fixer.replaceText(statement, newName);
830
- }
701
+ if (local.name === exported.name) {
702
+ return fixer.replaceText(statement, newName);
703
+ }
704
+
705
+ if (local.name === newName) {
706
+ return fixer.replaceText(statement, local.name);
707
+ }
708
+
709
+ return fixer.replaceText(exported, newName);
710
+ }
711
+ }]
712
+ });
713
+ };
714
+
715
+ var useConstantCase = {
716
+ meta: {
717
+ type: "suggestion",
718
+ docs: {
719
+ description: "Enforces constants in constants.js file to be named using constant-case."
720
+ },
721
+ hasSuggestions: true
722
+ },
723
+ create: context => ({
724
+ ExportNamedDeclaration(node) {
725
+ var _node$declaration;
726
+
727
+ if (!isConstantsFile(context)) return;
728
+
729
+ if (((_node$declaration = node.declaration) === null || _node$declaration === void 0 ? void 0 : _node$declaration.kind) === "const") {
730
+ var _node$declaration2;
731
+
732
+ (_node$declaration2 = node.declaration) === null || _node$declaration2 === void 0 ? void 0 : _node$declaration2.declarations.forEach(({
733
+ id
734
+ }) => {
735
+ if (id.type !== TYPES.OBJECT_PATTERN) {
736
+ checkCaseAndReport({
737
+ context,
738
+ name: id.name,
739
+ node: id
740
+ });
741
+ return;
742
+ }
743
+
744
+ id.properties.forEach(statement => {
745
+ checkExportAndReport({
746
+ context,
747
+ exported: statement.value,
748
+ local: statement.key,
749
+ node,
750
+ statement
751
+ });
752
+ });
753
+ });
754
+ } else {
755
+ node.specifiers.forEach(statement => {
756
+ const {
757
+ exported,
758
+ local
759
+ } = statement;
760
+ checkExportAndReport({
761
+ context,
762
+ exported,
763
+ local,
764
+ node,
765
+ statement
766
+ });
767
+ });
768
+ }
769
+ }
770
+
771
+ })
772
+ };
773
+
774
+ const ASSIGNMENT_PATTERNS = [{
775
+ id: {
776
+ type: "ObjectPattern"
777
+ }
778
+ }, {
779
+ id: {
780
+ type: "Identifier"
781
+ }
782
+ }];
783
+ const IDENTIFIER_INITIALIZATION_PATTERN = {
784
+ type: "Identifier",
785
+ name: "globalProps"
786
+ };
787
+ const MEMBER_EXPRESSION_INITIALIZATION_PATTERN = {
788
+ type: "MemberExpression",
789
+ object: {
790
+ type: "Identifier",
791
+ name: "globalProps"
792
+ }
793
+ };
794
+ const GLOBALPROPS_REASSIGNMENT_PATTERN = {
795
+ type: "Identifier",
796
+ name: "globalProps"
797
+ };
798
+
799
+ const checkAssignment = (context, node) => {
800
+ if (matches(IDENTIFIER_INITIALIZATION_PATTERN, node)) {
801
+ context.report(node, GLOBALPROPS_NO_ASSIGNMENT_MESSAGE);
802
+ } else if (matches(MEMBER_EXPRESSION_INITIALIZATION_PATTERN, node)) {
803
+ context.report(node, NESTED_GLOBALPROPS_NO_ASSIGNMENT_MESSAGE);
804
+ }
805
+ };
806
+
807
+ var noGlobalPropsDestructure = {
808
+ meta: {
809
+ type: "problem",
810
+ docs: {
811
+ description: "Disallows destructuring of globalProps."
812
+ }
813
+ },
814
+ create: context => ({
815
+ VariableDeclarator(node) {
816
+ if (!matchesAny(ASSIGNMENT_PATTERNS, node)) return;
817
+ checkAssignment(context, node.init);
818
+ },
819
+
820
+ AssignmentExpression: node => checkAssignment(context, node.right)
821
+ })
822
+ };
823
+
824
+ var noGlobalPropsReassignment = {
825
+ meta: {
826
+ type: "problem",
827
+ docs: {
828
+ description: "Disallows re-assignment of globalProps."
829
+ }
830
+ },
831
+ create: context => ({
832
+ AssignmentExpression(node) {
833
+ if (patternExistsDeep(node.left, GLOBALPROPS_REASSIGNMENT_PATTERN)) {
834
+ context.report(node, NO_GLOBALPROPS_REASSIGNMENT_MESSAGE);
835
+ }
836
+ }
837
+
838
+ })
839
+ };
840
+
841
+ const reportSuggestion = ({
842
+ context,
843
+ node,
844
+ fix,
845
+ func,
846
+ message = ""
847
+ }) => context.report({
848
+ node,
849
+ message: message || canBeReplacedWith(fix),
850
+ suggest: [{
851
+ desc: `Replace with ${fix}`,
852
+ fix: replacer$1.replaceNode({
853
+ context,
854
+ node,
855
+ fix,
856
+ functions: func
857
+ })
858
+ }]
859
+ });
860
+ const replacer$1 = nodeReplacerWithImports(ramda.assocPath(["source", "value"], "neetocommons/pure", IMPORT_DECLARATION)); // checks the given logical/binary expression uses only the parameters of the function for comparison
861
+ // (a) => a.x === 1;
862
+ // (a) => a.x === b.x && a.y === 100; // allowed
863
+ // (a) => a.x.y === 1; // not allowed
864
+
865
+ const areAllChecksWithParams = (expression, param, operators) => {
866
+ const isBinaryExpressionValid = pattern => {
867
+ const binaryExpressionPattern = {
868
+ type: TYPES.BINARY_EXPRESSION,
869
+ operator: operators.compare // ===, !==
870
+
871
+ };
872
+ return matches(binaryExpressionPattern, expression) && (matches(pattern, expression.left) || matches(pattern, expression.right));
873
+ };
874
+
875
+ const logicalExpressionPattern = {
876
+ type: TYPES.LOGICAL_EXPRESSION,
877
+ operator: operators.join
878
+ };
879
+
880
+ if (matches(logicalExpressionPattern, expression)) {
881
+ return areAllChecksWithParams(expression.left, param, operators) && areAllChecksWithParams(expression.right, param, operators);
882
+ } else if (param.type === TYPES.IDENTIFIER) {
883
+ const expressionPattern = {
884
+ type: TYPES.MEMBER_EXPRESSION,
885
+ object: {
886
+ name: param.name
887
+ }
888
+ };
889
+ if (isBinaryExpressionValid(expressionPattern)) return true;
890
+ } else if (param.type === TYPES.OBJECT_PATTERN) {
891
+ const identifierPattern = {
892
+ type: TYPES.IDENTIFIER,
893
+ name: name => existsBy$1({
894
+ value: {
895
+ name
896
+ }
897
+ }, param.properties)
898
+ };
899
+ if (isBinaryExpressionValid(identifierPattern)) return true;
900
+ }
901
+
902
+ return false;
903
+ };
904
+ const canBeShortenedWithCommons = replacement => `It may be possible to shorten this code using ${replacement} from neetocommons/pure`;
905
+
906
+ const NOT_NIL_BINARY_EXP_PATTERN = {
907
+ type: TYPES.BINARY_EXPRESSION,
908
+ operator: "!==",
909
+ right: matchesAny([{
910
+ type: TYPES.LITERAL,
911
+ value: null
912
+ }, {
913
+ type: TYPES.IDENTIFIER,
914
+ name: "undefined"
915
+ }])
916
+ };
917
+ const NOT_EQUALS_DEEP_CALL_EXP_PATTERN = {
918
+ type: TYPES.CALL_EXPRESSION,
919
+ callee: {
920
+ type: TYPES.MEMBER_EXPRESSION,
921
+ object: {
922
+ type: TYPES.IDENTIFIER,
923
+ name: "JSON"
924
+ },
925
+ property: {
926
+ type: TYPES.IDENTIFIER,
927
+ name: "stringify"
928
+ }
929
+ }
930
+ };
931
+ const OBJ_KEY_LENGTH_PATTERN$1 = {
932
+ type: TYPES.MEMBER_EXPRESSION,
933
+ object: {
934
+ type: TYPES.CALL_EXPRESSION,
935
+ callee: {
936
+ type: TYPES.MEMBER_EXPRESSION,
937
+ object: {
938
+ type: TYPES.IDENTIFIER,
939
+ name: "Object"
940
+ }
941
+ },
942
+ property: {
943
+ type: TYPES.IDENTIFIER,
944
+ name: "keys"
945
+ }
946
+ },
947
+ property: {
948
+ type: TYPES.IDENTIFIER,
949
+ name: "length"
950
+ }
951
+ };
952
+ const ARRAY_LENGTH_PATTERN$1 = {
953
+ type: TYPES.MEMBER_EXPRESSION,
954
+ property: {
955
+ type: TYPES.IDENTIFIER,
956
+ name: "length"
957
+ }
958
+ };
959
+ const NOOP_PATTERN = {
960
+ generator: false,
961
+ async: false,
962
+ expression: false,
963
+ body: {
964
+ type: "BlockStatement",
965
+ body: body => ramda.isEmpty(body)
966
+ }
967
+ };
968
+ const LABEL_AND_VALUE_PATTERN = {
969
+ properties: props => props.length === 2 && props.every(matches({
970
+ type: "Property",
971
+ computed: false,
972
+ key: {
973
+ type: "Identifier"
974
+ },
975
+ value: {
976
+ type: ramda.includes(ramda.__, ["Literal", "Identifier", "MemberExpression"])
977
+ }
978
+ })) && ramda.equals(["label", "value"], props.map(ramda.path(["key", "name"])).sort())
979
+ };
980
+ const DYNAMIC_ARRAY_PATTERN = {
981
+ callee: {
982
+ type: "MemberExpression",
983
+ object: {
984
+ type: "Identifier",
985
+ name: "Array"
986
+ },
987
+ property: {
988
+ type: "Identifier",
989
+ name: "from"
990
+ }
991
+ },
992
+ arguments: args => args.length === 2 && matches({
993
+ 0: {
994
+ type: "ObjectExpression",
995
+ properties: props => props.length === 1 && props[0].key.name === "length"
996
+ },
997
+ 1: {
998
+ type: "ArrowFunctionExpression"
999
+ }
1000
+ }, args)
1001
+ };
1002
+ const NOT_NIL_PATTERNS = [// x !== null && x !== undefined
1003
+ {
1004
+ type: TYPES.LOGICAL_EXPRESSION,
1005
+ operator: "&&",
1006
+ left: NOT_NIL_BINARY_EXP_PATTERN,
1007
+ right: NOT_NIL_BINARY_EXP_PATTERN
1008
+ }, // x => !isNil(x)
1009
+ {
1010
+ type: TYPES.ARROW_FUNCTION_EXPRESSION,
1011
+ params: params => params.length === 1 && params[0].type === TYPES.IDENTIFIER,
1012
+ body: {
1013
+ type: TYPES.UNARY_EXPRESSION,
1014
+ operator: "!",
1015
+ prefix: true,
1016
+ argument: {
1017
+ type: TYPES.CALL_EXPRESSION,
1018
+ callee: {
1019
+ type: TYPES.IDENTIFIER,
1020
+ name: "isNil"
1021
+ },
1022
+ arguments: args => args.length === 1 && args[0].type === TYPES.IDENTIFIER
1023
+ }
1024
+ }
1025
+ }];
1026
+ const NOT_EMPTY_PATTERNS = {
1027
+ /*
1028
+ array.length !== 0, array.length > 0, Object.keys(obj).length !== 0, Object.keys(obj).length > 0 ,
1029
+ if(array.length !== 0), while(Object.keys(obj).length > 0) etc
1030
+ */
1031
+ BINARY_EXP: {
1032
+ type: TYPES.BINARY_EXPRESSION,
1033
+ operator: opr => opr === "!==" || opr === ">",
1034
+ left: matchesAny([ARRAY_LENGTH_PATTERN$1, OBJ_KEY_LENGTH_PATTERN$1]),
1035
+ right: {
1036
+ type: TYPES.LITERAL,
1037
+ value: 0
1038
+ }
1039
+ },
1040
+ // if(array.length), if(Object.keys(obj).length), while(array.length), while(Object.keys(obj).length)
1041
+ CONDT_STAT: {
1042
+ type: matchesAny([TYPES.IF_STATEMENT, TYPES.WHILE_STATEMENT]),
1043
+ test: matchesAny([ARRAY_LENGTH_PATTERN$1, OBJ_KEY_LENGTH_PATTERN$1])
1044
+ },
1045
+ // x => !isEmpty(x)
1046
+ ARROW_FUNC: {
1047
+ type: TYPES.ARROW_FUNCTION_EXPRESSION,
1048
+ params: params => params.length === 1 && params[0].type === TYPES.IDENTIFIER,
1049
+ body: {
1050
+ type: TYPES.UNARY_EXPRESSION,
1051
+ operator: "!",
1052
+ prefix: true,
1053
+ argument: {
1054
+ type: TYPES.CALL_EXPRESSION,
1055
+ callee: {
1056
+ type: TYPES.IDENTIFIER,
1057
+ name: "isEmpty"
1058
+ },
1059
+ arguments: (args, root) => args.length === 1 && args[0].type === TYPES.IDENTIFIER && args[0].name === root.params[0].name
1060
+ }
1061
+ }
1062
+ }
1063
+ };
1064
+ const REPLACE_BY_PATTERN = {
1065
+ callee: {
1066
+ type: "MemberExpression",
1067
+ property: {
1068
+ type: "Identifier",
1069
+ name: "map"
1070
+ }
1071
+ },
1072
+ arguments: [{
1073
+ type: "ArrowFunctionExpression",
1074
+ generator: false,
1075
+ async: false,
1076
+ expression: true,
1077
+ params: params => params.length === 1 && params[0].type === "Identifier",
1078
+ body: {
1079
+ type: "ConditionalExpression",
1080
+ test: (test, root) => areAllChecksWithParams(test, arrayFuncParam(root), {
1081
+ compare: "===",
1082
+ join: "&&"
1083
+ }),
1084
+ alternate: {
1085
+ type: "Identifier",
1086
+ name: (name, root) => name === arrayFuncParam(root).name
1087
+ }
1088
+ }
1089
+ }]
1090
+ };
1091
+ const REPLACE_BY_NEGATED_PATTERN = ramda.assocPath(["arguments", 0, "body"], {
1092
+ type: "ConditionalExpression",
1093
+ test: (test, root) => areAllChecksWithParams(test, arrayFuncParam(root), {
1094
+ compare: "!==",
1095
+ join: "||"
1096
+ }),
1097
+ consequent: {
1098
+ type: "Identifier",
1099
+ name: (name, root) => name === arrayFuncParam(root).name
1100
+ }
1101
+ }, REPLACE_BY_PATTERN);
1102
+ const COPY_KEYS_PATTERN = {
1103
+ properties: props => props.length > 1 && matches({
1104
+ type: "SpreadElement",
1105
+ argument: {
1106
+ type: "Identifier"
1107
+ }
1108
+ }, props[0]) && props.slice(1).every(matches({
1109
+ type: "Property",
1110
+ kind: "init",
1111
+ method: false,
1112
+ computed: false,
1113
+ shorthand: false,
1114
+ key: {
1115
+ type: "Identifier"
1116
+ },
1117
+ value: {
1118
+ type: "MemberExpression",
1119
+ computed: false,
1120
+ optional: false,
1121
+ object: {
1122
+ type: "Identifier",
1123
+ name: props[0].argument.name
1124
+ },
1125
+ property: {
1126
+ type: "Identifier"
1127
+ }
1128
+ }
1129
+ }))
1130
+ };
1131
+ const NOT_EQUALS_PATTERNS = {
1132
+ // !Object.is(item1, item2)
1133
+ UNARY_EXP: {
1134
+ type: TYPES.UNARY_EXPRESSION,
1135
+ operator: "!",
1136
+ prefix: true,
1137
+ argument: {
1138
+ type: TYPES.CALL_EXPRESSION,
1139
+ callee: {
1140
+ type: TYPES.MEMBER_EXPRESSION,
1141
+ object: {
1142
+ type: TYPES.IDENTIFIER,
1143
+ name: "Object"
1144
+ },
1145
+ property: {
1146
+ type: TYPES.IDENTIFIER,
1147
+ name: "is"
1148
+ }
1149
+ },
1150
+ arguments: args => args.length === 2
1151
+ }
1152
+ },
1153
+ // x => x !== y
1154
+ ARROW_FUNC: {
1155
+ type: TYPES.ARROW_FUNCTION_EXPRESSION,
1156
+ params: p => p.length === 1 && matches([{
1157
+ type: TYPES.IDENTIFIER
1158
+ }], p),
1159
+ body: {
1160
+ type: TYPES.BINARY_EXPRESSION,
1161
+ operator: "!=="
1162
+ }
1163
+ }
1164
+ };
1165
+ const NOT_EQUALS_DEEP_PATTERNS = {
1166
+ BINARY_EXP: {
1167
+ // JSON.stringify(x) !== JSON.stringify(y)
1168
+ type: TYPES.BINARY_EXPRESSION,
1169
+ left: NOT_EQUALS_DEEP_CALL_EXP_PATTERN,
1170
+ right: NOT_EQUALS_DEEP_CALL_EXP_PATTERN,
1171
+ operator: "!=="
1172
+ },
1173
+ // x => JSON.stringify(x) !== JSON.stringify(y)
1174
+ ARROW_FUNC: {
1175
+ type: TYPES.ARROW_FUNCTION_EXPRESSION,
1176
+ params: p => p.length === 1 && matches([{
1177
+ type: TYPES.IDENTIFIER
1178
+ }], p),
1179
+ body: {
1180
+ type: TYPES.BINARY_EXPRESSION,
1181
+ left: NOT_EQUALS_DEEP_CALL_EXP_PATTERN,
1182
+ right: NOT_EQUALS_DEEP_CALL_EXP_PATTERN
1183
+ }
1184
+ }
1185
+ };
1186
+ const CAPITALIZE_PATTERN = {
1187
+ // string.charAt(0).toUpperCase() + string.slice(1)
1188
+ type: TYPES.BINARY_EXPRESSION,
1189
+ operator: "+",
1190
+ left: {
1191
+ type: TYPES.CALL_EXPRESSION,
1192
+ callee: {
1193
+ type: TYPES.MEMBER_EXPRESSION,
1194
+ object: {
1195
+ type: TYPES.CALL_EXPRESSION,
1196
+ callee: {
1197
+ type: TYPES.MEMBER_EXPRESSION,
1198
+ object: {
1199
+ type: TYPES.IDENTIFIER,
1200
+ name: (name, root) => name === root.right.callee.object.name
1201
+ },
1202
+ property: {
1203
+ type: TYPES.IDENTIFIER,
1204
+ name: "charAt"
1205
+ }
1206
+ },
1207
+ arguments: args => args.length === 1 && matches([{
1208
+ type: TYPES.LITERAL,
1209
+ value: 0
1210
+ }], args)
1211
+ },
1212
+ property: {
1213
+ type: TYPES.IDENTIFIER,
1214
+ name: "toUpperCase"
1215
+ }
1216
+ }
1217
+ },
1218
+ right: {
1219
+ type: TYPES.CALL_EXPRESSION,
1220
+ callee: {
1221
+ type: TYPES.MEMBER_EXPRESSION,
1222
+ object: {
1223
+ type: TYPES.IDENTIFIER
1224
+ },
1225
+ property: {
1226
+ type: TYPES.IDENTIFIER,
1227
+ name: "slice"
1228
+ }
1229
+ },
1230
+ arguments: args => args.length === 1 && matches([{
1231
+ type: TYPES.LITERAL,
1232
+ value: 1
1233
+ }], args)
1234
+ }
1235
+ };
1236
+ const COUNT_BY_PATTERN = {
1237
+ type: "MemberExpression",
1238
+ computed: false,
1239
+ optional: false,
1240
+ property: {
1241
+ type: "Identifier",
1242
+ name: "length"
1243
+ }
1244
+ };
1245
+
1246
+ const getObjectParamIdUsagePattern = root => ({
1247
+ type: TYPES.IDENTIFIER,
1248
+ name: root.params[0].properties[0].value.name
1249
+ });
1250
+
1251
+ const getIdentifierIdUsagePattern = root => ({
1252
+ type: TYPES.MEMBER_EXPRESSION,
1253
+ object: {
1254
+ type: TYPES.IDENTIFIER,
1255
+ name: root.params[0].name
1256
+ },
1257
+ property: {
1258
+ type: TYPES.IDENTIFIER,
1259
+ name: "id"
1260
+ }
1261
+ });
1262
+
1263
+ const matchesIdOperatorCheck = (operator, type) => (node, root) => {
1264
+ const pattern = type === "identifier" ? getIdentifierIdUsagePattern(root) : getObjectParamIdUsagePattern(root);
1265
+ return matches({
1266
+ type: TYPES.BINARY_EXPRESSION,
1267
+ operator
1268
+ }, node) && (matches(pattern, node.left) || matches(pattern, node.right));
1269
+ };
1270
+
1271
+ const checkByFunc = (context, node, {
1272
+ genericPatterns,
1273
+ byIdPattern,
1274
+ functions
1275
+ }) => {
1276
+ let array = null;
1277
+
1278
+ if (matches(genericPatterns.VANILLA, node)) {
1279
+ array = getCode(context, node.callee.object);
1280
+ } else if (matches(genericPatterns.RAMDA, node)) {
1281
+ array = getCode(context, node.arguments[1]);
1282
+ } else return; // arr.filter(x => x.prop === something).length
1283
+
1284
+
1285
+ if (functions.by === "filterBy" && matches(COUNT_BY_PATTERN, node.parent)) {
1286
+ const message = canBeShortenedWithCommons("countBy");
1287
+ context.report({
1288
+ node: node.parent,
1289
+ message
1290
+ });
1291
+ return;
1292
+ }
1293
+
1294
+ if (byIdPattern) {
1295
+ const predicate = node.arguments[0];
1296
+ let idUsagePattern = null;
1297
+
1298
+ if (matches(byIdPattern.IDENTIFIER, predicate)) {
1299
+ idUsagePattern = getIdentifierIdUsagePattern(predicate);
1300
+ } else if (matches(byIdPattern.OBJECT_PARAM, predicate)) {
1301
+ idUsagePattern = getObjectParamIdUsagePattern(predicate);
1302
+ }
1303
+
1304
+ if (idUsagePattern) {
1305
+ const id = matches(idUsagePattern, predicate.body.left) ? getCode(context, predicate.body.right) : getCode(context, predicate.body.left);
1306
+ const fix = `${functions.byId}(${id}, ${array})`;
1307
+ reportSuggestion({
1308
+ context,
1309
+ node,
1310
+ fix,
1311
+ func: functions.byId
1312
+ });
1313
+ } else {
1314
+ const message = canBeShortenedWithCommons(functions.by);
1315
+ context.report({
1316
+ node,
1317
+ message
1318
+ });
1319
+ }
1320
+ } else {
1321
+ context.report({
1322
+ node,
1323
+ message: canBeShortenedWithCommons(functions.by)
1324
+ });
1325
+ }
1326
+ };
1327
+
1328
+ const getArrowFuncPattern = (operators, root) => ({
1329
+ type: TYPES.ARROW_FUNCTION_EXPRESSION,
1330
+ generator: false,
1331
+ async: false,
1332
+ params: params => params.length === 1 && [TYPES.IDENTIFIER, TYPES.OBJECT_PATTERN].includes(params[0].type),
1333
+ body: node => areAllChecksWithParams(node, arrayFuncParam(root), operators)
1334
+ });
1335
+
1336
+ const getPatternsOfByFunc = (funcName, operators) => ({
1337
+ VANILLA: {
1338
+ callee: {
1339
+ type: TYPES.MEMBER_EXPRESSION,
1340
+ property: {
1341
+ type: TYPES.IDENTIFIER,
1342
+ name: funcName
1343
+ }
1344
+ },
1345
+ arguments: (args, root) => args.length === 1 && matches([getArrowFuncPattern(operators, root)], args)
1346
+ },
1347
+ RAMDA: {
1348
+ type: TYPES.CALL_EXPRESSION,
1349
+ callee: {
1350
+ type: TYPES.IDENTIFIER,
1351
+ name: funcName
1352
+ },
1353
+ arguments: (args, root) => args.length === 2 && matches([getArrowFuncPattern(operators, root)], args)
1354
+ }
1355
+ });
1356
+
1357
+ const getPatternOfByIdFunc = operator => ({
1358
+ IDENTIFIER: {
1359
+ params: [{
1360
+ type: TYPES.IDENTIFIER
1361
+ }],
1362
+ body: matchesIdOperatorCheck(operator, "identifier")
1363
+ },
1364
+ OBJECT_PARAM: {
1365
+ params: [{
1366
+ type: TYPES.OBJECT_PATTERN,
1367
+ properties: [{
1368
+ type: TYPES.PROPERTY,
1369
+ key: {
1370
+ type: TYPES.IDENTIFIER,
1371
+ name: "id"
1372
+ }
1373
+ }]
1374
+ }],
1375
+ body: matchesIdOperatorCheck(operator, "objectParam")
1376
+ }
1377
+ });
1378
+
1379
+ const buildChecksForByFunc = (functions, pattern) => ({
1380
+ operateOn: TYPES.CALL_EXPRESSION,
1381
+ check: (context, node) => checkByFunc(context, node, {
1382
+ genericPatterns: pattern.GENERIC,
1383
+ byIdPattern: pattern.BY_ID,
1384
+ functions
1385
+ })
1386
+ });
1387
+
1388
+ const findBy = buildChecksForByFunc({
1389
+ by: "findBy",
1390
+ byId: "findById"
1391
+ }, {
1392
+ GENERIC: getPatternsOfByFunc("find", {
1393
+ compare: "===",
1394
+ join: "&&"
1395
+ }),
1396
+ BY_ID: getPatternOfByIdFunc("===")
1397
+ });
1398
+ const removeBy = buildChecksForByFunc({
1399
+ by: "removeBy",
1400
+ byId: "removeById"
1401
+ }, {
1402
+ GENERIC: getPatternsOfByFunc("filter", {
1403
+ compare: "!==",
1404
+ join: "||"
1405
+ }),
1406
+ BY_ID: getPatternOfByIdFunc("!==")
1407
+ });
1408
+ const existsBy = buildChecksForByFunc({
1409
+ by: "existsBy",
1410
+ byId: "existsById"
1411
+ }, {
1412
+ GENERIC: getPatternsOfByFunc("some", {
1413
+ compare: "===",
1414
+ join: "&&"
1415
+ }),
1416
+ BY_ID: getPatternOfByIdFunc("===")
1417
+ });
1418
+ const findIndexBy = buildChecksForByFunc({
1419
+ by: "findIndexBy",
1420
+ byId: "findIndexById"
1421
+ }, {
1422
+ GENERIC: getPatternsOfByFunc("findIndex", {
1423
+ compare: "===",
1424
+ join: "&&"
1425
+ }),
1426
+ BY_ID: getPatternOfByIdFunc("===")
1427
+ });
1428
+ const findLastBy = buildChecksForByFunc({
1429
+ by: "findLastBy"
1430
+ }, {
1431
+ GENERIC: getPatternsOfByFunc("findLast", {
1432
+ compare: "===",
1433
+ join: "&&"
1434
+ })
1435
+ });
1436
+ const findLastIndexBy = buildChecksForByFunc({
1437
+ by: "findLastIndexBy"
1438
+ }, {
1439
+ GENERIC: getPatternsOfByFunc("findLastIndex", {
1440
+ compare: "===",
1441
+ join: "&&"
1442
+ })
1443
+ });
1444
+ const filterBy = buildChecksForByFunc({
1445
+ by: "filterBy"
1446
+ }, {
1447
+ GENERIC: getPatternsOfByFunc("filter", {
1448
+ compare: "===",
1449
+ join: "&&"
1450
+ })
1451
+ });
1452
+
1453
+ var capitalize = {
1454
+ operateOn: TYPES.BINARY_EXPRESSION,
1455
+ check: (context, node) => {
1456
+ if (!matches(CAPITALIZE_PATTERN, node)) return;
1457
+ const fix = `capitalize(${getCode(context, node.right.callee.object)})`;
1458
+ reportSuggestion({
1459
+ context,
1460
+ node,
1461
+ fix,
1462
+ func: "capitalize"
1463
+ });
1464
+ }
1465
+ };
831
1466
 
832
- if (local.name === newName) {
833
- return fixer.replaceText(statement, local.name);
834
- }
1467
+ var copyKeys = {
1468
+ operateOn: TYPES.OBJECT_EXPRESSION,
1469
+ check: (context, node) => {
1470
+ if (!matches(COPY_KEYS_PATTERN, node)) return;
1471
+ const keyValuePairs = node.properties.slice(1).map(prop => [prop.value.property.name, prop.key.name]);
1472
+ const keyMap = JSON.stringify(ramda.fromPairs(keyValuePairs));
1473
+ const sourceObject = getCode(context, node.properties[0].argument);
1474
+ const fix = `copyKeys(${keyMap}, ${sourceObject})`;
1475
+ reportSuggestion({
1476
+ context,
1477
+ node,
1478
+ fix,
1479
+ func: "copyKeys"
1480
+ });
1481
+ }
1482
+ };
835
1483
 
836
- return fixer.replaceText(exported, newName);
837
- }
838
- }]
839
- });
1484
+ var dynamicArray = {
1485
+ operateOn: "CallExpression",
1486
+ check: (context, node) => {
1487
+ var _node$arguments$1$par;
1488
+
1489
+ if (!matches(DYNAMIC_ARRAY_PATTERN, node)) return;
1490
+ const length = getCode(context, node.arguments[0].properties[0].value);
1491
+ 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;
1492
+ const elementGenBody = getCode(context, node.arguments[1].body);
1493
+ const fix = `dynamicArray(${length}, ${elementGenIndexParam || "()"} => ${elementGenBody})`;
1494
+ reportSuggestion({
1495
+ context,
1496
+ node,
1497
+ fix,
1498
+ func: "dynamicArray"
1499
+ });
1500
+ }
840
1501
  };
841
1502
 
842
- var useConstantCase = {
843
- meta: {
844
- type: "suggestion",
845
- docs: {
846
- description: "Enforces constants in constants.js file to be named using constant-case."
847
- },
848
- hasSuggestions: true
849
- },
850
- create: context => ({
851
- ExportNamedDeclaration(node) {
852
- var _node$declaration;
1503
+ var isNot = {
1504
+ operateOn: [TYPES.UNARY_EXPRESSION, TYPES.ARROW_FUNCTION_EXPRESSION],
1505
+ check: (context, node) => {
1506
+ let fix = null;
853
1507
 
854
- if (!isConstantsFile(context)) return;
1508
+ if (node.type === TYPES.UNARY_EXPRESSION) {
1509
+ if (!matches(NOT_EQUALS_PATTERNS.UNARY_EXP, node)) return;
1510
+ const first = getCode(context, node.argument.arguments[0]);
1511
+ const second = getCode(context, node.argument.arguments[1]);
1512
+ fix = `isNot(${first}, ${second})`;
1513
+ } else {
1514
+ if (!matches(NOT_EQUALS_PATTERNS.ARROW_FUNC, node)) return;
1515
+ const argumentName = node.params[0].name;
1516
+ let externalValueNode = null;
1517
+
1518
+ if (argumentName === node.body.left.name) {
1519
+ externalValueNode = node.body.right;
1520
+ } else if (argumentName === node.body.right.name) {
1521
+ externalValueNode = node.body.left;
1522
+ } else return;
1523
+
1524
+ const externalValue = getCode(context, externalValueNode);
1525
+ fix = `isNot(${externalValue})`;
1526
+ }
855
1527
 
856
- if (((_node$declaration = node.declaration) === null || _node$declaration === void 0 ? void 0 : _node$declaration.kind) === "const") {
857
- var _node$declaration2;
1528
+ reportSuggestion({
1529
+ context,
1530
+ node,
1531
+ fix,
1532
+ func: "isNot"
1533
+ });
1534
+ }
1535
+ };
858
1536
 
859
- (_node$declaration2 = node.declaration) === null || _node$declaration2 === void 0 ? void 0 : _node$declaration2.declarations.forEach(({
860
- id
861
- }) => {
862
- if (id.type !== TYPES.OBJECT_PATTERN) {
863
- checkCaseAndReport({
864
- context,
865
- name: id.name,
866
- node: id
867
- });
868
- return;
869
- }
1537
+ var isNotEmpty = {
1538
+ operateOn: [TYPES.IF_STATEMENT, TYPES.WHILE_STATEMENT, TYPES.BINARY_EXPRESSION, TYPES.ARROW_FUNCTION_EXPRESSION],
1539
+ check: (context, node) => {
1540
+ const isBinaryExp = node.type === TYPES.BINARY_EXPRESSION;
1541
+ const isArrowFunc = node.type === TYPES.ARROW_FUNCTION_EXPRESSION;
1542
+ const isCondStat = node.type === TYPES.IF_STATEMENT || node.type === TYPES.WHILE_STATEMENT;
1543
+ if (isBinaryExp && !matches(NOT_EMPTY_PATTERNS.BINARY_EXP, node)) return;
1544
+ if (isArrowFunc && !matches(NOT_EMPTY_PATTERNS.ARROW_FUNC, node)) return;
1545
+ if (isCondStat && !matches(NOT_EMPTY_PATTERNS.CONDT_STAT, node)) return;
1546
+ let fix = null;
1547
+ let message = "";
1548
+ let nodeToBeReplaced = node;
870
1549
 
871
- id.properties.forEach(statement => {
872
- checkExportAndReport({
873
- context,
874
- exported: statement.value,
875
- local: statement.key,
876
- node,
877
- statement
878
- });
879
- });
880
- });
1550
+ if (isArrowFunc) {
1551
+ fix = "isNotEmpty";
1552
+ } else {
1553
+ const object = isBinaryExp ? node.left.object : node.test.object;
1554
+ const isObjLenCheck = object.type === TYPES.CALL_EXPRESSION;
1555
+ nodeToBeReplaced = isBinaryExp ? node : node.test;
1556
+
1557
+ if (isObjLenCheck) {
1558
+ const objName = getCode(context, object.arguments[0]);
1559
+ fix = `isNotEmpty(${objName})`;
881
1560
  } else {
882
- node.specifiers.forEach(statement => {
883
- const {
884
- exported,
885
- local
886
- } = statement;
887
- checkExportAndReport({
888
- context,
889
- exported,
890
- local,
891
- node,
892
- statement
893
- });
894
- });
1561
+ const arrName = getCode(context, object);
1562
+ fix = `isNotEmpty(${arrName})`;
1563
+ message = `Can be replaced with: ${fix}, if '${arrName}' is an array or string.`;
895
1564
  }
896
1565
  }
897
1566
 
898
- })
1567
+ reportSuggestion({
1568
+ context,
1569
+ node: nodeToBeReplaced,
1570
+ fix,
1571
+ func: "isNotEmpty",
1572
+ message
1573
+ });
1574
+ }
899
1575
  };
900
1576
 
901
- const ASSIGNMENT_PATTERNS = [{
902
- id: {
903
- type: "ObjectPattern"
904
- }
905
- }, {
906
- id: {
907
- type: "Identifier"
1577
+ var isNotEqualDeep = {
1578
+ operateOn: [TYPES.BINARY_EXPRESSION, TYPES.ARROW_FUNCTION_EXPRESSION],
1579
+ check: (context, node) => {
1580
+ let fix = null;
1581
+
1582
+ if (node.type === TYPES.BINARY_EXPRESSION) {
1583
+ if (!matches(NOT_EQUALS_DEEP_PATTERNS.BINARY_EXP, node)) return;
1584
+ const first = getCode(context, node.left.arguments[0]);
1585
+ const second = getCode(context, node.right.arguments[0]);
1586
+ fix = `isNotEqualDeep(${first}, ${second})`;
1587
+ } else {
1588
+ if (!matches(NOT_EQUALS_DEEP_PATTERNS.ARROW_FUNC, node)) return;
1589
+ const argumentName = node.params[0].name;
1590
+ let externalValueNode = null;
1591
+
1592
+ if (argumentName === node.body.left.arguments[0].name) {
1593
+ externalValueNode = node.body.right.arguments[0];
1594
+ } else if (argumentName === node.body.right.arguments[0].name) {
1595
+ externalValueNode = node.body.left.arguments[0];
1596
+ } else return;
1597
+
1598
+ const externalValue = getCode(context, externalValueNode);
1599
+ fix = `isNotEqualDeep(${externalValue})`;
1600
+ }
1601
+
1602
+ reportSuggestion({
1603
+ context,
1604
+ node,
1605
+ fix,
1606
+ func: "isNotEqualDeep"
1607
+ });
908
1608
  }
909
- }];
910
- const IDENTIFIER_INITIALIZATION_PATTERN = {
911
- type: "Identifier",
912
- name: "globalProps"
913
1609
  };
914
- const MEMBER_EXPRESSION_INITIALIZATION_PATTERN = {
915
- type: "MemberExpression",
916
- object: {
917
- type: "Identifier",
918
- name: "globalProps"
1610
+
1611
+ var isNotNil = {
1612
+ operateOn: [TYPES.LOGICAL_EXPRESSION, TYPES.ARROW_FUNCTION_EXPRESSION],
1613
+ check: (context, node) => {
1614
+ if (!matchesAny(NOT_NIL_PATTERNS, node)) return;
1615
+ let fix = null;
1616
+
1617
+ if (node.type === TYPES.ARROW_FUNCTION_EXPRESSION) {
1618
+ if (node.params[0].name !== node.body.argument.arguments[0].name) return;
1619
+ fix = `isNotNil`;
1620
+ } else if (node.type === TYPES.LOGICAL_EXPRESSION) {
1621
+ if (node.left.left.name !== node.right.left.name) return;
1622
+ fix = `isNotNil(${node.left.left.name})`;
1623
+ }
1624
+
1625
+ reportSuggestion({
1626
+ context,
1627
+ node,
1628
+ fix,
1629
+ func: "isNotNil"
1630
+ });
919
1631
  }
920
1632
  };
921
- const GLOBALPROPS_REASSIGNMENT_PATTERN = {
922
- type: "Identifier",
923
- name: "globalProps"
924
- };
925
1633
 
926
- const checkAssignment = (context, node) => {
927
- if (matches_1(IDENTIFIER_INITIALIZATION_PATTERN, node)) {
928
- context.report(node, GLOBALPROPS_NO_ASSIGNMENT_MESSAGE);
929
- } else if (matches_1(MEMBER_EXPRESSION_INITIALIZATION_PATTERN, node)) {
930
- context.report(node, NESTED_GLOBALPROPS_NO_ASSIGNMENT_MESSAGE);
1634
+ var noop = {
1635
+ operateOn: ["FunctionExpression", "ArrowFunctionExpression", "FunctionDeclaration"],
1636
+ check: (context, node) => {
1637
+ if (matches(NOOP_PATTERN, node)) {
1638
+ reportSuggestion({
1639
+ context,
1640
+ node,
1641
+ fix: "noop",
1642
+ func: "noop"
1643
+ });
1644
+ }
931
1645
  }
932
1646
  };
933
1647
 
934
- var noGlobalPropsDestructure = {
935
- meta: {
936
- type: "problem",
937
- docs: {
938
- description: "Disallows destructuring of globalProps."
939
- }
1648
+ const getMemberIdPattern = paramName => ({
1649
+ type: TYPES.MEMBER_EXPRESSION,
1650
+ object: {
1651
+ type: TYPES.IDENTIFIER,
1652
+ name: name => name === paramName
940
1653
  },
941
- create: context => ({
942
- VariableDeclarator(node) {
943
- if (!matchesAny(node, ASSIGNMENT_PATTERNS)) return;
944
- checkAssignment(context, node.init);
945
- },
1654
+ computed: false,
1655
+ property: {
1656
+ type: TYPES.IDENTIFIER,
1657
+ name: "id"
1658
+ },
1659
+ optional: false
1660
+ });
946
1661
 
947
- AssignmentExpression: node => checkAssignment(context, node.right)
948
- })
1662
+ var replaceBy = {
1663
+ operateOn: TYPES.CALL_EXPRESSION,
1664
+ check: (context, node) => {
1665
+ var _node$arguments;
1666
+
1667
+ const {
1668
+ body: conditional
1669
+ } = ((_node$arguments = node.arguments) === null || _node$arguments === void 0 ? void 0 : _node$arguments[0]) ?? {};
1670
+ let comparison = null,
1671
+ replaceNode = null,
1672
+ binaryExpressionPattern = null;
1673
+
1674
+ if (matches(REPLACE_BY_PATTERN, node)) {
1675
+ binaryExpressionPattern = {
1676
+ type: TYPES.BINARY_EXPRESSION,
1677
+ operator: "==="
1678
+ };
1679
+ replaceNode = conditional.consequent;
1680
+ comparison = conditional.test;
1681
+ } else if (matches(REPLACE_BY_NEGATED_PATTERN, node)) {
1682
+ binaryExpressionPattern = {
1683
+ type: TYPES.BINARY_EXPRESSION,
1684
+ operator: "!=="
1685
+ };
1686
+ replaceNode = conditional.alternate;
1687
+ comparison = conditional.test;
1688
+ } else return;
1689
+
1690
+ if (!matches(binaryExpressionPattern, comparison)) {
1691
+ context.report({
1692
+ node,
1693
+ message: canBeShortenedWithCommons("replaceBy")
1694
+ });
1695
+ return;
1696
+ }
1697
+
1698
+ const argumentName = arrayFuncParam(node).name;
1699
+ const memberIdPattern = getMemberIdPattern(argumentName);
1700
+ let externalId = null;
1701
+
1702
+ if (matches(memberIdPattern, comparison.left)) {
1703
+ externalId = comparison.right;
1704
+ } else if (matches(memberIdPattern, comparison.right)) {
1705
+ externalId = comparison.left;
1706
+ } else return;
1707
+
1708
+ const id = getCode(context, externalId);
1709
+ const replacement = getCode(context, replaceNode);
1710
+ const array = getCode(context, node.callee.object);
1711
+ const fix = `replaceById(${id}, ${replacement}, ${array})`;
1712
+ reportSuggestion({
1713
+ context,
1714
+ node,
1715
+ fix,
1716
+ func: "replaceById"
1717
+ });
1718
+ }
949
1719
  };
950
1720
 
951
- var noGlobalPropsReassignment = {
1721
+ var toLabelAndValue = {
1722
+ operateOn: "ObjectExpression",
1723
+ check: (context, node) => {
1724
+ if (!matches(LABEL_AND_VALUE_PATTERN, node)) return;
1725
+ const [label, value] = ramda.pluck("value", node.properties).map(node => getCode(context, node)); // order doesn't matter here
1726
+
1727
+ if (label !== value) return;
1728
+ const fix = `toLabelAndValue(${label})`;
1729
+ reportSuggestion({
1730
+ context,
1731
+ node,
1732
+ fix,
1733
+ func: "toLabelAndValue"
1734
+ });
1735
+ }
1736
+ };
1737
+
1738
+ var neetocommonsTips = {
952
1739
  meta: {
953
- type: "problem",
1740
+ type: "suggestion",
954
1741
  docs: {
955
- description: "Disallows re-assignment of globalProps."
956
- }
1742
+ description: "Provides suggestions on pieces of code that can be imported from neeto-commons-frontend rather than reinventing the wheel"
1743
+ },
1744
+ hasSuggestions: true
957
1745
  },
958
- create: context => ({
959
- AssignmentExpression(node) {
960
- if (patternExistsDeep(node.left, GLOBALPROPS_REASSIGNMENT_PATTERN)) {
961
- context.report(node, NO_GLOBALPROPS_REASSIGNMENT_MESSAGE);
962
- }
963
- }
964
-
965
- })
1746
+ create: context => {
1747
+ const operationsArr = [noop, toLabelAndValue, findBy, removeBy, existsBy, filterBy, findIndexBy, findLastBy, findLastIndexBy, replaceBy, copyKeys, dynamicArray, capitalize, isNotNil, isNotEqualDeep, isNot, isNotEmpty].map(op => {
1748
+ if (!Array.isArray(op.operateOn)) return op;
1749
+ return op.operateOn.map(operateOn => ({
1750
+ operateOn,
1751
+ check: op.check
1752
+ }));
1753
+ }).flat();
1754
+ const operations = ramda.groupBy(ramda.prop("operateOn"), operationsArr);
1755
+ return ramda.fromPairs(ramda.toPairs(operations).map(([operateOn, operations]) => [operateOn, node => operations.forEach(op => op.check(context, node))]));
1756
+ }
966
1757
  };
967
1758
 
968
1759
  var noAxiosImportOutsideApis = {
@@ -1010,7 +1801,7 @@
1010
1801
  }) => type !== TYPES.ASSIGNMENT_PATTERN;
1011
1802
 
1012
1803
  const containsExcessArguments = (params, isApiAction) => {
1013
- const noOfParams = require$$0.count(nonDefaultParam, params);
1804
+ const noOfParams = ramda.count(nonDefaultParam, params);
1014
1805
  return isApiAction ? noOfParams > API_ACTIONS_ARGUMENT_LIMIT : noOfParams > ARGUMENT_LIMIT;
1015
1806
  };
1016
1807
 
@@ -1021,7 +1812,7 @@
1021
1812
  if (!containsExcessArguments(params, isApiAction)) return;
1022
1813
  const loc = {
1023
1814
  start: params[0].loc.start,
1024
- end: require$$0.last(params).loc.end
1815
+ end: ramda.last(params).loc.end
1025
1816
  };
1026
1817
  const messages = isApiAction ? [NO_EXCESS_API_ACTION_ARGUMENTS_MESSAGE] : [NO_EXCESS_FUNCTION_ARGUMENTS_MESSAGE];
1027
1818
  const containsUnfixableParam = params.some(({
@@ -1085,7 +1876,7 @@
1085
1876
  }]
1086
1877
  }];
1087
1878
 
1088
- const i18next = require$$0.memoizeWith(() => "", () => require("i18next"));
1879
+ const i18next = ramda.memoizeWith(() => "", () => require("i18next"));
1089
1880
 
1090
1881
  const isKeyMissing = ({
1091
1882
  config,
@@ -1095,7 +1886,7 @@
1095
1886
  const translationExists = i18next().exists(key, config);
1096
1887
  if (!translationExists) return true;
1097
1888
  const translation = i18next().t(key, config);
1098
- return typeof require$$0.path(translation.exactUsedKey.split("."), content) !== "string";
1889
+ return typeof ramda.path(translation.exactUsedKey.split("."), content) !== "string";
1099
1890
  };
1100
1891
 
1101
1892
  const checkAndReport$1 = ({
@@ -1174,7 +1965,7 @@
1174
1965
  CallExpression(node) {
1175
1966
  var _node$arguments$;
1176
1967
 
1177
- if (!matchesAny(node, LOCALIZATION_CALL_PATTERNS)) return;
1968
+ if (!matchesAny(LOCALIZATION_CALL_PATTERNS, node)) return;
1178
1969
  const config = {};
1179
1970
 
1180
1971
  if (((_node$arguments$ = node.arguments[1]) === null || _node$arguments$ === void 0 ? void 0 : _node$arguments$.type) === TYPES.OBJECT_EXPRESSION) {
@@ -1240,12 +2031,12 @@
1240
2031
  if (!node || typeof node !== "object") return acc;
1241
2032
  return Object.entries(node).reduce((acc, [key, value]) => {
1242
2033
  if (key === "parent") return acc;
1243
- if (matches_1(ramdaUsage(identifierName), value)) return [...acc, value];
2034
+ if (matches(ramdaUsage(identifierName), value)) return [...acc, value];
1244
2035
  return findAllRamdaUsage(value, identifierName, acc);
1245
2036
  }, acc);
1246
2037
  };
1247
2038
 
1248
- const gatherMethods = require$$0.pipe(require$$0.map(require$$0.path(["property", "name"])), require$$0.sortBy(require$$0.identity), require$$0.uniq, require$$0.join(", "));
2039
+ const gatherMethods = ramda.pipe(ramda.map(ramda.path(["property", "name"])), ramda.sortBy(ramda.identity), ramda.uniq, ramda.join(", "));
1249
2040
  var noNamespaceSpecifierImportForRamda = {
1250
2041
  meta: {
1251
2042
  type: "problem",
@@ -1256,7 +2047,7 @@
1256
2047
  },
1257
2048
  create: context => ({
1258
2049
  ImportDeclaration: node => {
1259
- if (matches_1(RAMDA_NAMESPACE_IMPORT_PATTERN, node)) {
2050
+ if (matches(RAMDA_NAMESPACE_IMPORT_PATTERN, node)) {
1260
2051
  const allRUsages = findAllRamdaUsage(node.parent.body, node.specifiers[0].local.name);
1261
2052
  const ramdaMethodsUsed = gatherMethods(allRUsages);
1262
2053
  context.report({
@@ -1328,7 +2119,7 @@
1328
2119
 
1329
2120
  const isExpressionOnly = node => node.expressions.length === 1 && node.quasis.length === 2 && node.quasis[0].value.cooked === "" && node.quasis[1].value.cooked === "";
1330
2121
 
1331
- const isInsideJSXElement = node => node.parent.type === TYPES.JSX_EXPRESSION_CONTAINER && node.parent.parent.type === TYPES.JSX_ELEMENT && !node.quasis[0].value.cooked.match(STARTS_WITH_SPACES_PATTERN) && !require$$0.last(node.quasis).value.cooked.match(ENDS_WITH_SPACES_PATTERN);
2122
+ const isInsideJSXElement = node => node.parent.type === TYPES.JSX_EXPRESSION_CONTAINER && node.parent.parent.type === TYPES.JSX_ELEMENT && !node.quasis[0].value.cooked.match(STARTS_WITH_SPACES_PATTERN) && !ramda.last(node.quasis).value.cooked.match(ENDS_WITH_SPACES_PATTERN);
1332
2123
 
1333
2124
  const isReplaceableQuasiOnly = node => node.expressions.length === 0 && node.quasis.length === 1 && !node.quasis[0].value.cooked.match(STARTS_OR_ENDS_WITH_SPACES_PATTERN);
1334
2125
 
@@ -1405,6 +2196,45 @@
1405
2196
  })
1406
2197
  };
1407
2198
 
2199
+ const NIL_BINARY_EXP_PATTERN = {
2200
+ type: TYPES.BINARY_EXPRESSION,
2201
+ operator: "===",
2202
+ right: matchesAny([{
2203
+ type: TYPES.LITERAL,
2204
+ value: null
2205
+ }, {
2206
+ type: TYPES.IDENTIFIER,
2207
+ name: "undefined"
2208
+ }])
2209
+ };
2210
+ const OBJ_KEY_LENGTH_PATTERN = {
2211
+ type: TYPES.MEMBER_EXPRESSION,
2212
+ object: {
2213
+ type: TYPES.CALL_EXPRESSION,
2214
+ callee: {
2215
+ type: TYPES.MEMBER_EXPRESSION,
2216
+ object: {
2217
+ type: TYPES.IDENTIFIER,
2218
+ name: "Object"
2219
+ }
2220
+ },
2221
+ property: {
2222
+ type: TYPES.IDENTIFIER,
2223
+ name: "keys"
2224
+ }
2225
+ },
2226
+ property: {
2227
+ type: TYPES.IDENTIFIER,
2228
+ name: "length"
2229
+ }
2230
+ };
2231
+ const ARRAY_LENGTH_PATTERN = {
2232
+ type: TYPES.MEMBER_EXPRESSION,
2233
+ property: {
2234
+ type: TYPES.IDENTIFIER,
2235
+ name: "length"
2236
+ }
2237
+ };
1408
2238
  const ARRAY_INSERTS_PATTERN = {
1409
2239
  APPEND: {
1410
2240
  // x => [...x, y]
@@ -1701,29 +2531,29 @@
1701
2531
  }
1702
2532
  }
1703
2533
  };
1704
-
1705
- const addFunctionImport = (context, fixer, functions) => {
1706
- const root = context.getAncestors()[0];
1707
- const ramdaImport = root.body.find(node => matches_1(RAMDA_IMPORT_PATTERN, node));
1708
-
1709
- if (ramdaImport) {
1710
- const extraImports = functions.filter(func => !ramdaImport.specifiers.some(require$$0.pathEq(["imported", "name"], func)));
1711
- if (require$$0.isEmpty(extraImports)) return undefined;
1712
- return fixer.insertTextBefore(ramdaImport.specifiers[0], `${extraImports.join(", ")}, `);
2534
+ const NIL_PATTERN = // x === null || x === undefined
2535
+ {
2536
+ operator: "||",
2537
+ left: NIL_BINARY_EXP_PATTERN,
2538
+ right: NIL_BINARY_EXP_PATTERN
2539
+ };
2540
+ const EMPTY_PATTERN = [// array.length === 0, Object.keys(obj).length === 0, if(array.length === 0), while(array.length === 0)
2541
+ {
2542
+ type: TYPES.BINARY_EXPRESSION,
2543
+ operator: "===",
2544
+ left: matchesAny([ARRAY_LENGTH_PATTERN, OBJ_KEY_LENGTH_PATTERN]),
2545
+ right: {
2546
+ type: TYPES.LITERAL,
2547
+ value: 0
1713
2548
  }
1714
-
1715
- return fixer.insertTextBefore(root.body[0], `import { ${functions.join(", ")} } from "ramda";\n`);
1716
- };
1717
- const replaceNodeWithImports = ({
1718
- context,
1719
- node,
1720
- fix,
1721
- functions
1722
- }) => function* (fixer) {
1723
- const imports = addFunctionImport(context, fixer, Array.isArray(functions) ? functions : [functions]);
1724
- if (imports) yield imports;
1725
- yield fixer.replaceText(node, fix);
1726
- };
2549
+ }, // if(!array.length), if(!Object.keys(obj).length), while(!array.length), while(!Object.keys(obj).length)
2550
+ {
2551
+ type: TYPES.UNARY_EXPRESSION,
2552
+ operator: "!",
2553
+ prefix: true,
2554
+ argument: matchesAny([ARRAY_LENGTH_PATTERN, OBJ_KEY_LENGTH_PATTERN])
2555
+ }];
2556
+ const replacer = nodeReplacerWithImports(RAMDA_IMPORT_PATTERN);
1727
2557
 
1728
2558
  var arrayInsertsLintCheck = {
1729
2559
  operateOn: "ArrowFunctionExpression",
@@ -1742,11 +2572,11 @@
1742
2572
  } = body;
1743
2573
  let fix = null;
1744
2574
 
1745
- if (matches_1(ARRAY_INSERTS_PATTERN.APPEND, node) && elements[1].type !== TYPES.SPREAD_ELEMENT && params[0].name === elements[0].argument.name) {
2575
+ if (matches(ARRAY_INSERTS_PATTERN.APPEND, node) && elements[1].type !== TYPES.SPREAD_ELEMENT && params[0].name === elements[0].argument.name) {
1746
2576
  fix = `append(${getCode(context, elements[1])})`;
1747
- } else if (matches_1(ARRAY_INSERTS_PATTERN.PREPEND, node) && elements[0].type !== TYPES.SPREAD_ELEMENT && params[0].name === elements[1].argument.name) {
2577
+ } else if (matches(ARRAY_INSERTS_PATTERN.PREPEND, node) && elements[0].type !== TYPES.SPREAD_ELEMENT && params[0].name === elements[1].argument.name) {
1748
2578
  fix = `prepend(${getCode(context, elements[0])})`;
1749
- } else if (matches_1(ARRAY_INSERTS_PATTERN.CONCAT, node) && params[0].name === elements[0].argument.name) {
2579
+ } else if (matches(ARRAY_INSERTS_PATTERN.CONCAT, node) && params[0].name === elements[0].argument.name) {
1750
2580
  fix = `concat(${getCode(context, elements[1].argument)})`;
1751
2581
  }
1752
2582
 
@@ -1757,7 +2587,7 @@
1757
2587
  message: canBeReplacedWith(fix),
1758
2588
  suggest: [{
1759
2589
  desc: `Replace with ${funcName} function`,
1760
- fix: replaceNodeWithImports({
2590
+ fix: replacer.replaceNode({
1761
2591
  context,
1762
2592
  node,
1763
2593
  fix,
@@ -1778,7 +2608,7 @@
1778
2608
  operateOn: "ArrowFunctionExpression",
1779
2609
  check: (context, node) => {
1780
2610
  if (node.params.length !== 1) return;
1781
- if (!matches_1(ASSOC_PATTERN, node)) return;
2611
+ if (!matches(ASSOC_PATTERN, node)) return;
1782
2612
  if (node.body.properties.length !== 2) return;
1783
2613
  if (node.body.properties[0].argument.name !== node.params[0].name) return;
1784
2614
  const property = node.body.properties[1];
@@ -1793,7 +2623,7 @@
1793
2623
  message: canBeReplacedWith(fix),
1794
2624
  suggest: [{
1795
2625
  desc: "Replace with assoc function",
1796
- fix: replaceNodeWithImports({
2626
+ fix: replacer.replaceNode({
1797
2627
  context,
1798
2628
  node,
1799
2629
  fix,
@@ -1807,14 +2637,14 @@
1807
2637
  var equalsLintCheck = {
1808
2638
  operateOn: "BinaryExpression",
1809
2639
  check: (context, node) => {
1810
- if (matches_1(JSON_EQUALS_PATTERN, node)) {
2640
+ if (matches(JSON_EQUALS_PATTERN, node)) {
1811
2641
  const fix = `equals(${getCode(context, node.left.arguments[0])}, ${getCode(context, node.right.arguments[0])})`;
1812
2642
  context.report({
1813
2643
  node,
1814
2644
  message: canBeReplacedWith(fix),
1815
2645
  suggest: [{
1816
2646
  desc: "Replace with equals function",
1817
- fix: replaceNodeWithImports({
2647
+ fix: replacer.replaceNode({
1818
2648
  context,
1819
2649
  node,
1820
2650
  fix,
@@ -1829,13 +2659,13 @@
1829
2659
  var identityLintCheck = {
1830
2660
  operateOn: "ArrowFunctionExpression",
1831
2661
  check: (context, node) => {
1832
- if (matches_1(IDENTITY_PATTERN, node) && node.params[0].name === node.body.name) {
2662
+ if (matches(IDENTITY_PATTERN, node) && node.params[0].name === node.body.name) {
1833
2663
  context.report({
1834
2664
  node,
1835
2665
  message: canBeReplacedWith("identity"),
1836
2666
  suggest: [{
1837
2667
  desc: "Replace with identity function",
1838
- fix: replaceNodeWithImports({
2668
+ fix: replacer.replaceNode({
1839
2669
  context,
1840
2670
  node,
1841
2671
  fix: "identity",
@@ -1847,13 +2677,57 @@
1847
2677
  }
1848
2678
  };
1849
2679
 
1850
- const findPatternIndex = node => MERGE_PATTERNS.findIndex(matches_1(require$$0.__, node));
2680
+ var isEmptyCheck = {
2681
+ operateOn: [TYPES.BINARY_EXPRESSION, TYPES.UNARY_EXPRESSION],
2682
+ check: (context, node) => {
2683
+ if (!matchesAny(EMPTY_PATTERN, node)) return;
2684
+ let fix = null;
2685
+ let message = "";
2686
+ const isBinaryExp = node.type === TYPES.BINARY_EXPRESSION;
2687
+ const object = isBinaryExp ? node.left.object : node.argument.object;
2688
+ const isObjLenCheck = object.type === TYPES.CALL_EXPRESSION;
2689
+
2690
+ if (isObjLenCheck) {
2691
+ const objName = getCode(context, object.arguments[0]);
2692
+ fix = `isEmpty(${objName})`;
2693
+ } else {
2694
+ const arrName = getCode(context, object);
2695
+ fix = `isEmpty(${arrName})`;
2696
+ message = `Can be replaced with: ${fix}, if '${arrName}' is an array or string.`;
2697
+ }
2698
+
2699
+ reportSuggestion({
2700
+ context,
2701
+ node,
2702
+ fix,
2703
+ func: "isEmpty",
2704
+ message
2705
+ });
2706
+ }
2707
+ };
2708
+
2709
+ var isNilCheck = {
2710
+ operateOn: TYPES.LOGICAL_EXPRESSION,
2711
+ check: (context, node) => {
2712
+ if (!matches(NIL_PATTERN, node)) return;
2713
+ if (node.left.left.name !== node.right.left.name) return;
2714
+ const fix = `isNil(${node.left.left.name})`;
2715
+ reportSuggestion({
2716
+ context,
2717
+ node,
2718
+ fix,
2719
+ func: "isNil"
2720
+ });
2721
+ }
2722
+ };
2723
+
2724
+ const findPatternIndex = node => MERGE_PATTERNS.findIndex(matches(ramda.__, node));
1851
2725
 
1852
2726
  const convertToMergeLeft = (context, node) => {
1853
2727
  const properties = node.body.properties.slice(1);
1854
2728
  const matchIndex = findPatternIndex(node);
1855
2729
  return matchIndex === 2 && properties.length === 1 ? `mergeLeft(${getCode(context, properties[0].argument)})` : `mergeLeft({ ${getCode(context, {
1856
- range: [properties[0].range[0], require$$0.last(properties).range[1]]
2730
+ range: [properties[0].range[0], ramda.last(properties).range[1]]
1857
2731
  })} })`;
1858
2732
  };
1859
2733
 
@@ -1876,7 +2750,7 @@
1876
2750
  message: canBeReplacedWith(fix),
1877
2751
  suggest: [{
1878
2752
  desc: "Replace with mergeLeft function",
1879
- fix: replaceNodeWithImports({
2753
+ fix: replacer.replaceNode({
1880
2754
  context,
1881
2755
  node,
1882
2756
  fix,
@@ -1892,7 +2766,7 @@
1892
2766
  message: canBeReplacedWith(fix),
1893
2767
  suggest: [{
1894
2768
  desc: "Replace with pluck function",
1895
- fix: replaceNodeWithImports({
2769
+ fix: replacer.replaceNode({
1896
2770
  context,
1897
2771
  node,
1898
2772
  fix,
@@ -1904,15 +2778,15 @@
1904
2778
  var pluckLintCheck = {
1905
2779
  operateOn: "CallExpression",
1906
2780
  check: (context, node) => {
1907
- if (matches_1(PLUCK_PATTERNS.OBJECT_ARROW_FUNCTION, node)) {
2781
+ if (matches(PLUCK_PATTERNS.OBJECT_ARROW_FUNCTION, node)) {
1908
2782
  const code = getCode(context, node.callee.object);
1909
2783
  const func = node.arguments[0];
1910
2784
 
1911
- if (matches_1(PLUCK_PATTERNS.IDENTIFIER, func)) {
2785
+ if (matches(PLUCK_PATTERNS.IDENTIFIER, func)) {
1912
2786
  if (func.params[0].name !== func.body.object.name) return;
1913
2787
  const fix = `pluck("${func.body.property.name}", ${code})`;
1914
2788
  reportViolation(context, node, fix);
1915
- } else if (matches_1(PLUCK_PATTERNS.DESTRUCTURE, func)) {
2789
+ } else if (matches(PLUCK_PATTERNS.DESTRUCTURE, func)) {
1916
2790
  const propertyName = func.params[0].properties[0].value.name;
1917
2791
  if (propertyName !== func.body.name) return;
1918
2792
  const fix = `pluck("${propertyName}", ${code})`;
@@ -1926,11 +2800,11 @@
1926
2800
  operateOn: "ArrowFunctionExpression",
1927
2801
  check: (context, node) => {
1928
2802
  let fix = null;
1929
- if (matches_1(PROP_IGNORE_PATTERN, node.parent)) return;
2803
+ if (matches(PROP_IGNORE_PATTERN, node.parent)) return;
1930
2804
 
1931
- if (matches_1(PROP_PATTERNS.OBJECT, node) && node.params[0].properties[0].value.name === node.body.name) {
2805
+ if (matches(PROP_PATTERNS.OBJECT, node) && node.params[0].properties[0].value.name === node.body.name) {
1932
2806
  fix = `prop("${node.body.name}")`;
1933
- } else if (matches_1(PROP_PATTERNS.IDENTITY, node) && node.params[0].name === node.body.object.name) {
2807
+ } else if (matches(PROP_PATTERNS.IDENTITY, node) && node.params[0].name === node.body.object.name) {
1934
2808
  fix = `prop("${node.body.property.name}")`;
1935
2809
  } else {
1936
2810
  return;
@@ -1941,7 +2815,7 @@
1941
2815
  message: canBeReplacedWith(fix),
1942
2816
  suggest: [{
1943
2817
  desc: "Replace with prop function",
1944
- fix: replaceNodeWithImports({
2818
+ fix: replacer.replaceNode({
1945
2819
  context,
1946
2820
  node,
1947
2821
  fix,
@@ -1975,7 +2849,7 @@
1975
2849
  var sumLintCheck = {
1976
2850
  operateOn: "CallExpression",
1977
2851
  check: (context, node) => {
1978
- if (!matches_1(SUM_PATTERN, node)) return;
2852
+ if (!matches(SUM_PATTERN, node)) return;
1979
2853
  const reduceFunc = node.arguments[0];
1980
2854
  const {
1981
2855
  accumulator,
@@ -2002,7 +2876,7 @@
2002
2876
  message: canBeReplacedWith(fix),
2003
2877
  suggest: [{
2004
2878
  desc: "Replace with sum function",
2005
- fix: replaceNodeWithImports({
2879
+ fix: replacer.replaceNode({
2006
2880
  context,
2007
2881
  node,
2008
2882
  fix,
@@ -2022,8 +2896,8 @@
2022
2896
  }
2023
2897
  },
2024
2898
  create: context => {
2025
- const operations = require$$0.groupBy(require$$0.prop("operateOn"), [arrayInsertsLintCheck, assocLintCheck, equalsLintCheck, identityLintCheck, mergeLintCheck, pluckLintCheck, propLintCheck, sumLintCheck]);
2026
- return require$$0.fromPairs(require$$0.toPairs(operations).map(([operateOn, operations]) => [operateOn, node => operations.forEach(op => op.check(context, node))]));
2899
+ const operations = ramda.groupBy(ramda.prop("operateOn"), [arrayInsertsLintCheck, assocLintCheck, equalsLintCheck, identityLintCheck, mergeLintCheck, pluckLintCheck, propLintCheck, sumLintCheck, isNilCheck, isEmptyCheck]);
2900
+ return ramda.fromPairs(ramda.toPairs(operations).map(([operateOn, operations]) => [operateOn, node => operations.forEach(op => op.check(context, node))]));
2027
2901
  }
2028
2902
  };
2029
2903
 
@@ -2087,14 +2961,14 @@
2087
2961
  },
2088
2962
  create: context => ({
2089
2963
  CallExpression(node) {
2090
- if (matches_1(AXIOS_GET_PATTERN, node)) {
2964
+ if (matches(AXIOS_GET_PATTERN, node)) {
2091
2965
  if (!VALID_URL_TYPES.includes(node.arguments[0].type)) return;
2092
2966
  checkAndReport({
2093
2967
  context,
2094
2968
  node,
2095
2969
  urlNode: node.arguments[0]
2096
2970
  });
2097
- } else if (matches_1(AXIOS_PATTERN, node)) {
2971
+ } else if (matches(AXIOS_PATTERN, node)) {
2098
2972
  var _methodNode;
2099
2973
 
2100
2974
  let methodNode = null;
@@ -2173,7 +3047,7 @@
2173
3047
  create: context => ({
2174
3048
  ImportDeclaration(node) {
2175
3049
  const aliases = context.options[0];
2176
- if (require$$0.isEmpty(aliases) || require$$0.isNil(aliases)) return;
3050
+ if (ramda.isEmpty(aliases) || ramda.isNil(aliases)) return;
2177
3051
  const importPath = node.source.value;
2178
3052
  if (!importPath.startsWith("../")) return;
2179
3053
  const filename = context.getFilename();
@@ -2197,6 +3071,7 @@
2197
3071
 
2198
3072
  var index = {
2199
3073
  rules: {
3074
+ "neetocommons-tips": neetocommonsTips,
2200
3075
  "api-connector-name-should-match-filename": apiConnectorNameShouldMatchFilename,
2201
3076
  "api-connector-should-use-default-export": apiConnectorShouldUseDefaultExport,
2202
3077
  "combine-multiple-independent-awaits": combineMultipleIndependentAwaits,