@bigbinary/eslint-plugin-neeto 1.0.11

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 +149 -0
  2. package/dist/index.js +2225 -0
  3. package/package.json +56 -0
package/dist/index.js ADDED
@@ -0,0 +1,2225 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('path'), require('ramda')) :
3
+ typeof define === 'function' && define.amd ? define(['path', 'ramda'], factory) :
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';
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
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
+
177
+ function _arrayWithHoles(arr) {
178
+ if (Array.isArray(arr)) return arr;
179
+ }
180
+
181
+ function _iterableToArrayLimit(arr, i) {
182
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
183
+
184
+ if (_i == null) return;
185
+ var _arr = [];
186
+ var _n = true;
187
+ var _d = false;
188
+
189
+ var _s, _e;
190
+
191
+ try {
192
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
193
+ _arr.push(_s.value);
194
+
195
+ if (i && _arr.length === i) break;
196
+ }
197
+ } catch (err) {
198
+ _d = true;
199
+ _e = err;
200
+ } finally {
201
+ try {
202
+ if (!_n && _i["return"] != null) _i["return"]();
203
+ } finally {
204
+ if (_d) throw _e;
205
+ }
206
+ }
207
+
208
+ return _arr;
209
+ }
210
+
211
+ function _arrayLikeToArray(arr, len) {
212
+ if (len == null || len > arr.length) len = arr.length;
213
+
214
+ for (var i = 0, arr2 = new Array(len); i < len; i++) {
215
+ arr2[i] = arr[i];
216
+ }
217
+
218
+ return arr2;
219
+ }
220
+
221
+ function _unsupportedIterableToArray(o, minLen) {
222
+ if (!o) return;
223
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
224
+ var n = Object.prototype.toString.call(o).slice(8, -1);
225
+ if (n === "Object" && o.constructor) n = o.constructor.name;
226
+ if (n === "Map" || n === "Set") return Array.from(o);
227
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
228
+ }
229
+
230
+ function _nonIterableRest() {
231
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
232
+ }
233
+
234
+ function _slicedToArray(arr, i) {
235
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
236
+ }
237
+
238
+ function _typeof(obj) {
239
+ "@babel/helpers - typeof";
240
+
241
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
242
+ return typeof obj;
243
+ } : function (obj) {
244
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
245
+ }, _typeof(obj);
246
+ }
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
+ var matches = ramda.curry(function (pattern, object) {
319
+ if (object === pattern) return true;
320
+ if (typeof pattern === "function" && pattern(object)) return true;
321
+ if (ramda.isNil(pattern) || ramda.isNil(object)) return false;
322
+ 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];
327
+
328
+ return matches(value, object[key]);
329
+ });
330
+ });
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
+
346
+ function _defineProperty(obj, key, value) {
347
+ if (key in obj) {
348
+ Object.defineProperty(obj, key, {
349
+ value: value,
350
+ enumerable: true,
351
+ configurable: true,
352
+ writable: true
353
+ });
354
+ } else {
355
+ obj[key] = value;
356
+ }
357
+
358
+ return obj;
359
+ }
360
+
361
+ 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
+
363
+ 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) {
365
+ return array.filter(function (item) {
366
+ return item.id !== id;
367
+ });
368
+ });
369
+ var findById = ramda.curry(function (id, array) {
370
+ return array.find(function (item) {
371
+ return item.id === id;
372
+ });
373
+ });
374
+ var replaceById = ramda.curry(function (id, newItem, array) {
375
+ return array.map(function (item) {
376
+ return item.id === id ? newItem : item;
377
+ });
378
+ });
379
+ var modifyById = ramda.curry(function (id, modifier, array) {
380
+ return array.map(function (item) {
381
+ return item.id === id ? modifier(item) : item;
382
+ });
383
+ });
384
+ var findBy = ramda.curry(function (pattern, array) {
385
+ return array.find(matches(pattern));
386
+ });
387
+ var removeBy = ramda.curry(function (pattern, array) {
388
+ return array.filter(ramda.complement(matches(pattern)));
389
+ });
390
+ var replaceBy = ramda.curry(function (pattern, newItem, array) {
391
+ return array.map(function (item) {
392
+ return matches(pattern, item) ? newItem : item;
393
+ });
394
+ });
395
+ var modifyBy = ramda.curry(function (pattern, modifier, array) {
396
+ return array.map(function (item) {
397
+ return matches(pattern, item) ? modifier(item) : item;
398
+ });
399
+ });
400
+ var existsById = ramda.curry(function (id, array) {
401
+ return array.some(function (item) {
402
+ return item.id === id;
403
+ });
404
+ });
405
+ var existsBy = ramda.curry(function (pattern, array) {
406
+ return array.some(matches(pattern));
407
+ });
408
+ var findLastBy = ramda.curry(function (pattern, array) {
409
+ return ramda.findLast(matches(pattern), array);
410
+ });
411
+ var findIndexById = ramda.curry(function (id, array) {
412
+ return array.findIndex(function (item) {
413
+ return item.id === id;
414
+ });
415
+ });
416
+ var findIndexBy = ramda.curry(function (pattern, array) {
417
+ return array.findIndex(matches(pattern));
418
+ });
419
+ var findLastIndexBy = ramda.curry(function (pattern, array) {
420
+ return ramda.findLastIndex(matches(pattern), array);
421
+ });
422
+ var filterBy = ramda.curry(function (pattern, array) {
423
+ return array.filter(matches(pattern));
424
+ });
425
+ var countBy = ramda.curry(function (pattern, array) {
426
+ return ramda.count(matches(pattern), array);
427
+ });
428
+ var copyKeys = ramda.curry(function (keyMap, objectArray) {
429
+ return objectArray.map(function (object) {
430
+ var shallowCopy = _objectSpread({}, object);
431
+
432
+ for (var source in keyMap) {
433
+ shallowCopy[keyMap[source]] = object[source];
434
+ }
435
+
436
+ return shallowCopy;
437
+ });
438
+ });
439
+ var renameKeys = ramda.curry(function (keyMap, objectArray) {
440
+ return objectArray.map(function (object) {
441
+ var shallowCopy = _objectSpread({}, object);
442
+
443
+ for (var source in keyMap) {
444
+ shallowCopy[keyMap[source]] = object[source];
445
+ delete shallowCopy[source];
446
+ }
447
+
448
+ return shallowCopy;
449
+ });
450
+ });
451
+ var copyKeysDeep = ramda.curry(function (keyMap, objectArray) {
452
+ var copyKeysSingleObject = function copyKeysSingleObject(object, keyMap) {
453
+ var root = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : object;
454
+ return _objectSpread(_objectSpread({}, object), ramda.fromPairs(ramda.toPairs(keyMap).map(function (_ref) {
455
+ var _ref2 = _slicedToArray(_ref, 2),
456
+ destination = _ref2[0],
457
+ source = _ref2[1];
458
+
459
+ if (typeof source === "function") {
460
+ return [destination, source(object[destination], root)];
461
+ } else if (Array.isArray(source)) {
462
+ return [destination, ramda.path(source, root)];
463
+ } else if (_typeof(source) === "object") {
464
+ return [destination, copyKeysSingleObject(object[destination], source, root)];
465
+ }
466
+
467
+ return [destination, object[source]];
468
+ })));
469
+ };
470
+
471
+ return objectArray.map(function (object) {
472
+ return copyKeysSingleObject(object, keyMap);
473
+ });
474
+ });
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) {
515
+ return x !== y;
516
+ });
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
+ */
573
+
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);
581
+ };
582
+ /**
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
587
+ */
588
+
589
+ const matchesAny = require$$0.curry((obj, list) => list.some(matches_1(require$$0.__, obj)));
590
+ /**
591
+ * Checks if the given pattern exists somewhere deep inside
592
+ * the given object-tree by partial object matching.
593
+ *
594
+ * @param {Object} obj the object tree to check
595
+ * @param {Object} pattern the pattern to match partially
596
+ */
597
+
598
+ const patternExistsDeep = (obj, pattern) => {
599
+ if (typeof obj !== "object" || require$$0.isNil(obj)) return false;
600
+ if (matches_1(pattern, obj)) return true;
601
+ return Object.entries(obj).some(([key, value]) => {
602
+ if (key === "parent") return false;
603
+ return patternExistsDeep(value, pattern);
604
+ });
605
+ };
606
+
607
+ const AWAIT_DECLARATION_PATTERN = {
608
+ type: TYPES.VARIABLE_DECLARATOR,
609
+ init: {
610
+ type: TYPES.AWAIT_EXPRESSION
611
+ }
612
+ };
613
+ const IDENTIFIER_PATTERN = {
614
+ type: TYPES.IDENTIFIER
615
+ };
616
+
617
+ const isDefaultValueNode = node => {
618
+ var _node$parent, _node$parent$right;
619
+
620
+ 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
+ };
622
+
623
+ const getChildCode = (context, nodes, pathArray) => nodes.map(node => getCode(context, require$$0.path(pathArray, node))).join(", ");
624
+ const getIdentifiersInNode = node => findMatchingNodesDeep(node, IDENTIFIER_PATTERN).filter(node => !(isKeyNode(node) || isDefaultValueNode(node) || node.parent.computed)); // id from const { id : orgID } = ...
625
+
626
+ const isKeyNode = node => {
627
+ var _node$parent2;
628
+
629
+ return node === ((_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.key);
630
+ };
631
+
632
+ const areAwaitsSubsequent = (awaitParent, subsequentAwaits, functionBody) => {
633
+ var _last, _last2;
634
+
635
+ if (subsequentAwaits.length === 0) return false;
636
+ 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()
638
+
639
+ const areBothAwaitsInSameLine = functionBody[currentNodeIndex] === ((_last2 = require$$0.last(subsequentAwaits)) === null || _last2 === void 0 ? void 0 : _last2.parent);
640
+ return isPrevLineSameAsLastAwait || areBothAwaitsInSameLine;
641
+ };
642
+
643
+ const identifiersUsed = (node, identifiers) => identifiers.length > 0 && identifiers.some(identifier => findMatchingNodesDeep(node, { ...IDENTIFIER_PATTERN,
644
+ name: identifier.name
645
+ }).some(node => !isKeyNode(node)));
646
+
647
+ const getIndependentAwaits = functionNode => {
648
+ const awaitDeclarations = findMatchingNodesDeep(functionNode, AWAIT_DECLARATION_PATTERN);
649
+ if (awaitDeclarations.length < 2) return [];
650
+ const listOfSubsequentAwaits = [];
651
+ let subsequentAwaits = [];
652
+ let identifiers = [];
653
+ awaitDeclarations.forEach(awaitDeclaration => {
654
+ const isIndependent = !identifiersUsed(awaitDeclaration.init, identifiers);
655
+ const isSubsequent = areAwaitsSubsequent(awaitDeclaration.parent, subsequentAwaits, functionNode.body.body);
656
+
657
+ if (isSubsequent && isIndependent) {
658
+ subsequentAwaits.push(awaitDeclaration);
659
+ identifiers = identifiers.concat(getIdentifiersInNode(awaitDeclaration.id));
660
+ } else {
661
+ if (subsequentAwaits.length > 1) {
662
+ listOfSubsequentAwaits.push(subsequentAwaits);
663
+ }
664
+
665
+ subsequentAwaits = [awaitDeclaration];
666
+ identifiers = getIdentifiersInNode(awaitDeclaration.id);
667
+ }
668
+ });
669
+
670
+ if (subsequentAwaits.length > 1) {
671
+ listOfSubsequentAwaits.push(subsequentAwaits);
672
+ }
673
+
674
+ return listOfSubsequentAwaits;
675
+ };
676
+
677
+ const reportIndependentAwaits = (context, nodes) => {
678
+ const calls = getChildCode(context, nodes, ["init", "argument"]);
679
+ const ids = getChildCode(context, nodes, ["id"]);
680
+ const fix = `[${ids}] = await Promise.all([${calls}])`;
681
+ const fixRange = [nodes[0].range[0], require$$0.last(nodes).range[1]];
682
+ context.report({
683
+ loc: {
684
+ start: nodes[0].parent.loc.start,
685
+ end: require$$0.last(nodes).loc.end
686
+ },
687
+ message: COMBINE_MULTIPLE_INDEPENDENT_AWAITS_MESSAGE,
688
+ fix: fixer => fixer.replaceTextRange(fixRange, fix)
689
+ });
690
+ };
691
+
692
+ const checkAndReport$4 = (context, node) => {
693
+ if (!node.async) return;
694
+ const subsequentAwaits = getIndependentAwaits(node);
695
+ if (subsequentAwaits.length === 0) return;
696
+ subsequentAwaits.forEach(nodes => reportIndependentAwaits(context, nodes));
697
+ };
698
+
699
+ var combineMultipleIndependentAwaits = {
700
+ meta: {
701
+ type: "problem",
702
+ docs: {
703
+ description: "Multiple independent awaits should be combined to a single Promise.all call"
704
+ },
705
+ fixable: "code"
706
+ },
707
+ create: context => ({
708
+ // const sum = (a, b) => a + b;
709
+ ArrowFunctionExpression(node) {
710
+ checkAndReport$4(context, node);
711
+ },
712
+
713
+ // const sum = function (a, b) { return a + b };
714
+ FunctionExpression(node) {
715
+ checkAndReport$4(context, node);
716
+ },
717
+
718
+ // function sum (a, b) { return a + b };
719
+ FunctionDeclaration(node) {
720
+ checkAndReport$4(context, node);
721
+ }
722
+
723
+ })
724
+ };
725
+
726
+ const CONSTANT_CASE_PATTERN = /^[A-Z0-9_]*$/;
727
+ const CONSTANTS_FILES = [/.*constants.js$/i, /app\/javascript\/src\/common\/urls.js$/];
728
+
729
+ const isConstantsFile = context => CONSTANTS_FILES.some(filePath => filePath.test(path__default["default"].resolve(context.getFilename())));
730
+
731
+ var noDanglingConstants = {
732
+ meta: {
733
+ type: "suggestion",
734
+ docs: {
735
+ description: "Indicates that any constant outside a constant.js file should be moved to a constant.js file."
736
+ }
737
+ },
738
+ create: context => ({
739
+ VariableDeclaration(node) {
740
+ if (node.kind !== "const") return;
741
+ if (isConstantsFile(context)) return;
742
+ const constantName = node.declarations[0].id.name;
743
+
744
+ if (CONSTANT_CASE_PATTERN.test(constantName)) {
745
+ context.report(node, moveToConstantsJs(constantName));
746
+ }
747
+ }
748
+
749
+ })
750
+ };
751
+
752
+ const isDefinedInFile = (node, levels) => [TYPES.PROGRAM, TYPES.EXPORT_NAMED_DECLARATION].includes(require$$0.path(require$$0.repeat("parent", levels), node).type);
753
+
754
+ const checkAndReport$3 = (context, node, levels = 3) => {
755
+ if (!(isConstantsFile(context) && isDefinedInFile(node, levels))) return;
756
+ context.report({
757
+ node,
758
+ message: NO_DANGLING_FUNCTIONS_MESSAGE
759
+ });
760
+ };
761
+
762
+ var noDanglingFunctions = {
763
+ meta: {
764
+ type: "problem",
765
+ docs: {
766
+ description: "Prevents exporting functions from the constants files."
767
+ }
768
+ },
769
+ create: context => ({
770
+ // const sum = (a, b) => a + b;
771
+ ArrowFunctionExpression(node) {
772
+ checkAndReport$3(context, node);
773
+ },
774
+
775
+ // const sum = function (a, b) { return a + b };
776
+ FunctionExpression(node) {
777
+ checkAndReport$3(context, node);
778
+ },
779
+
780
+ // function sum (a, b) { return a + b };
781
+ FunctionDeclaration(node) {
782
+ checkAndReport$3(context, node, 1);
783
+ },
784
+
785
+ // const sum = Function("a", "b", "return a + b");
786
+ CallExpression(node) {
787
+ if (node.callee.name !== "Function") return;
788
+ checkAndReport$3(context, node);
789
+ }
790
+
791
+ })
792
+ };
793
+
794
+ 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, "");
795
+
796
+ const checkCaseAndReport = ({
797
+ context,
798
+ name,
799
+ node
800
+ }) => {
801
+ if (CONSTANT_CASE_PATTERN.test(name)) return;
802
+ context.report({
803
+ node,
804
+ message: useConstantCaseFor(name),
805
+ suggest: [{
806
+ desc: `Replace ${getCode(context, node)} with ${toConstantCase(name)}`,
807
+ fix: fixer => fixer.replaceText(node, toConstantCase(name))
808
+ }]
809
+ });
810
+ };
811
+
812
+ const checkExportAndReport = ({
813
+ context,
814
+ exported,
815
+ local,
816
+ node,
817
+ statement
818
+ }) => {
819
+ if (CONSTANT_CASE_PATTERN.test(exported.name)) return;
820
+ context.report({
821
+ node,
822
+ message: useConstantCaseFor(exported.name),
823
+ suggest: [{
824
+ desc: `Replace ${getCode(context, node)} with ${toConstantCase(exported.name)}`,
825
+ fix: fixer => {
826
+ const newName = toConstantCase(exported.name);
827
+
828
+ if (local.name === exported.name) {
829
+ return fixer.replaceText(statement, newName);
830
+ }
831
+
832
+ if (local.name === newName) {
833
+ return fixer.replaceText(statement, local.name);
834
+ }
835
+
836
+ return fixer.replaceText(exported, newName);
837
+ }
838
+ }]
839
+ });
840
+ };
841
+
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;
853
+
854
+ if (!isConstantsFile(context)) return;
855
+
856
+ if (((_node$declaration = node.declaration) === null || _node$declaration === void 0 ? void 0 : _node$declaration.kind) === "const") {
857
+ var _node$declaration2;
858
+
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
+ }
870
+
871
+ id.properties.forEach(statement => {
872
+ checkExportAndReport({
873
+ context,
874
+ exported: statement.value,
875
+ local: statement.key,
876
+ node,
877
+ statement
878
+ });
879
+ });
880
+ });
881
+ } 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
+ });
895
+ }
896
+ }
897
+
898
+ })
899
+ };
900
+
901
+ const ASSIGNMENT_PATTERNS = [{
902
+ id: {
903
+ type: "ObjectPattern"
904
+ }
905
+ }, {
906
+ id: {
907
+ type: "Identifier"
908
+ }
909
+ }];
910
+ const IDENTIFIER_INITIALIZATION_PATTERN = {
911
+ type: "Identifier",
912
+ name: "globalProps"
913
+ };
914
+ const MEMBER_EXPRESSION_INITIALIZATION_PATTERN = {
915
+ type: "MemberExpression",
916
+ object: {
917
+ type: "Identifier",
918
+ name: "globalProps"
919
+ }
920
+ };
921
+ const GLOBALPROPS_REASSIGNMENT_PATTERN = {
922
+ type: "Identifier",
923
+ name: "globalProps"
924
+ };
925
+
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);
931
+ }
932
+ };
933
+
934
+ var noGlobalPropsDestructure = {
935
+ meta: {
936
+ type: "problem",
937
+ docs: {
938
+ description: "Disallows destructuring of globalProps."
939
+ }
940
+ },
941
+ create: context => ({
942
+ VariableDeclarator(node) {
943
+ if (!matchesAny(node, ASSIGNMENT_PATTERNS)) return;
944
+ checkAssignment(context, node.init);
945
+ },
946
+
947
+ AssignmentExpression: node => checkAssignment(context, node.right)
948
+ })
949
+ };
950
+
951
+ var noGlobalPropsReassignment = {
952
+ meta: {
953
+ type: "problem",
954
+ docs: {
955
+ description: "Disallows re-assignment of globalProps."
956
+ }
957
+ },
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
+ })
966
+ };
967
+
968
+ var noAxiosImportOutsideApis = {
969
+ meta: {
970
+ type: "problem",
971
+ docs: {
972
+ description: `Axios should only be imported and used inside scripts within "${APIS_DIRECTORY}"`
973
+ }
974
+ },
975
+ create: context => ({
976
+ ImportDeclaration(node) {
977
+ // Do not replace this with `isInsideApisDirectory` since this rule should include axios.js
978
+ // `isInsideApisDirectory` returns false for apis/axios.js
979
+ const apisFolder = path__default["default"].resolve(APIS_DIRECTORY);
980
+ if (context.getFilename().startsWith(apisFolder)) return;
981
+ if (!isPackageImported(context, node, "axios")) return;
982
+ context.report(node, NO_AXIOS_IMPORT_OUTSIDE_APIS_MESSAGE);
983
+ }
984
+
985
+ })
986
+ };
987
+
988
+ var noBlacklistedImports = {
989
+ meta: {
990
+ type: "problem",
991
+ docs: {
992
+ description: "Prevents importing certain packages"
993
+ }
994
+ },
995
+ create: context => ({
996
+ ImportDeclaration(node) {
997
+ const disallowSources = getPackagesAndAliases(context, BLACKLISTED_PACKAGES);
998
+ if (!disallowSources.includes(node.source.value)) return;
999
+ context.report({
1000
+ node,
1001
+ message: disallowUse(node.source.value)
1002
+ });
1003
+ }
1004
+
1005
+ })
1006
+ };
1007
+
1008
+ const nonDefaultParam = ({
1009
+ type
1010
+ }) => type !== TYPES.ASSIGNMENT_PATTERN;
1011
+
1012
+ const containsExcessArguments = (params, isApiAction) => {
1013
+ const noOfParams = require$$0.count(nonDefaultParam, params);
1014
+ return isApiAction ? noOfParams > API_ACTIONS_ARGUMENT_LIMIT : noOfParams > ARGUMENT_LIMIT;
1015
+ };
1016
+
1017
+ const getParamList = (context, params) => params.map(param => getCode(context, param)).join(", ");
1018
+
1019
+ const checkAndReport$2 = (context, params) => {
1020
+ const isApiAction = isInsideApisDirectory(context);
1021
+ if (!containsExcessArguments(params, isApiAction)) return;
1022
+ const loc = {
1023
+ start: params[0].loc.start,
1024
+ end: require$$0.last(params).loc.end
1025
+ };
1026
+ const messages = isApiAction ? [NO_EXCESS_API_ACTION_ARGUMENTS_MESSAGE] : [NO_EXCESS_FUNCTION_ARGUMENTS_MESSAGE];
1027
+ const containsUnfixableParam = params.some(({
1028
+ type
1029
+ }) => !FIXABLE_PARAMETER_TYPES.includes(type));
1030
+
1031
+ if (!containsUnfixableParam) {
1032
+ messages.push(replaceWith(`{ ${getParamList(context, params)} }`));
1033
+ }
1034
+
1035
+ context.report({
1036
+ loc,
1037
+ message: messages.join(". ")
1038
+ });
1039
+ };
1040
+
1041
+ var noExcessFunctionArguments = {
1042
+ meta: {
1043
+ type: "problem",
1044
+ docs: {
1045
+ description: "Prevents the usage of too many arguments in a single function"
1046
+ }
1047
+ },
1048
+ create: context => ({
1049
+ // const sum = (a, b) => a + b;
1050
+ ArrowFunctionExpression(node) {
1051
+ checkAndReport$2(context, node.params);
1052
+ },
1053
+
1054
+ // const sum = function (a, b) { return a + b };
1055
+ FunctionExpression(node) {
1056
+ checkAndReport$2(context, node.params);
1057
+ },
1058
+
1059
+ // function sum (a, b) { return a + b };
1060
+ FunctionDeclaration(node) {
1061
+ checkAndReport$2(context, node.params);
1062
+ }
1063
+
1064
+ })
1065
+ };
1066
+
1067
+ const LOCALIZATION_CALL_PATTERNS = [{
1068
+ callee: {
1069
+ type: "Identifier",
1070
+ name: "t"
1071
+ },
1072
+ arguments: [{
1073
+ type: "Literal"
1074
+ }]
1075
+ }, {
1076
+ callee: {
1077
+ type: "MemberExpression",
1078
+ property: {
1079
+ type: "Identifier",
1080
+ name: "t"
1081
+ }
1082
+ },
1083
+ arguments: [{
1084
+ type: "Literal"
1085
+ }]
1086
+ }];
1087
+
1088
+ const i18next = require$$0.memoizeWith(() => "", () => require("i18next"));
1089
+
1090
+ const isKeyMissing = ({
1091
+ config,
1092
+ content,
1093
+ key
1094
+ }) => {
1095
+ const translationExists = i18next().exists(key, config);
1096
+ if (!translationExists) return true;
1097
+ const translation = i18next().t(key, config);
1098
+ return typeof require$$0.path(translation.exactUsedKey.split("."), content) !== "string";
1099
+ };
1100
+
1101
+ const checkAndReport$1 = ({
1102
+ context,
1103
+ node,
1104
+ key,
1105
+ config
1106
+ }) => {
1107
+ var _config$context, _config$count;
1108
+
1109
+ const skipContext = config.context && config.context.type !== TYPES.LITERAL;
1110
+ const skipCount = config.count && config.count.type !== TYPES.LITERAL;
1111
+ if (skipCount || skipContext) return;
1112
+ config.context = (_config$context = config.context) === null || _config$context === void 0 ? void 0 : _config$context.value;
1113
+ config.count = (_config$count = config.count) === null || _config$count === void 0 ? void 0 : _config$count.value; // @ts-ignore
1114
+
1115
+ i18next().init({
1116
+ resources: getResources(context),
1117
+ interpolation: {
1118
+ escapeValue: false,
1119
+ skipOnVariables: false
1120
+ },
1121
+ returnDetails: true
1122
+ });
1123
+ const translationFiles = context.options;
1124
+ const missingFile = translationFiles.find(({
1125
+ lng,
1126
+ content
1127
+ }) => isKeyMissing({
1128
+ config: { ...config,
1129
+ lng
1130
+ },
1131
+ content,
1132
+ key
1133
+ }));
1134
+
1135
+ if (missingFile) {
1136
+ context.report({
1137
+ node,
1138
+ message: unableToResolveKey({
1139
+ key,
1140
+ fileName: missingFile.name
1141
+ })
1142
+ });
1143
+ }
1144
+ };
1145
+
1146
+ const findAttribute = (attrName, node) => node.attributes.find(({
1147
+ name
1148
+ }) => name.name === attrName);
1149
+
1150
+ const getResources = context => context.options.reduce((acc, {
1151
+ lng,
1152
+ content
1153
+ }) => {
1154
+ acc[lng] = {
1155
+ translation: content
1156
+ };
1157
+ return acc;
1158
+ }, {});
1159
+
1160
+ const getObjectPropValue = (argument, key) => {
1161
+ var _argument$properties$;
1162
+
1163
+ return (_argument$properties$ = argument.properties.find(prop => prop.key.name === key)) === null || _argument$properties$ === void 0 ? void 0 : _argument$properties$.value;
1164
+ };
1165
+
1166
+ var noMissingLocalization = {
1167
+ meta: {
1168
+ type: "problem",
1169
+ docs: {
1170
+ description: "Warns when a translation key is missing in any of the translation files."
1171
+ }
1172
+ },
1173
+ create: context => ({
1174
+ CallExpression(node) {
1175
+ var _node$arguments$;
1176
+
1177
+ if (!matchesAny(node, LOCALIZATION_CALL_PATTERNS)) return;
1178
+ const config = {};
1179
+
1180
+ if (((_node$arguments$ = node.arguments[1]) === null || _node$arguments$ === void 0 ? void 0 : _node$arguments$.type) === TYPES.OBJECT_EXPRESSION) {
1181
+ config.count = getObjectPropValue(node.arguments[1], "count");
1182
+ config.context = getObjectPropValue(node.arguments[1], "context");
1183
+ }
1184
+
1185
+ checkAndReport$1({
1186
+ key: node.arguments[0].value,
1187
+ context,
1188
+ node,
1189
+ config
1190
+ });
1191
+ },
1192
+
1193
+ JSXOpeningElement(node) {
1194
+ var _countAttribute$value;
1195
+
1196
+ if (node.name.name !== "Trans") return;
1197
+ const i18nKey = findAttribute("i18nKey", node);
1198
+ if (!i18nKey) return;
1199
+ const countAttribute = findAttribute("count", node);
1200
+ const contextAttribute = findAttribute("context", node);
1201
+ const config = {
1202
+ count: countAttribute === null || countAttribute === void 0 ? void 0 : (_countAttribute$value = countAttribute.value) === null || _countAttribute$value === void 0 ? void 0 : _countAttribute$value.expression,
1203
+ context: contextAttribute === null || contextAttribute === void 0 ? void 0 : contextAttribute.value
1204
+ };
1205
+ const keyNode = i18nKey.value;
1206
+ if (keyNode.type !== TYPES.LITERAL) return;
1207
+ checkAndReport$1({
1208
+ key: keyNode.value,
1209
+ context,
1210
+ node,
1211
+ config
1212
+ });
1213
+ }
1214
+
1215
+ })
1216
+ };
1217
+
1218
+ const RAMDA_NAMESPACE_IMPORT_PATTERN = {
1219
+ specifiers: [{
1220
+ type: "ImportNamespaceSpecifier",
1221
+ local: {
1222
+ type: "Identifier"
1223
+ }
1224
+ }],
1225
+ source: {
1226
+ type: "Literal",
1227
+ value: "ramda"
1228
+ }
1229
+ };
1230
+
1231
+ const ramdaUsage = identifierName => ({
1232
+ type: "MemberExpression",
1233
+ object: {
1234
+ name: identifierName,
1235
+ type: "Identifier"
1236
+ }
1237
+ });
1238
+
1239
+ const findAllRamdaUsage = (node, identifierName, acc = []) => {
1240
+ if (!node || typeof node !== "object") return acc;
1241
+ return Object.entries(node).reduce((acc, [key, value]) => {
1242
+ if (key === "parent") return acc;
1243
+ if (matches_1(ramdaUsage(identifierName), value)) return [...acc, value];
1244
+ return findAllRamdaUsage(value, identifierName, acc);
1245
+ }, acc);
1246
+ };
1247
+
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(", "));
1249
+ var noNamespaceSpecifierImportForRamda = {
1250
+ meta: {
1251
+ type: "problem",
1252
+ docs: {
1253
+ description: "Prevents using Namespace Specifier import method for Ramda"
1254
+ },
1255
+ fixable: "code"
1256
+ },
1257
+ create: context => ({
1258
+ ImportDeclaration: node => {
1259
+ if (matches_1(RAMDA_NAMESPACE_IMPORT_PATTERN, node)) {
1260
+ const allRUsages = findAllRamdaUsage(node.parent.body, node.specifiers[0].local.name);
1261
+ const ramdaMethodsUsed = gatherMethods(allRUsages);
1262
+ context.report({
1263
+ node,
1264
+ message: NO_NAMESPACE_SPECIFIER_IMPORT_FOR_RAMDA_MESSAGE,
1265
+ fix: fixer => {
1266
+ const importFixer = fixer.replaceText(node.specifiers[0], `{ ${ramdaMethodsUsed} }`);
1267
+ const methodFixers = allRUsages.map(node => fixer.replaceText(node, node.property.name));
1268
+ return [importFixer, ...methodFixers];
1269
+ }
1270
+ });
1271
+ }
1272
+ }
1273
+ })
1274
+ };
1275
+
1276
+ const SPECIAL_CHARS_PATTERN = /^ +| +$|[\r\n\t\f\v&<>{}"'`\\]+/;
1277
+
1278
+ const isReplaceableLiteral = node => node.expression.type === TYPES.LITERAL && typeof node.expression.value === "string" && !SPECIAL_CHARS_PATTERN.test(node.expression.value);
1279
+
1280
+ var noRedundantJsxExpression = {
1281
+ meta: {
1282
+ type: "problem",
1283
+ docs: {
1284
+ description: "Suggests using strings directly instead of wrapping it in a JSX expression (i.e. curly braces), provided there is no string interpolation"
1285
+ },
1286
+ fixable: "code"
1287
+ },
1288
+ create: context => ({
1289
+ JSXExpressionContainer(node) {
1290
+ if (!isReplaceableLiteral(node)) return;
1291
+ let fix = "";
1292
+
1293
+ if (node.parent.type === TYPES.JSX_ELEMENT) {
1294
+ fix = node.expression.value;
1295
+ } else if (node.parent.type === TYPES.JSX_ATTRIBUTE) {
1296
+ fix = node.expression.raw;
1297
+ } else {
1298
+ return;
1299
+ }
1300
+
1301
+ context.report({
1302
+ node,
1303
+ message: canBeReplacedWith(fix),
1304
+ fix: fixer => fixer.replaceText(node, fix)
1305
+ });
1306
+ }
1307
+
1308
+ })
1309
+ };
1310
+
1311
+ const CHARACTERS_TO_IGNORE_PATTERN = /[\r\n\t\f\v&><}"{'`\\]/;
1312
+ const ENDS_WITH_SPACES_PATTERN = / +$/;
1313
+ const STARTS_OR_ENDS_WITH_SPACES_PATTERN = /^ +| +$/;
1314
+ const STARTS_WITH_SPACES_PATTERN = /^ +/;
1315
+
1316
+ const doQusisHaveSpecialCharacters = ({
1317
+ quasis
1318
+ }) => quasis.some(quasi => quasi.value.cooked.match(CHARACTERS_TO_IGNORE_PATTERN));
1319
+
1320
+ const getTemplateContent = (context, {
1321
+ expressions,
1322
+ quasis
1323
+ }) => expressions.reduce((acc, expression, index) => {
1324
+ const expressionCode = getCode(context, expression);
1325
+ const quasi = quasis[index + 1].value.cooked;
1326
+ return `${acc}{${expressionCode}}${quasi}`;
1327
+ }, `${quasis[0].value.cooked}`);
1328
+
1329
+ const isExpressionOnly = node => node.expressions.length === 1 && node.quasis.length === 2 && node.quasis[0].value.cooked === "" && node.quasis[1].value.cooked === "";
1330
+
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);
1332
+
1333
+ const isReplaceableQuasiOnly = node => node.expressions.length === 0 && node.quasis.length === 1 && !node.quasis[0].value.cooked.match(STARTS_OR_ENDS_WITH_SPACES_PATTERN);
1334
+
1335
+ var noRedundantStringTemplates = {
1336
+ meta: {
1337
+ type: "problem",
1338
+ docs: {
1339
+ description: "Prevent usage of string templates as direct children of JSX components."
1340
+ },
1341
+ fixable: "code"
1342
+ },
1343
+ create: context => ({
1344
+ TemplateLiteral(node) {
1345
+ if (doQusisHaveSpecialCharacters(node)) return;
1346
+
1347
+ if (isExpressionOnly(node)) {
1348
+ const fix = getCode(context, node.expressions[0]);
1349
+ context.report({
1350
+ node,
1351
+ message: canBeReplacedWith(fix),
1352
+ fix: fixer => fixer.replaceText(node, fix)
1353
+ });
1354
+ } else if (isInsideJSXElement(node)) {
1355
+ const fix = getTemplateContent(context, node);
1356
+ context.report({
1357
+ node,
1358
+ message: canBeReplacedWith(fix),
1359
+ fix: fixer => fixer.replaceText(node.parent, fix)
1360
+ });
1361
+ } else if (isReplaceableQuasiOnly(node)) {
1362
+ const fix = `"${node.quasis[0].value.cooked}"`;
1363
+ context.report({
1364
+ node,
1365
+ message: canBeReplacedWith(fix),
1366
+ fix: fixer => fixer.replaceText(node, fix)
1367
+ });
1368
+ }
1369
+ }
1370
+
1371
+ })
1372
+ };
1373
+
1374
+ const NEETO_PACKAGES = ["@bigbinary/neetoui", "@bigbinary/neeto-icons"];
1375
+
1376
+ const importedFromNeeto = (context, node) => getPackagesAndAliases(context, NEETO_PACKAGES).includes(node.source.value);
1377
+
1378
+ var prefixNeetoUIImportAlias = {
1379
+ meta: {
1380
+ type: "problem",
1381
+ docs: {
1382
+ description: PREFIX_NEETO_UI_IMPORT_ALIAS_MESSAGE,
1383
+ schema: {
1384
+ type: "object",
1385
+ description: "An object mapping aliases to paths.",
1386
+ patternProperties: {
1387
+ "*": {
1388
+ type: "string"
1389
+ }
1390
+ }
1391
+ }
1392
+ }
1393
+ },
1394
+ create: context => ({
1395
+ ImportSpecifier(node) {
1396
+ if (node.imported.name === node.local.name) return;
1397
+ if (!importedFromNeeto(context, node.parent)) return;
1398
+ if (node.local.name.startsWith("NeetoUI")) return;
1399
+ context.report({
1400
+ node,
1401
+ message: PREFIX_NEETO_UI_IMPORT_ALIAS_MESSAGE
1402
+ });
1403
+ }
1404
+
1405
+ })
1406
+ };
1407
+
1408
+ const ARRAY_INSERTS_PATTERN = {
1409
+ APPEND: {
1410
+ // x => [...x, y]
1411
+ params: [{
1412
+ type: "Identifier"
1413
+ }],
1414
+ body: {
1415
+ type: "ArrayExpression",
1416
+ elements: [{
1417
+ type: "SpreadElement",
1418
+ argument: {
1419
+ type: "Identifier"
1420
+ }
1421
+ }]
1422
+ }
1423
+ },
1424
+ PREPEND: {
1425
+ // x => [y, ...x]
1426
+ params: [{
1427
+ type: "Identifier"
1428
+ }],
1429
+ body: {
1430
+ type: "ArrayExpression",
1431
+ elements: {
1432
+ 1: {
1433
+ type: "SpreadElement",
1434
+ argument: {
1435
+ type: "Identifier"
1436
+ }
1437
+ }
1438
+ }
1439
+ }
1440
+ },
1441
+ CONCAT: {
1442
+ // x => [...x, ...y]
1443
+ params: [{
1444
+ type: "Identifier"
1445
+ }],
1446
+ body: {
1447
+ type: "ArrayExpression",
1448
+ elements: [{
1449
+ type: "SpreadElement",
1450
+ argument: {
1451
+ type: "Identifier"
1452
+ }
1453
+ }, {
1454
+ type: "SpreadElement"
1455
+ }]
1456
+ }
1457
+ }
1458
+ };
1459
+ const ASSOC_PATTERN = {
1460
+ // x => ({ ...x, y: 10 })
1461
+ params: [{
1462
+ type: "Identifier"
1463
+ }],
1464
+ body: {
1465
+ type: "ObjectExpression",
1466
+ properties: [{
1467
+ type: "SpreadElement",
1468
+ argument: {
1469
+ type: "Identifier"
1470
+ }
1471
+ }, {
1472
+ type: "Property"
1473
+ }]
1474
+ }
1475
+ };
1476
+ const JSON_EQUALS_PATTERN = {
1477
+ // JSON.stringify(x) === JSON.stringify(y)
1478
+ left: {
1479
+ type: "CallExpression",
1480
+ callee: {
1481
+ type: "MemberExpression",
1482
+ object: {
1483
+ type: "Identifier",
1484
+ name: "JSON"
1485
+ },
1486
+ property: {
1487
+ type: "Identifier",
1488
+ name: "stringify"
1489
+ }
1490
+ }
1491
+ },
1492
+ right: {
1493
+ type: "CallExpression",
1494
+ callee: {
1495
+ type: "MemberExpression",
1496
+ object: {
1497
+ type: "Identifier",
1498
+ name: "JSON"
1499
+ },
1500
+ property: {
1501
+ type: "Identifier",
1502
+ name: "stringify"
1503
+ }
1504
+ }
1505
+ },
1506
+ operator: "==="
1507
+ };
1508
+ const IDENTITY_PATTERN = {
1509
+ // item => item
1510
+ generator: false,
1511
+ async: false,
1512
+ expression: true,
1513
+ params: [{
1514
+ type: "Identifier"
1515
+ }],
1516
+ body: {
1517
+ type: "Identifier"
1518
+ }
1519
+ };
1520
+ const MERGE_PATTERNS = [{
1521
+ // x => ({ ...x, y: 10, z: 11 })
1522
+ params: [{
1523
+ type: "Identifier"
1524
+ }],
1525
+ body: {
1526
+ type: "ObjectExpression",
1527
+ properties: [{
1528
+ type: "SpreadElement",
1529
+ argument: {
1530
+ type: "Identifier"
1531
+ }
1532
+ }, {
1533
+ type: "Property"
1534
+ }, {
1535
+ type: "Property"
1536
+ }]
1537
+ }
1538
+ }, {
1539
+ // x => ({ ...x, y: 10, ...z })
1540
+ params: [{
1541
+ type: "Identifier"
1542
+ }],
1543
+ body: {
1544
+ type: "ObjectExpression",
1545
+ properties: [{
1546
+ type: "SpreadElement",
1547
+ argument: {
1548
+ type: "Identifier"
1549
+ }
1550
+ }, {
1551
+ type: "Property"
1552
+ }, {
1553
+ type: "SpreadElement"
1554
+ }]
1555
+ }
1556
+ }, {
1557
+ // x => ({ ...x, ...y })
1558
+ params: [{
1559
+ type: "Identifier"
1560
+ }],
1561
+ body: {
1562
+ type: "ObjectExpression",
1563
+ properties: [{
1564
+ type: "SpreadElement",
1565
+ argument: {
1566
+ type: "Identifier"
1567
+ }
1568
+ }, {
1569
+ type: "SpreadElement"
1570
+ }]
1571
+ }
1572
+ }];
1573
+ const PLUCK_PATTERNS = {
1574
+ OBJECT_ARROW_FUNCTION: {
1575
+ callee: {
1576
+ type: "MemberExpression",
1577
+ property: {
1578
+ name: "map"
1579
+ }
1580
+ },
1581
+ arguments: [{
1582
+ type: "ArrowFunctionExpression"
1583
+ }]
1584
+ },
1585
+ IDENTIFIER: {
1586
+ // abc.map(x => x.a);
1587
+ params: [{
1588
+ type: "Identifier"
1589
+ }],
1590
+ body: {
1591
+ type: "MemberExpression",
1592
+ object: {
1593
+ type: "Identifier"
1594
+ },
1595
+ property: {
1596
+ type: "Identifier"
1597
+ }
1598
+ }
1599
+ },
1600
+ DESTRUCTURE: {
1601
+ // abc.map(({ a }) => a);
1602
+ params: [{
1603
+ type: "ObjectPattern",
1604
+ properties: [{
1605
+ type: "Property",
1606
+ key: {
1607
+ type: "Identifier"
1608
+ },
1609
+ value: {
1610
+ type: "Identifier"
1611
+ }
1612
+ }]
1613
+ }],
1614
+ body: {
1615
+ type: "Identifier"
1616
+ }
1617
+ }
1618
+ };
1619
+ const PROP_PATTERNS = {
1620
+ OBJECT: {
1621
+ // ({ property }) => property
1622
+ generator: false,
1623
+ async: false,
1624
+ expression: true,
1625
+ params: [{
1626
+ type: "ObjectPattern",
1627
+ properties: [{
1628
+ type: "Property",
1629
+ value: {
1630
+ type: "Identifier"
1631
+ }
1632
+ }]
1633
+ }],
1634
+ body: {
1635
+ type: "Identifier"
1636
+ }
1637
+ },
1638
+ IDENTITY: {
1639
+ // item => item.property
1640
+ generator: false,
1641
+ async: false,
1642
+ expression: true,
1643
+ params: [{
1644
+ type: "Identifier"
1645
+ }],
1646
+ body: {
1647
+ type: "MemberExpression",
1648
+ object: {
1649
+ type: "Identifier"
1650
+ },
1651
+ property: {
1652
+ type: "Identifier"
1653
+ }
1654
+ }
1655
+ }
1656
+ };
1657
+ const SUM_PATTERN = {
1658
+ callee: {
1659
+ type: "MemberExpression",
1660
+ property: {
1661
+ type: "Identifier",
1662
+ name: "reduce"
1663
+ }
1664
+ },
1665
+ arguments: [{
1666
+ type: "ArrowFunctionExpression",
1667
+ generator: false,
1668
+ async: false,
1669
+ expression: true,
1670
+ body: {
1671
+ type: "BinaryExpression",
1672
+ operator: "+"
1673
+ },
1674
+ params: [{
1675
+ type: "Identifier"
1676
+ }]
1677
+ }, {
1678
+ type: "Literal",
1679
+ value: 0
1680
+ }]
1681
+ };
1682
+ const RAMDA_IMPORT_PATTERN = {
1683
+ type: "ImportDeclaration",
1684
+ source: {
1685
+ type: "Literal",
1686
+ value: "ramda"
1687
+ },
1688
+ specifiers: [{
1689
+ type: "ImportSpecifier"
1690
+ }]
1691
+ }; // when ({ name }) => name is used inside something.map(...), ignore it.
1692
+ // It will be picked up by pluck function
1693
+
1694
+ const PROP_IGNORE_PATTERN = {
1695
+ type: "CallExpression",
1696
+ callee: {
1697
+ type: "MemberExpression",
1698
+ property: {
1699
+ type: "Identifier",
1700
+ name: "map"
1701
+ }
1702
+ }
1703
+ };
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(", ")}, `);
1713
+ }
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
+ };
1727
+
1728
+ var arrayInsertsLintCheck = {
1729
+ operateOn: "ArrowFunctionExpression",
1730
+ check: (context, node) => {
1731
+ const {
1732
+ params,
1733
+ body
1734
+ } = node;
1735
+
1736
+ if (body.type !== TYPES.ARRAY_EXPRESSION || body.elements.length !== 2) {
1737
+ return;
1738
+ }
1739
+
1740
+ const {
1741
+ elements
1742
+ } = body;
1743
+ let fix = null;
1744
+
1745
+ if (matches_1(ARRAY_INSERTS_PATTERN.APPEND, node) && elements[1].type !== TYPES.SPREAD_ELEMENT && params[0].name === elements[0].argument.name) {
1746
+ 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) {
1748
+ fix = `prepend(${getCode(context, elements[0])})`;
1749
+ } else if (matches_1(ARRAY_INSERTS_PATTERN.CONCAT, node) && params[0].name === elements[0].argument.name) {
1750
+ fix = `concat(${getCode(context, elements[1].argument)})`;
1751
+ }
1752
+
1753
+ if (!fix) return;
1754
+ const funcName = fix.split("(")[0];
1755
+ context.report({
1756
+ node,
1757
+ message: canBeReplacedWith(fix),
1758
+ suggest: [{
1759
+ desc: `Replace with ${funcName} function`,
1760
+ fix: replaceNodeWithImports({
1761
+ context,
1762
+ node,
1763
+ fix,
1764
+ functions: funcName
1765
+ })
1766
+ }]
1767
+ });
1768
+ }
1769
+ };
1770
+
1771
+ const convertToAssoc = (context, node) => {
1772
+ const property = node.body.properties[1];
1773
+ const key = property.computed ? getCode(context, property.key) : `"${property.key.name}"`;
1774
+ return `assoc(${key}, ${getCode(context, property.value)})`;
1775
+ };
1776
+
1777
+ var assocLintCheck = {
1778
+ operateOn: "ArrowFunctionExpression",
1779
+ check: (context, node) => {
1780
+ if (node.params.length !== 1) return;
1781
+ if (!matches_1(ASSOC_PATTERN, node)) return;
1782
+ if (node.body.properties.length !== 2) return;
1783
+ if (node.body.properties[0].argument.name !== node.params[0].name) return;
1784
+ const property = node.body.properties[1];
1785
+ const selfReferencingPattern = {
1786
+ type: "Identifier",
1787
+ name: node.params[0].name
1788
+ };
1789
+ if (patternExistsDeep(property.value, selfReferencingPattern)) return;
1790
+ const fix = convertToAssoc(context, node);
1791
+ context.report({
1792
+ node,
1793
+ message: canBeReplacedWith(fix),
1794
+ suggest: [{
1795
+ desc: "Replace with assoc function",
1796
+ fix: replaceNodeWithImports({
1797
+ context,
1798
+ node,
1799
+ fix,
1800
+ functions: "assoc"
1801
+ })
1802
+ }]
1803
+ });
1804
+ }
1805
+ };
1806
+
1807
+ var equalsLintCheck = {
1808
+ operateOn: "BinaryExpression",
1809
+ check: (context, node) => {
1810
+ if (matches_1(JSON_EQUALS_PATTERN, node)) {
1811
+ const fix = `equals(${getCode(context, node.left.arguments[0])}, ${getCode(context, node.right.arguments[0])})`;
1812
+ context.report({
1813
+ node,
1814
+ message: canBeReplacedWith(fix),
1815
+ suggest: [{
1816
+ desc: "Replace with equals function",
1817
+ fix: replaceNodeWithImports({
1818
+ context,
1819
+ node,
1820
+ fix,
1821
+ functions: "equals"
1822
+ })
1823
+ }]
1824
+ });
1825
+ }
1826
+ }
1827
+ };
1828
+
1829
+ var identityLintCheck = {
1830
+ operateOn: "ArrowFunctionExpression",
1831
+ check: (context, node) => {
1832
+ if (matches_1(IDENTITY_PATTERN, node) && node.params[0].name === node.body.name) {
1833
+ context.report({
1834
+ node,
1835
+ message: canBeReplacedWith("identity"),
1836
+ suggest: [{
1837
+ desc: "Replace with identity function",
1838
+ fix: replaceNodeWithImports({
1839
+ context,
1840
+ node,
1841
+ fix: "identity",
1842
+ functions: "identity"
1843
+ })
1844
+ }]
1845
+ });
1846
+ }
1847
+ }
1848
+ };
1849
+
1850
+ const findPatternIndex = node => MERGE_PATTERNS.findIndex(matches_1(require$$0.__, node));
1851
+
1852
+ const convertToMergeLeft = (context, node) => {
1853
+ const properties = node.body.properties.slice(1);
1854
+ const matchIndex = findPatternIndex(node);
1855
+ 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]]
1857
+ })} })`;
1858
+ };
1859
+
1860
+ var mergeLintCheck = {
1861
+ operateOn: "ArrowFunctionExpression",
1862
+ check: (context, node) => {
1863
+ if (node.params.length !== 1) return;
1864
+ const matchIndex = findPatternIndex(node);
1865
+ if (matchIndex < 0) return;
1866
+ if (node.body.properties[0].argument.name !== node.params[0].name) return;
1867
+ const selfReferencingPattern = {
1868
+ type: "Identifier",
1869
+ name: node.params[0].name
1870
+ };
1871
+ const properties = node.body.properties.slice(1);
1872
+ if (patternExistsDeep(properties, selfReferencingPattern)) return;
1873
+ const fix = convertToMergeLeft(context, node);
1874
+ context.report({
1875
+ node,
1876
+ message: canBeReplacedWith(fix),
1877
+ suggest: [{
1878
+ desc: "Replace with mergeLeft function",
1879
+ fix: replaceNodeWithImports({
1880
+ context,
1881
+ node,
1882
+ fix,
1883
+ functions: "mergeLeft"
1884
+ })
1885
+ }]
1886
+ });
1887
+ }
1888
+ };
1889
+
1890
+ const reportViolation = (context, node, fix) => context.report({
1891
+ node,
1892
+ message: canBeReplacedWith(fix),
1893
+ suggest: [{
1894
+ desc: "Replace with pluck function",
1895
+ fix: replaceNodeWithImports({
1896
+ context,
1897
+ node,
1898
+ fix,
1899
+ functions: "pluck"
1900
+ })
1901
+ }]
1902
+ });
1903
+
1904
+ var pluckLintCheck = {
1905
+ operateOn: "CallExpression",
1906
+ check: (context, node) => {
1907
+ if (matches_1(PLUCK_PATTERNS.OBJECT_ARROW_FUNCTION, node)) {
1908
+ const code = getCode(context, node.callee.object);
1909
+ const func = node.arguments[0];
1910
+
1911
+ if (matches_1(PLUCK_PATTERNS.IDENTIFIER, func)) {
1912
+ if (func.params[0].name !== func.body.object.name) return;
1913
+ const fix = `pluck("${func.body.property.name}", ${code})`;
1914
+ reportViolation(context, node, fix);
1915
+ } else if (matches_1(PLUCK_PATTERNS.DESTRUCTURE, func)) {
1916
+ const propertyName = func.params[0].properties[0].value.name;
1917
+ if (propertyName !== func.body.name) return;
1918
+ const fix = `pluck("${propertyName}", ${code})`;
1919
+ reportViolation(context, node, fix);
1920
+ }
1921
+ }
1922
+ }
1923
+ };
1924
+
1925
+ var propLintCheck = {
1926
+ operateOn: "ArrowFunctionExpression",
1927
+ check: (context, node) => {
1928
+ let fix = null;
1929
+ if (matches_1(PROP_IGNORE_PATTERN, node.parent)) return;
1930
+
1931
+ if (matches_1(PROP_PATTERNS.OBJECT, node) && node.params[0].properties[0].value.name === node.body.name) {
1932
+ fix = `prop("${node.body.name}")`;
1933
+ } else if (matches_1(PROP_PATTERNS.IDENTITY, node) && node.params[0].name === node.body.object.name) {
1934
+ fix = `prop("${node.body.property.name}")`;
1935
+ } else {
1936
+ return;
1937
+ }
1938
+
1939
+ context.report({
1940
+ node,
1941
+ message: canBeReplacedWith(fix),
1942
+ suggest: [{
1943
+ desc: "Replace with prop function",
1944
+ fix: replaceNodeWithImports({
1945
+ context,
1946
+ node,
1947
+ fix,
1948
+ functions: "prop"
1949
+ })
1950
+ }]
1951
+ });
1952
+ }
1953
+ };
1954
+
1955
+ const distinguishBinaryExpression = reduceFunc => {
1956
+ const isAccumulator = node => node.type === TYPES.IDENTIFIER && node.name === reduceFunc.params[0].name;
1957
+
1958
+ if (isAccumulator(reduceFunc.body.left)) {
1959
+ return {
1960
+ accumulator: reduceFunc.body.left,
1961
+ delta: reduceFunc.body.right
1962
+ };
1963
+ }
1964
+
1965
+ if (isAccumulator(reduceFunc.body.right)) {
1966
+ return {
1967
+ accumulator: reduceFunc.body.right,
1968
+ delta: reduceFunc.body.left
1969
+ };
1970
+ }
1971
+
1972
+ return {};
1973
+ };
1974
+
1975
+ var sumLintCheck = {
1976
+ operateOn: "CallExpression",
1977
+ check: (context, node) => {
1978
+ if (!matches_1(SUM_PATTERN, node)) return;
1979
+ const reduceFunc = node.arguments[0];
1980
+ const {
1981
+ accumulator,
1982
+ delta
1983
+ } = distinguishBinaryExpression(reduceFunc);
1984
+ if (!accumulator || !delta) return;
1985
+ let fix = null;
1986
+ let functions = ["sum"];
1987
+
1988
+ if (reduceFunc.params[1].type === TYPES.IDENTIFIER && delta.type === TYPES.IDENTIFIER && delta.name === reduceFunc.params[1].name) {
1989
+ fix = `sum(${getCode(context, node.callee.object)})`;
1990
+ } else if (reduceFunc.params[1].type === TYPES.OBJECT_PATTERN && delta.type === TYPES.IDENTIFIER && delta.name === reduceFunc.params[1].properties[0].value.name) {
1991
+ fix = `sum(pluck("${delta.name}", ${getCode(context, node.callee.object)}))`;
1992
+ functions = ["sum", "pluck"];
1993
+ } 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) {
1994
+ fix = `sum(pluck("${delta.property.name}", ${getCode(context, node.callee.object)}))`;
1995
+ functions = ["sum", "pluck"];
1996
+ } else {
1997
+ return;
1998
+ }
1999
+
2000
+ context.report({
2001
+ node,
2002
+ message: canBeReplacedWith(fix),
2003
+ suggest: [{
2004
+ desc: "Replace with sum function",
2005
+ fix: replaceNodeWithImports({
2006
+ context,
2007
+ node,
2008
+ fix,
2009
+ functions
2010
+ })
2011
+ }]
2012
+ });
2013
+ }
2014
+ };
2015
+
2016
+ var ramdaTips = {
2017
+ meta: {
2018
+ type: "suggestion",
2019
+ hasSuggestions: true,
2020
+ docs: {
2021
+ description: "Provides hints for common Ramda usage patterns."
2022
+ }
2023
+ },
2024
+ 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))]));
2027
+ }
2028
+ };
2029
+
2030
+ const AXIOS_GET_PATTERN = {
2031
+ callee: {
2032
+ type: TYPES.MEMBER_EXPRESSION,
2033
+ object: {
2034
+ name: "axios",
2035
+ type: TYPES.IDENTIFIER
2036
+ },
2037
+ property: {
2038
+ name: "get",
2039
+ type: TYPES.IDENTIFIER
2040
+ }
2041
+ }
2042
+ };
2043
+ const AXIOS_PATTERN = {
2044
+ callee: {
2045
+ name: "axios",
2046
+ type: TYPES.IDENTIFIER
2047
+ }
2048
+ };
2049
+ const VALID_URL_TYPES = [TYPES.LITERAL, TYPES.TEMPLATE_LITERAL];
2050
+
2051
+ const getPropValue = (configNode, name) => {
2052
+ var _configNode$propertie;
2053
+
2054
+ return (_configNode$propertie = configNode.properties.find(({
2055
+ key
2056
+ }) => key.name === name)) === null || _configNode$propertie === void 0 ? void 0 : _configNode$propertie.value;
2057
+ };
2058
+
2059
+ const containsQuestionMark = ({
2060
+ quasis
2061
+ }) => quasis.some(({
2062
+ value
2063
+ }) => value.cooked.includes("?"));
2064
+
2065
+ const checkAndReport = ({
2066
+ context,
2067
+ node,
2068
+ urlNode
2069
+ }) => {
2070
+ const addsQueryThroughTemplate = urlNode.type === TYPES.TEMPLATE_LITERAL && containsQuestionMark(urlNode);
2071
+ const urlStringContainsQuery = urlNode.type === TYPES.LITERAL && urlNode.value.includes("?");
2072
+
2073
+ if (addsQueryThroughTemplate || urlStringContainsQuery) {
2074
+ context.report({
2075
+ node,
2076
+ message: USE_AXIOS_CONFIG_FOR_PASSING_QUERY_PARAMETERS_MESSAGE
2077
+ });
2078
+ }
2079
+ };
2080
+
2081
+ var useAxiosConfigForPassingQueryParameters = {
2082
+ meta: {
2083
+ type: "problem",
2084
+ docs: {
2085
+ description: "Enforces using the config parameter of axios to send query parameters through axios"
2086
+ }
2087
+ },
2088
+ create: context => ({
2089
+ CallExpression(node) {
2090
+ if (matches_1(AXIOS_GET_PATTERN, node)) {
2091
+ if (!VALID_URL_TYPES.includes(node.arguments[0].type)) return;
2092
+ checkAndReport({
2093
+ context,
2094
+ node,
2095
+ urlNode: node.arguments[0]
2096
+ });
2097
+ } else if (matches_1(AXIOS_PATTERN, node)) {
2098
+ var _methodNode;
2099
+
2100
+ let methodNode = null;
2101
+ let urlNode = null;
2102
+
2103
+ if (VALID_URL_TYPES.includes(node.arguments[0].type)) {
2104
+ urlNode = node.arguments[0];
2105
+ methodNode = getPropValue(node.arguments[1], "method");
2106
+ } else if (node.arguments[0].type === TYPES.OBJECT_EXPRESSION) {
2107
+ urlNode = getPropValue(node.arguments[0], "url");
2108
+ methodNode = getPropValue(node.arguments[0], "method");
2109
+ }
2110
+
2111
+ if (!urlNode) return;
2112
+
2113
+ if (((_methodNode = methodNode) === null || _methodNode === void 0 ? void 0 : _methodNode.value.toLowerCase()) !== "get") {
2114
+ return;
2115
+ }
2116
+
2117
+ if (!VALID_URL_TYPES.includes(urlNode.type)) return;
2118
+ checkAndReport({
2119
+ context,
2120
+ node,
2121
+ urlNode
2122
+ });
2123
+ }
2124
+ }
2125
+
2126
+ })
2127
+ };
2128
+
2129
+ const SNAKE_CASE_REGEX = /^[a-z0-9_]+$/;
2130
+
2131
+ const isSnakeCase = text => SNAKE_CASE_REGEX.test(text);
2132
+
2133
+ const toSnakeCase = text => text.replace("-", "_").replace(/([A-Z0-9][a-z])/g, "_$1").replace(/([a-z0-9])([A-Z0-9])/g, "$1_$2").toLowerCase().replace(/[^a-z0-9_]/g, "").replace(/^_/g, "");
2134
+
2135
+ var useSnakeCaseForApiConnectorFilename = {
2136
+ meta: {
2137
+ type: "problem",
2138
+ docs: {
2139
+ description: "Enforces API connector files to be named in snake_case"
2140
+ }
2141
+ },
2142
+ create: context => ({
2143
+ ImportDeclaration(node) {
2144
+ if (!isPackageImported(context, node, "axios")) return;
2145
+ const [fileName, extension] = getFilenameAndExtension(context);
2146
+ if (isSnakeCase(fileName)) return;
2147
+ context.report({
2148
+ node: node.parent,
2149
+ message: renameFile(`${toSnakeCase(fileName)}.${extension}`)
2150
+ });
2151
+ }
2152
+
2153
+ })
2154
+ };
2155
+
2156
+ var useWebpackAlias = {
2157
+ meta: {
2158
+ type: "suggestion",
2159
+ fixable: "code",
2160
+ docs: {
2161
+ description: "Shows import paths that can be simplified using aliases configured by webpack.",
2162
+ schema: {
2163
+ type: "object",
2164
+ description: "An object mapping aliases to paths.",
2165
+ patternProperties: {
2166
+ "*": {
2167
+ type: "string"
2168
+ }
2169
+ }
2170
+ }
2171
+ }
2172
+ },
2173
+ create: context => ({
2174
+ ImportDeclaration(node) {
2175
+ const aliases = context.options[0];
2176
+ if (require$$0.isEmpty(aliases) || require$$0.isNil(aliases)) return;
2177
+ const importPath = node.source.value;
2178
+ if (!importPath.startsWith("../")) return;
2179
+ const filename = context.getFilename();
2180
+ const importFullPath = path__default["default"].resolve(filename, "../", importPath);
2181
+ const matches = Object.entries(aliases).filter(([, path]) => importFullPath.startsWith(path)).sort((first, second) => first.length - second.length);
2182
+ if (matches.length === 0) return;
2183
+ const aliasMatch = matches[matches.length - 1];
2184
+ const importPathWithAlias = importFullPath.replace(aliasMatch[1], aliasMatch[0]);
2185
+
2186
+ if (importPath.length > importPathWithAlias.length) {
2187
+ context.report({
2188
+ node,
2189
+ message: canBeReplacedWith(importPathWithAlias),
2190
+ fix: fixer => fixer.replaceText(node.source, `"${importPathWithAlias}"`)
2191
+ });
2192
+ }
2193
+ }
2194
+
2195
+ })
2196
+ };
2197
+
2198
+ var index = {
2199
+ rules: {
2200
+ "api-connector-name-should-match-filename": apiConnectorNameShouldMatchFilename,
2201
+ "api-connector-should-use-default-export": apiConnectorShouldUseDefaultExport,
2202
+ "combine-multiple-independent-awaits": combineMultipleIndependentAwaits,
2203
+ "no-blacklisted-imports": noBlacklistedImports,
2204
+ "no-axios-import-outside-apis": noAxiosImportOutsideApis,
2205
+ "no-excess-function-arguments": noExcessFunctionArguments,
2206
+ "no-dangling-constants": noDanglingConstants,
2207
+ "no-dangling-functions": noDanglingFunctions,
2208
+ "no-globalProps-destructure": noGlobalPropsDestructure,
2209
+ "no-globalProps-reassignment": noGlobalPropsReassignment,
2210
+ "no-missing-localization": noMissingLocalization,
2211
+ "no-namespace-specifier-import-for-ramda": noNamespaceSpecifierImportForRamda,
2212
+ "no-redundant-jsx-expression": noRedundantJsxExpression,
2213
+ "no-redundant-string-templates": noRedundantStringTemplates,
2214
+ "prefix-neeto-ui-import-alias": prefixNeetoUIImportAlias,
2215
+ "ramda-tips": ramdaTips,
2216
+ "use-axios-config-for-passing-query-parameters": useAxiosConfigForPassingQueryParameters,
2217
+ "use-constant-case": useConstantCase,
2218
+ "use-snake-case-for-api-connector-filename": useSnakeCaseForApiConnectorFilename,
2219
+ "use-webpack-alias": useWebpackAlias
2220
+ }
2221
+ };
2222
+
2223
+ return index;
2224
+
2225
+ }));