@bigbinary/eslint-plugin-neeto 1.0.13 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/index.js +451 -431
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
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, ramda) { 'use strict';
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('path'), require('ramda'), require('fs')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['path', 'ramda', 'fs'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global["@bigbinary/eslint-plugin-neeto"] = factory(global.path, global.ramda, global.fs));
|
|
5
|
+
})(this, (function (path, ramda, fs) { 'use strict';
|
|
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 fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
10
11
|
|
|
11
12
|
function _arrayWithHoles(arr) {
|
|
12
13
|
if (Array.isArray(arr)) return arr;
|
|
@@ -78,161 +79,36 @@
|
|
|
78
79
|
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
79
80
|
}, _typeof(obj);
|
|
80
81
|
}
|
|
81
|
-
|
|
82
|
+
|
|
83
|
+
var matchesImpl = function matchesImpl(pattern, object) {
|
|
82
84
|
var __parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : object;
|
|
83
85
|
|
|
84
86
|
if (object === pattern) return true;
|
|
85
87
|
if (typeof pattern === "function" && pattern(object, __parent)) return true;
|
|
86
88
|
if (ramda.isNil(pattern) || ramda.isNil(object)) return false;
|
|
87
89
|
if (_typeof(pattern) !== "object") return false;
|
|
88
|
-
return Object.entries(pattern).every(function (
|
|
89
|
-
var
|
|
90
|
-
key =
|
|
91
|
-
value =
|
|
92
|
-
|
|
93
|
-
return matches(value, object[key], __parent);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
function _defineProperty(obj, key, value) {
|
|
98
|
-
if (key in obj) {
|
|
99
|
-
Object.defineProperty(obj, key, {
|
|
100
|
-
value: value,
|
|
101
|
-
enumerable: true,
|
|
102
|
-
configurable: true,
|
|
103
|
-
writable: true
|
|
104
|
-
});
|
|
105
|
-
} else {
|
|
106
|
-
obj[key] = value;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return obj;
|
|
110
|
-
}
|
|
90
|
+
return Object.entries(pattern).every(function (_ref) {
|
|
91
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
92
|
+
key = _ref2[0],
|
|
93
|
+
value = _ref2[1];
|
|
111
94
|
|
|
112
|
-
|
|
113
|
-
|
|
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; }
|
|
115
|
-
ramda.curry(function (id, array) {
|
|
116
|
-
return array.filter(function (item) {
|
|
117
|
-
return item.id !== id;
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
ramda.curry(function (id, array) {
|
|
121
|
-
return array.find(function (item) {
|
|
122
|
-
return item.id === id;
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
ramda.curry(function (id, newItem, array) {
|
|
126
|
-
return array.map(function (item) {
|
|
127
|
-
return item.id === id ? newItem : item;
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
ramda.curry(function (id, modifier, array) {
|
|
131
|
-
return array.map(function (item) {
|
|
132
|
-
return item.id === id ? modifier(item) : item;
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
ramda.curry(function (pattern, array) {
|
|
136
|
-
return array.find(matches(pattern));
|
|
137
|
-
});
|
|
138
|
-
ramda.curry(function (pattern, array) {
|
|
139
|
-
return array.filter(ramda.complement(matches(pattern)));
|
|
140
|
-
});
|
|
141
|
-
ramda.curry(function (pattern, newItem, array) {
|
|
142
|
-
return array.map(function (item) {
|
|
143
|
-
return matches(pattern, item) ? newItem : item;
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
ramda.curry(function (pattern, modifier, array) {
|
|
147
|
-
return array.map(function (item) {
|
|
148
|
-
return matches(pattern, item) ? modifier(item) : item;
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
ramda.curry(function (id, array) {
|
|
152
|
-
return array.some(function (item) {
|
|
153
|
-
return item.id === id;
|
|
95
|
+
return matchesImpl(value, object[key], __parent);
|
|
154
96
|
});
|
|
97
|
+
};
|
|
98
|
+
var matches = /*#__PURE__*/ramda.curry(function (pattern, object) {
|
|
99
|
+
return matchesImpl(pattern, object);
|
|
155
100
|
});
|
|
156
|
-
var existsBy$1 = ramda.curry(function (pattern, array) {
|
|
101
|
+
var existsBy$1 = /*#__PURE__*/ramda.curry(function (pattern, array) {
|
|
157
102
|
return array.some(matches(pattern));
|
|
158
103
|
});
|
|
159
|
-
ramda.
|
|
160
|
-
|
|
161
|
-
});
|
|
162
|
-
ramda.curry(function (id, array) {
|
|
163
|
-
return array.findIndex(function (item) {
|
|
164
|
-
return item.id === id;
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
ramda.curry(function (pattern, array) {
|
|
168
|
-
return array.findIndex(matches(pattern));
|
|
169
|
-
});
|
|
170
|
-
ramda.curry(function (pattern, array) {
|
|
171
|
-
return ramda.findLastIndex(matches(pattern), array);
|
|
172
|
-
});
|
|
173
|
-
ramda.curry(function (pattern, array) {
|
|
174
|
-
return array.filter(matches(pattern));
|
|
175
|
-
});
|
|
176
|
-
ramda.curry(function (pattern, array) {
|
|
177
|
-
return ramda.count(matches(pattern), array);
|
|
178
|
-
});
|
|
179
|
-
ramda.curry(function (keyMap, objectArray) {
|
|
180
|
-
return objectArray.map(function (object) {
|
|
181
|
-
var shallowCopy = _objectSpread({}, object);
|
|
182
|
-
|
|
183
|
-
for (var source in keyMap) {
|
|
184
|
-
shallowCopy[keyMap[source]] = object[source];
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return shallowCopy;
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
ramda.curry(function (keyMap, objectArray) {
|
|
191
|
-
return objectArray.map(function (object) {
|
|
192
|
-
var shallowCopy = _objectSpread({}, object);
|
|
193
|
-
|
|
194
|
-
for (var source in keyMap) {
|
|
195
|
-
shallowCopy[keyMap[source]] = object[source];
|
|
196
|
-
delete shallowCopy[source];
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return shallowCopy;
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
ramda.curry(function (keyMap, objectArray) {
|
|
203
|
-
var copyKeysSingleObject = function copyKeysSingleObject(object, keyMap) {
|
|
204
|
-
var root = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : object;
|
|
205
|
-
return _objectSpread(_objectSpread({}, object), ramda.fromPairs(ramda.toPairs(keyMap).map(function (_ref) {
|
|
206
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
207
|
-
destination = _ref2[0],
|
|
208
|
-
source = _ref2[1];
|
|
209
|
-
|
|
210
|
-
if (typeof source === "function") {
|
|
211
|
-
return [destination, source(object[destination], root)];
|
|
212
|
-
} else if (Array.isArray(source)) {
|
|
213
|
-
return [destination, ramda.path(source, root)];
|
|
214
|
-
} else if (_typeof(source) === "object") {
|
|
215
|
-
return [destination, copyKeysSingleObject(object[destination], source, root)];
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return [destination, object[source]];
|
|
219
|
-
})));
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
return objectArray.map(function (object) {
|
|
223
|
-
return copyKeysSingleObject(object, keyMap);
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
ramda.complement(ramda.isNil);
|
|
227
|
-
var isNotEmpty$1 = ramda.complement(ramda.isEmpty);
|
|
228
|
-
var notEquals = ramda.curry(function (x, y) {
|
|
104
|
+
var isNotEmpty$1 = /*#__PURE__*/ramda.complement(ramda.isEmpty);
|
|
105
|
+
var notEquals = /*#__PURE__*/ramda.curry(function (x, y) {
|
|
229
106
|
return x !== y;
|
|
230
107
|
});
|
|
231
|
-
var isNot$1 = notEquals;
|
|
232
|
-
ramda.complement(ramda.equals);
|
|
233
108
|
|
|
234
109
|
const APIS_DIRECTORY = "app/javascript/src/apis";
|
|
235
110
|
const ROUTES_FILE_PATH = "app/javascript/src/common/routes.js";
|
|
111
|
+
const WEBPACK_ALIAS_PATH = "config/webpack/alias.js";
|
|
236
112
|
const BLACKLISTED_PACKAGES = ["moment", "bootstrap", "blueprint", "react-spinners", "react-table", "remixicon", "mjml", "react-select", "antd"];
|
|
237
113
|
const TYPES = {
|
|
238
114
|
ARRAY_EXPRESSION: "ArrayExpression",
|
|
@@ -243,10 +119,17 @@
|
|
|
243
119
|
CALL_EXPRESSION: "CallExpression",
|
|
244
120
|
EXPORT_NAMED_DECLARATION: "ExportNamedDeclaration",
|
|
245
121
|
EXPORT_DEFAULT_DECLARATION: "ExportDefaultDeclaration",
|
|
122
|
+
FUNCTION_DECLARATION: "FunctionDeclaration",
|
|
123
|
+
FUNCTION_EXPRESSION: "FunctionExpression",
|
|
246
124
|
IDENTIFIER: "Identifier",
|
|
247
125
|
IF_STATEMENT: "IfStatement",
|
|
248
126
|
IMPORT_DECLARATION: "ImportDeclaration",
|
|
249
127
|
IMPORT_DEFAULT_SPECIFIER: "ImportDefaultSpecifier",
|
|
128
|
+
IMPORT_SPECIFIER: "ImportSpecifier",
|
|
129
|
+
JSX_ATTRIBUTE: "JSXAttribute",
|
|
130
|
+
JSX_ELEMENT: "JSXElement",
|
|
131
|
+
JSX_EXPRESSION_CONTAINER: "JSXExpressionContainer",
|
|
132
|
+
JSX_IDENTIFIER: "JSXIdentifier",
|
|
250
133
|
LITERAL: "Literal",
|
|
251
134
|
LOGICAL_EXPRESSION: "LogicalExpression",
|
|
252
135
|
MEMBER_EXPRESSION: "MemberExpression",
|
|
@@ -259,19 +142,15 @@
|
|
|
259
142
|
UNARY_EXPRESSION: "UnaryExpression",
|
|
260
143
|
VARIABLE_DECLARATION: "VariableDeclaration",
|
|
261
144
|
VARIABLE_DECLARATOR: "VariableDeclarator",
|
|
262
|
-
WHILE_STATEMENT: "WhileStatement"
|
|
263
|
-
JSX_ATTRIBUTE: "JSXAttribute",
|
|
264
|
-
JSX_ELEMENT: "JSXElement",
|
|
265
|
-
JSX_EXPRESSION_CONTAINER: "JSXExpressionContainer",
|
|
266
|
-
JSX_IDENTIFIER: "JSXIdentifier"
|
|
145
|
+
WHILE_STATEMENT: "WhileStatement"
|
|
267
146
|
};
|
|
268
147
|
const IMPORT_DECLARATION = {
|
|
269
|
-
type:
|
|
148
|
+
type: TYPES.IMPORT_DECLARATION,
|
|
270
149
|
source: {
|
|
271
|
-
type:
|
|
150
|
+
type: TYPES.LITERAL
|
|
272
151
|
},
|
|
273
152
|
specifiers: [{
|
|
274
|
-
type:
|
|
153
|
+
type: TYPES.IMPORT_SPECIFIER
|
|
275
154
|
}]
|
|
276
155
|
};
|
|
277
156
|
|
|
@@ -358,6 +237,7 @@
|
|
|
358
237
|
const API_ACTIONS_ARGUMENT_LIMIT = 2;
|
|
359
238
|
const FIXABLE_PARAMETER_TYPES = [TYPES.IDENTIFIER, TYPES.ASSIGNMENT_PATTERN];
|
|
360
239
|
|
|
240
|
+
const addInJsconfig = aliasName => `Add path for "${aliasName}" in jsconfig.json. Refer https://github.com/bigbinary/eslint-plugin-neeto/blob/master/docs/src/rules/webpack-aliases-and-jsconfig-paths-should-be-in-sync.md for more details.`;
|
|
361
241
|
const canBeReplacedWith = fix => `Can be replaced with: ${fix}`;
|
|
362
242
|
const disallowUse = packageName => `Do not use the package ${packageName}`;
|
|
363
243
|
const moveToConstantsJs = constantName => `Move the constant ${constantName} to a constants.js file.`;
|
|
@@ -958,20 +838,20 @@
|
|
|
958
838
|
|
|
959
839
|
|
|
960
840
|
const HISTORY_PUSH_PATTERN = {
|
|
961
|
-
type:
|
|
841
|
+
type: TYPES.CALL_EXPRESSION,
|
|
962
842
|
callee: {
|
|
963
|
-
type:
|
|
843
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
964
844
|
object: {
|
|
965
|
-
type:
|
|
845
|
+
type: TYPES.IDENTIFIER,
|
|
966
846
|
name: "history"
|
|
967
847
|
},
|
|
968
848
|
property: {
|
|
969
|
-
type:
|
|
849
|
+
type: TYPES.IDENTIFIER,
|
|
970
850
|
name: "push"
|
|
971
851
|
}
|
|
972
852
|
},
|
|
973
853
|
arguments: args => args.length === 1 && matches([{
|
|
974
|
-
type:
|
|
854
|
+
type: notEquals(TYPES.OBJECT_EXPRESSION)
|
|
975
855
|
}], args)
|
|
976
856
|
};
|
|
977
857
|
const WINDOW_LOCATION_PATTERNS = [// window.location.href = "/path"
|
|
@@ -979,22 +859,22 @@
|
|
|
979
859
|
type: "AssignmentExpression",
|
|
980
860
|
operator: "=",
|
|
981
861
|
left: {
|
|
982
|
-
type:
|
|
862
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
983
863
|
object: {
|
|
984
|
-
type:
|
|
864
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
985
865
|
object: {
|
|
986
|
-
type:
|
|
866
|
+
type: TYPES.IDENTIFIER,
|
|
987
867
|
name: "window"
|
|
988
868
|
},
|
|
989
869
|
property: {
|
|
990
|
-
type:
|
|
870
|
+
type: TYPES.IDENTIFIER,
|
|
991
871
|
name: "location"
|
|
992
872
|
},
|
|
993
873
|
computed: false,
|
|
994
874
|
optional: false
|
|
995
875
|
},
|
|
996
876
|
property: {
|
|
997
|
-
type:
|
|
877
|
+
type: TYPES.IDENTIFIER,
|
|
998
878
|
name: "href"
|
|
999
879
|
},
|
|
1000
880
|
computed: false,
|
|
@@ -1002,24 +882,24 @@
|
|
|
1002
882
|
}
|
|
1003
883
|
}, // window.location.assign("/path")
|
|
1004
884
|
{
|
|
1005
|
-
type:
|
|
885
|
+
type: TYPES.CALL_EXPRESSION,
|
|
1006
886
|
callee: {
|
|
1007
|
-
type:
|
|
887
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
1008
888
|
object: {
|
|
1009
|
-
type:
|
|
889
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
1010
890
|
object: {
|
|
1011
|
-
type:
|
|
891
|
+
type: TYPES.IDENTIFIER,
|
|
1012
892
|
name: "window"
|
|
1013
893
|
},
|
|
1014
894
|
property: {
|
|
1015
|
-
type:
|
|
895
|
+
type: TYPES.IDENTIFIER,
|
|
1016
896
|
name: "location"
|
|
1017
897
|
},
|
|
1018
898
|
computed: false,
|
|
1019
899
|
optional: false
|
|
1020
900
|
},
|
|
1021
901
|
property: {
|
|
1022
|
-
type:
|
|
902
|
+
type: TYPES.IDENTIFIER,
|
|
1023
903
|
name: "assign"
|
|
1024
904
|
},
|
|
1025
905
|
computed: false,
|
|
@@ -1029,15 +909,15 @@
|
|
|
1029
909
|
}]; // onClick={() => <expression>}
|
|
1030
910
|
|
|
1031
911
|
const ONCLICK_ATTRIBUTE_PATTERN = {
|
|
1032
|
-
type:
|
|
912
|
+
type: TYPES.JSX_ATTRIBUTE,
|
|
1033
913
|
name: {
|
|
1034
|
-
type:
|
|
914
|
+
type: TYPES.JSX_IDENTIFIER,
|
|
1035
915
|
name: "onClick"
|
|
1036
916
|
},
|
|
1037
917
|
value: {
|
|
1038
|
-
type:
|
|
918
|
+
type: TYPES.JSX_EXPRESSION_CONTAINER,
|
|
1039
919
|
expression: {
|
|
1040
|
-
type:
|
|
920
|
+
type: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
1041
921
|
params: ramda.isEmpty,
|
|
1042
922
|
generator: false,
|
|
1043
923
|
async: false
|
|
@@ -1047,7 +927,7 @@
|
|
|
1047
927
|
|
|
1048
928
|
const LINK_REPLACEABLE_PATTERN = {
|
|
1049
929
|
name: {
|
|
1050
|
-
type:
|
|
930
|
+
type: TYPES.JSX_IDENTIFIER,
|
|
1051
931
|
name: ramda.includes(ramda.__, ["Button", "button", "span", "div", "a"])
|
|
1052
932
|
},
|
|
1053
933
|
attributes: ramda.any(matches(ramda.assocPath(["value", "expression", "body"], matchesAny([HISTORY_PUSH_PATTERN, wrappedInBlockPattern(HISTORY_PUSH_PATTERN)]), ONCLICK_ATTRIBUTE_PATTERN)))
|
|
@@ -1055,7 +935,7 @@
|
|
|
1055
935
|
|
|
1056
936
|
const ANCHOR_REPLACEABLE_PATTERN = {
|
|
1057
937
|
name: {
|
|
1058
|
-
type:
|
|
938
|
+
type: TYPES.JSX_IDENTIFIER,
|
|
1059
939
|
name: ramda.includes(ramda.__, ["Button", "button", "span", "div"])
|
|
1060
940
|
},
|
|
1061
941
|
attributes: ramda.any(matches(ramda.assocPath(["value", "expression", "body"], matchesAny([WINDOW_LOCATION_PATTERNS, WINDOW_LOCATION_PATTERNS.map(wrappedInBlockPattern)].flat()), ONCLICK_ATTRIBUTE_PATTERN)))
|
|
@@ -1069,7 +949,7 @@
|
|
|
1069
949
|
}) => fixer => {
|
|
1070
950
|
const onClickAttributeNode = node.attributes.find(matches(ONCLICK_ATTRIBUTE_PATTERN));
|
|
1071
951
|
const pathNode = findPathNode(onClickAttributeNode);
|
|
1072
|
-
const navigateAttr = pathNode.type ===
|
|
952
|
+
const navigateAttr = pathNode.type === TYPES.LITERAL ? `${attribute}="${pathNode.value}"` : `${attribute}={${getCode$1(context, pathNode)}}`;
|
|
1073
953
|
return fixer.replaceText(onClickAttributeNode, navigateAttr);
|
|
1074
954
|
};
|
|
1075
955
|
|
|
@@ -1129,7 +1009,15 @@
|
|
|
1129
1009
|
};
|
|
1130
1010
|
|
|
1131
1011
|
const CONSTANT_CASE_PATTERN = /^[A-Z0-9_]*$/;
|
|
1132
|
-
const CONSTANTS_FILES = [/.*constants.js$/i, /app\/javascript\/src\/common\/urls.js$/];
|
|
1012
|
+
const CONSTANTS_FILES = [/.*constants.(js|jsx)$/i, /app\/javascript\/src\/common\/urls.js$/];
|
|
1013
|
+
const CONSTANT_DECALARATION_PATTERN = {
|
|
1014
|
+
kind: "const",
|
|
1015
|
+
declarations: [{
|
|
1016
|
+
id: {
|
|
1017
|
+
name: name => CONSTANT_CASE_PATTERN.test(name)
|
|
1018
|
+
}
|
|
1019
|
+
}]
|
|
1020
|
+
};
|
|
1133
1021
|
|
|
1134
1022
|
const isConstantsFile = context => CONSTANTS_FILES.some(filePath => filePath.test(path__default["default"].resolve(context.getFilename())));
|
|
1135
1023
|
|
|
@@ -1137,16 +1025,13 @@
|
|
|
1137
1025
|
meta: {
|
|
1138
1026
|
type: "suggestion",
|
|
1139
1027
|
docs: {
|
|
1140
|
-
description: "Indicates that any constant outside a constant.js file should be moved to a constant.js file."
|
|
1028
|
+
description: "Indicates that any constant outside a constant.[js|jsx] file should be moved to a constant.[js|jsx] file."
|
|
1141
1029
|
}
|
|
1142
1030
|
},
|
|
1143
1031
|
create: context => ({
|
|
1144
1032
|
VariableDeclaration(node) {
|
|
1145
|
-
if (
|
|
1146
|
-
|
|
1147
|
-
const constantName = node.declarations[0].id.name;
|
|
1148
|
-
|
|
1149
|
-
if (CONSTANT_CASE_PATTERN.test(constantName)) {
|
|
1033
|
+
if (!isConstantsFile(context) && matches(CONSTANT_DECALARATION_PATTERN, node)) {
|
|
1034
|
+
const constantName = node.declarations[0].id.name;
|
|
1150
1035
|
context.report(node, moveToConstantsJs(constantName));
|
|
1151
1036
|
}
|
|
1152
1037
|
}
|
|
@@ -1305,26 +1190,26 @@
|
|
|
1305
1190
|
|
|
1306
1191
|
const ASSIGNMENT_PATTERNS = [{
|
|
1307
1192
|
id: {
|
|
1308
|
-
type:
|
|
1193
|
+
type: TYPES.OBJECT_PATTERN
|
|
1309
1194
|
}
|
|
1310
1195
|
}, {
|
|
1311
1196
|
id: {
|
|
1312
|
-
type:
|
|
1197
|
+
type: TYPES.IDENTIFIER
|
|
1313
1198
|
}
|
|
1314
1199
|
}];
|
|
1315
1200
|
const IDENTIFIER_INITIALIZATION_PATTERN = {
|
|
1316
|
-
type:
|
|
1201
|
+
type: TYPES.IDENTIFIER,
|
|
1317
1202
|
name: "globalProps"
|
|
1318
1203
|
};
|
|
1319
1204
|
const MEMBER_EXPRESSION_INITIALIZATION_PATTERN = {
|
|
1320
|
-
type:
|
|
1205
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
1321
1206
|
object: {
|
|
1322
|
-
type:
|
|
1207
|
+
type: TYPES.IDENTIFIER,
|
|
1323
1208
|
name: "globalProps"
|
|
1324
1209
|
}
|
|
1325
1210
|
};
|
|
1326
1211
|
const GLOBALPROPS_REASSIGNMENT_PATTERN = {
|
|
1327
|
-
type:
|
|
1212
|
+
type: TYPES.IDENTIFIER,
|
|
1328
1213
|
name: "globalProps"
|
|
1329
1214
|
};
|
|
1330
1215
|
|
|
@@ -1499,35 +1384,35 @@
|
|
|
1499
1384
|
};
|
|
1500
1385
|
const LABEL_AND_VALUE_PATTERN = {
|
|
1501
1386
|
properties: props => props.length === 2 && props.every(matches({
|
|
1502
|
-
type:
|
|
1387
|
+
type: TYPES.PROPERTY,
|
|
1503
1388
|
computed: false,
|
|
1504
1389
|
key: {
|
|
1505
|
-
type:
|
|
1390
|
+
type: TYPES.IDENTIFIER
|
|
1506
1391
|
},
|
|
1507
1392
|
value: {
|
|
1508
|
-
type: ramda.includes(ramda.__, [
|
|
1393
|
+
type: ramda.includes(ramda.__, [TYPES.LITERAL, TYPES.IDENTIFIER, TYPES.MEMBER_EXPRESSION])
|
|
1509
1394
|
}
|
|
1510
1395
|
})) && ramda.equals(["label", "value"], props.map(ramda.path(["key", "name"])).sort())
|
|
1511
1396
|
};
|
|
1512
1397
|
const DYNAMIC_ARRAY_PATTERN = {
|
|
1513
1398
|
callee: {
|
|
1514
|
-
type:
|
|
1399
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
1515
1400
|
object: {
|
|
1516
|
-
type:
|
|
1401
|
+
type: TYPES.IDENTIFIER,
|
|
1517
1402
|
name: "Array"
|
|
1518
1403
|
},
|
|
1519
1404
|
property: {
|
|
1520
|
-
type:
|
|
1405
|
+
type: TYPES.IDENTIFIER,
|
|
1521
1406
|
name: "from"
|
|
1522
1407
|
}
|
|
1523
1408
|
},
|
|
1524
1409
|
arguments: args => args.length === 2 && matches({
|
|
1525
1410
|
0: {
|
|
1526
|
-
type:
|
|
1411
|
+
type: TYPES.OBJECT_EXPRESSION,
|
|
1527
1412
|
properties: props => props.length === 1 && props[0].key.name === "length"
|
|
1528
1413
|
},
|
|
1529
1414
|
1: {
|
|
1530
|
-
type:
|
|
1415
|
+
type: TYPES.ARROW_FUNCTION_EXPRESSION
|
|
1531
1416
|
}
|
|
1532
1417
|
}, args)
|
|
1533
1418
|
};
|
|
@@ -1536,7 +1421,11 @@
|
|
|
1536
1421
|
type: TYPES.LOGICAL_EXPRESSION,
|
|
1537
1422
|
operator: "&&",
|
|
1538
1423
|
left: NOT_NIL_BINARY_EXP_PATTERN,
|
|
1539
|
-
right:
|
|
1424
|
+
right: (right, root) => {
|
|
1425
|
+
var _right$left, _root$left, _root$left$left;
|
|
1426
|
+
|
|
1427
|
+
return matches(NOT_NIL_BINARY_EXP_PATTERN, right) && ((_right$left = right.left) === null || _right$left === void 0 ? void 0 : _right$left.name) === ((_root$left = root.left) === null || _root$left === void 0 ? void 0 : (_root$left$left = _root$left.left) === null || _root$left$left === void 0 ? void 0 : _root$left$left.name);
|
|
1428
|
+
}
|
|
1540
1429
|
}, // x => !isNil(x)
|
|
1541
1430
|
{
|
|
1542
1431
|
type: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
@@ -1551,7 +1440,14 @@
|
|
|
1551
1440
|
type: TYPES.IDENTIFIER,
|
|
1552
1441
|
name: "isNil"
|
|
1553
1442
|
},
|
|
1554
|
-
arguments: args => args.length === 1 &&
|
|
1443
|
+
arguments: (args, root) => args.length === 1 && matches([{
|
|
1444
|
+
type: TYPES.IDENTIFIER,
|
|
1445
|
+
name: name => {
|
|
1446
|
+
var _root$params$;
|
|
1447
|
+
|
|
1448
|
+
return name === ((_root$params$ = root.params[0]) === null || _root$params$ === void 0 ? void 0 : _root$params$.name);
|
|
1449
|
+
}
|
|
1450
|
+
}], args)
|
|
1555
1451
|
}
|
|
1556
1452
|
}
|
|
1557
1453
|
}];
|
|
@@ -1595,18 +1491,18 @@
|
|
|
1595
1491
|
};
|
|
1596
1492
|
const REPLACE_BY_PATTERN = {
|
|
1597
1493
|
callee: {
|
|
1598
|
-
type:
|
|
1494
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
1599
1495
|
property: {
|
|
1600
|
-
type:
|
|
1496
|
+
type: TYPES.IDENTIFIER,
|
|
1601
1497
|
name: "map"
|
|
1602
1498
|
}
|
|
1603
1499
|
},
|
|
1604
1500
|
arguments: [{
|
|
1605
|
-
type:
|
|
1501
|
+
type: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
1606
1502
|
generator: false,
|
|
1607
1503
|
async: false,
|
|
1608
1504
|
expression: true,
|
|
1609
|
-
params: params => params.length === 1 && params[0].type ===
|
|
1505
|
+
params: params => params.length === 1 && params[0].type === TYPES.IDENTIFIER,
|
|
1610
1506
|
body: {
|
|
1611
1507
|
type: "ConditionalExpression",
|
|
1612
1508
|
test: (test, root) => areAllChecksWithParams(test, arrayFuncParam(root), {
|
|
@@ -1614,7 +1510,7 @@
|
|
|
1614
1510
|
join: "&&"
|
|
1615
1511
|
}),
|
|
1616
1512
|
alternate: {
|
|
1617
|
-
type:
|
|
1513
|
+
type: TYPES.IDENTIFIER,
|
|
1618
1514
|
name: (name, root) => name === arrayFuncParam(root).name
|
|
1619
1515
|
}
|
|
1620
1516
|
}
|
|
@@ -1627,35 +1523,35 @@
|
|
|
1627
1523
|
join: "||"
|
|
1628
1524
|
}),
|
|
1629
1525
|
consequent: {
|
|
1630
|
-
type:
|
|
1526
|
+
type: TYPES.IDENTIFIER,
|
|
1631
1527
|
name: (name, root) => name === arrayFuncParam(root).name
|
|
1632
1528
|
}
|
|
1633
1529
|
}, REPLACE_BY_PATTERN);
|
|
1634
1530
|
const COPY_KEYS_PATTERN = {
|
|
1635
1531
|
properties: props => props.length > 1 && matches({
|
|
1636
|
-
type:
|
|
1532
|
+
type: TYPES.SPREAD_ELEMENT,
|
|
1637
1533
|
argument: {
|
|
1638
|
-
type:
|
|
1534
|
+
type: TYPES.IDENTIFIER
|
|
1639
1535
|
}
|
|
1640
1536
|
}, props[0]) && props.slice(1).every(matches({
|
|
1641
|
-
type:
|
|
1537
|
+
type: TYPES.PROPERTY,
|
|
1642
1538
|
kind: "init",
|
|
1643
1539
|
method: false,
|
|
1644
1540
|
computed: false,
|
|
1645
1541
|
shorthand: false,
|
|
1646
1542
|
key: {
|
|
1647
|
-
type:
|
|
1543
|
+
type: TYPES.IDENTIFIER
|
|
1648
1544
|
},
|
|
1649
1545
|
value: {
|
|
1650
|
-
type:
|
|
1546
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
1651
1547
|
computed: false,
|
|
1652
1548
|
optional: false,
|
|
1653
1549
|
object: {
|
|
1654
|
-
type:
|
|
1550
|
+
type: TYPES.IDENTIFIER,
|
|
1655
1551
|
name: props[0].argument.name
|
|
1656
1552
|
},
|
|
1657
1553
|
property: {
|
|
1658
|
-
type:
|
|
1554
|
+
type: TYPES.IDENTIFIER
|
|
1659
1555
|
}
|
|
1660
1556
|
}
|
|
1661
1557
|
}))
|
|
@@ -1770,11 +1666,11 @@
|
|
|
1770
1666
|
}
|
|
1771
1667
|
};
|
|
1772
1668
|
const COUNT_BY_PATTERN = {
|
|
1773
|
-
type:
|
|
1669
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
1774
1670
|
computed: false,
|
|
1775
1671
|
optional: false,
|
|
1776
1672
|
property: {
|
|
1777
|
-
type:
|
|
1673
|
+
type: TYPES.IDENTIFIER,
|
|
1778
1674
|
name: "length"
|
|
1779
1675
|
}
|
|
1780
1676
|
};
|
|
@@ -2018,7 +1914,7 @@
|
|
|
2018
1914
|
};
|
|
2019
1915
|
|
|
2020
1916
|
var dynamicArray = {
|
|
2021
|
-
operateOn:
|
|
1917
|
+
operateOn: TYPES.CALL_EXPRESSION,
|
|
2022
1918
|
check: (context, node) => {
|
|
2023
1919
|
var _node$arguments$1$par;
|
|
2024
1920
|
|
|
@@ -2041,13 +1937,11 @@
|
|
|
2041
1937
|
check: (context, node) => {
|
|
2042
1938
|
let fix = null;
|
|
2043
1939
|
|
|
2044
|
-
if (
|
|
2045
|
-
if (!matches(NOT_EQUALS_PATTERNS.UNARY_EXP, node)) return;
|
|
1940
|
+
if (matches(NOT_EQUALS_PATTERNS.UNARY_EXP, node)) {
|
|
2046
1941
|
const first = getCode$1(context, node.argument.arguments[0]);
|
|
2047
1942
|
const second = getCode$1(context, node.argument.arguments[1]);
|
|
2048
1943
|
fix = `isNot(${first}, ${second})`;
|
|
2049
|
-
} else {
|
|
2050
|
-
if (!matches(NOT_EQUALS_PATTERNS.ARROW_FUNC, node)) return;
|
|
1944
|
+
} else if (matches(NOT_EQUALS_PATTERNS.ARROW_FUNC, node)) {
|
|
2051
1945
|
const argumentName = node.params[0].name;
|
|
2052
1946
|
let externalValueNode = null;
|
|
2053
1947
|
|
|
@@ -2059,7 +1953,7 @@
|
|
|
2059
1953
|
|
|
2060
1954
|
const externalValue = getCode$1(context, externalValueNode);
|
|
2061
1955
|
fix = `isNot(${externalValue})`;
|
|
2062
|
-
}
|
|
1956
|
+
} else return;
|
|
2063
1957
|
|
|
2064
1958
|
reportSuggestion({
|
|
2065
1959
|
context,
|
|
@@ -2073,19 +1967,14 @@
|
|
|
2073
1967
|
var isNotEmpty = {
|
|
2074
1968
|
operateOn: [TYPES.IF_STATEMENT, TYPES.WHILE_STATEMENT, TYPES.BINARY_EXPRESSION, TYPES.ARROW_FUNCTION_EXPRESSION],
|
|
2075
1969
|
check: (context, node) => {
|
|
2076
|
-
const isBinaryExp = node.type === TYPES.BINARY_EXPRESSION;
|
|
2077
|
-
const isArrowFunc = node.type === TYPES.ARROW_FUNCTION_EXPRESSION;
|
|
2078
|
-
const isCondStat = node.type === TYPES.IF_STATEMENT || node.type === TYPES.WHILE_STATEMENT;
|
|
2079
|
-
if (isBinaryExp && !matches(NOT_EMPTY_PATTERNS.BINARY_EXP, node)) return;
|
|
2080
|
-
if (isArrowFunc && !matches(NOT_EMPTY_PATTERNS.ARROW_FUNC, node)) return;
|
|
2081
|
-
if (isCondStat && !matches(NOT_EMPTY_PATTERNS.CONDT_STAT, node)) return;
|
|
2082
1970
|
let fix = null;
|
|
2083
1971
|
let message = "";
|
|
2084
1972
|
let nodeToBeReplaced = node;
|
|
2085
1973
|
|
|
2086
|
-
if (
|
|
1974
|
+
if (matches(NOT_EMPTY_PATTERNS.ARROW_FUNC, node)) {
|
|
2087
1975
|
fix = "isNotEmpty";
|
|
2088
|
-
} else {
|
|
1976
|
+
} else if (matchesAny([NOT_EMPTY_PATTERNS.BINARY_EXP, NOT_EMPTY_PATTERNS.CONDT_STAT], node)) {
|
|
1977
|
+
const isBinaryExp = node.type === TYPES.BINARY_EXPRESSION;
|
|
2089
1978
|
const expNode = isBinaryExp ? node.left : node.test;
|
|
2090
1979
|
const isObjLenCheck = matches(OBJ_KEY_LENGTH_PATTERN$1, expNode);
|
|
2091
1980
|
nodeToBeReplaced = isBinaryExp ? node : node.test;
|
|
@@ -2098,7 +1987,7 @@
|
|
|
2098
1987
|
fix = `isNotEmpty(${arrName})`;
|
|
2099
1988
|
message = `Can be replaced with: ${fix}, if '${arrName}' is an array or string.`;
|
|
2100
1989
|
}
|
|
2101
|
-
}
|
|
1990
|
+
} else return;
|
|
2102
1991
|
|
|
2103
1992
|
reportSuggestion({
|
|
2104
1993
|
context,
|
|
@@ -2115,13 +2004,11 @@
|
|
|
2115
2004
|
check: (context, node) => {
|
|
2116
2005
|
let fix = null;
|
|
2117
2006
|
|
|
2118
|
-
if (
|
|
2119
|
-
if (!matches(NOT_EQUALS_DEEP_PATTERNS.BINARY_EXP, node)) return;
|
|
2007
|
+
if (matches(NOT_EQUALS_DEEP_PATTERNS.BINARY_EXP, node)) {
|
|
2120
2008
|
const first = getCode$1(context, node.left.arguments[0]);
|
|
2121
2009
|
const second = getCode$1(context, node.right.arguments[0]);
|
|
2122
2010
|
fix = `isNotEqualDeep(${first}, ${second})`;
|
|
2123
|
-
} else {
|
|
2124
|
-
if (!matches(NOT_EQUALS_DEEP_PATTERNS.ARROW_FUNC, node)) return;
|
|
2011
|
+
} else if (matches(NOT_EQUALS_DEEP_PATTERNS.ARROW_FUNC, node)) {
|
|
2125
2012
|
const argumentName = node.params[0].name;
|
|
2126
2013
|
let externalValueNode = null;
|
|
2127
2014
|
|
|
@@ -2133,7 +2020,7 @@
|
|
|
2133
2020
|
|
|
2134
2021
|
const externalValue = getCode$1(context, externalValueNode);
|
|
2135
2022
|
fix = `isNotEqualDeep(${externalValue})`;
|
|
2136
|
-
}
|
|
2023
|
+
} else return;
|
|
2137
2024
|
|
|
2138
2025
|
reportSuggestion({
|
|
2139
2026
|
context,
|
|
@@ -2151,10 +2038,8 @@
|
|
|
2151
2038
|
let fix = null;
|
|
2152
2039
|
|
|
2153
2040
|
if (node.type === TYPES.ARROW_FUNCTION_EXPRESSION) {
|
|
2154
|
-
if (node.params[0].name !== node.body.argument.arguments[0].name) return;
|
|
2155
2041
|
fix = `isNotNil`;
|
|
2156
2042
|
} else if (node.type === TYPES.LOGICAL_EXPRESSION) {
|
|
2157
|
-
if (node.left.left.name !== node.right.left.name) return;
|
|
2158
2043
|
fix = `isNotNil(${node.left.left.name})`;
|
|
2159
2044
|
}
|
|
2160
2045
|
|
|
@@ -2168,7 +2053,7 @@
|
|
|
2168
2053
|
};
|
|
2169
2054
|
|
|
2170
2055
|
var noop = {
|
|
2171
|
-
operateOn: [
|
|
2056
|
+
operateOn: [TYPES.FUNCTION_EXPRESSION, TYPES.ARROW_FUNCTION_EXPRESSION, TYPES.FUNCTION_DECLARATION],
|
|
2172
2057
|
check: (context, node) => {
|
|
2173
2058
|
if (matches(NOOP_PATTERN, node)) {
|
|
2174
2059
|
reportSuggestion({
|
|
@@ -2255,7 +2140,7 @@
|
|
|
2255
2140
|
};
|
|
2256
2141
|
|
|
2257
2142
|
var toLabelAndValue = {
|
|
2258
|
-
operateOn:
|
|
2143
|
+
operateOn: TYPES.OBJECT_EXPRESSION,
|
|
2259
2144
|
check: (context, node) => {
|
|
2260
2145
|
if (!matches(LABEL_AND_VALUE_PATTERN, node)) return;
|
|
2261
2146
|
const [label, value] = ramda.pluck("value", node.properties).map(node => getCode$1(context, node)); // order doesn't matter here
|
|
@@ -2393,22 +2278,22 @@
|
|
|
2393
2278
|
|
|
2394
2279
|
const LOCALIZATION_CALL_PATTERNS = [{
|
|
2395
2280
|
callee: {
|
|
2396
|
-
type:
|
|
2281
|
+
type: TYPES.IDENTIFIER,
|
|
2397
2282
|
name: "t"
|
|
2398
2283
|
},
|
|
2399
2284
|
arguments: [{
|
|
2400
|
-
type:
|
|
2285
|
+
type: TYPES.LITERAL
|
|
2401
2286
|
}]
|
|
2402
2287
|
}, {
|
|
2403
2288
|
callee: {
|
|
2404
|
-
type:
|
|
2289
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
2405
2290
|
property: {
|
|
2406
|
-
type:
|
|
2291
|
+
type: TYPES.IDENTIFIER,
|
|
2407
2292
|
name: "t"
|
|
2408
2293
|
}
|
|
2409
2294
|
},
|
|
2410
2295
|
arguments: [{
|
|
2411
|
-
type:
|
|
2296
|
+
type: TYPES.LITERAL
|
|
2412
2297
|
}]
|
|
2413
2298
|
}];
|
|
2414
2299
|
|
|
@@ -2546,20 +2431,20 @@
|
|
|
2546
2431
|
specifiers: [{
|
|
2547
2432
|
type: "ImportNamespaceSpecifier",
|
|
2548
2433
|
local: {
|
|
2549
|
-
type:
|
|
2434
|
+
type: TYPES.IDENTIFIER
|
|
2550
2435
|
}
|
|
2551
2436
|
}],
|
|
2552
2437
|
source: {
|
|
2553
|
-
type:
|
|
2438
|
+
type: TYPES.LITERAL,
|
|
2554
2439
|
value: "ramda"
|
|
2555
2440
|
}
|
|
2556
2441
|
};
|
|
2557
2442
|
|
|
2558
2443
|
const ramdaUsage = identifierName => ({
|
|
2559
|
-
type:
|
|
2444
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
2560
2445
|
object: {
|
|
2561
2446
|
name: identifierName,
|
|
2562
|
-
type:
|
|
2447
|
+
type: TYPES.IDENTIFIER
|
|
2563
2448
|
}
|
|
2564
2449
|
});
|
|
2565
2450
|
|
|
@@ -2601,8 +2486,12 @@
|
|
|
2601
2486
|
};
|
|
2602
2487
|
|
|
2603
2488
|
const SPECIAL_CHARS_PATTERN = /^ +| +$|[\r\n\t\f\v&<>{}"'`\\]+/;
|
|
2604
|
-
|
|
2605
|
-
|
|
2489
|
+
const REPLACEABLE_LITERAL_PATTERN = {
|
|
2490
|
+
expression: {
|
|
2491
|
+
type: TYPES.LITERAL,
|
|
2492
|
+
value: value => typeof value === "string" && !SPECIAL_CHARS_PATTERN.test(value)
|
|
2493
|
+
}
|
|
2494
|
+
};
|
|
2606
2495
|
|
|
2607
2496
|
var noRedundantJsxExpression = {
|
|
2608
2497
|
meta: {
|
|
@@ -2614,7 +2503,7 @@
|
|
|
2614
2503
|
},
|
|
2615
2504
|
create: context => ({
|
|
2616
2505
|
JSXExpressionContainer(node) {
|
|
2617
|
-
if (!
|
|
2506
|
+
if (!matches(REPLACEABLE_LITERAL_PATTERN, node)) return;
|
|
2618
2507
|
let fix = "";
|
|
2619
2508
|
|
|
2620
2509
|
if (node.parent.type === TYPES.JSX_ELEMENT) {
|
|
@@ -2639,10 +2528,48 @@
|
|
|
2639
2528
|
const ENDS_WITH_SPACES_PATTERN = / +$/;
|
|
2640
2529
|
const STARTS_OR_ENDS_WITH_SPACES_PATTERN = /^ +| +$/;
|
|
2641
2530
|
const STARTS_WITH_SPACES_PATTERN = /^ +/;
|
|
2531
|
+
const QUASI_WITH_SPECIAL_CHARACTERS_PATTERN = {
|
|
2532
|
+
value: {
|
|
2533
|
+
cooked: cooked => cooked.match(CHARACTERS_TO_IGNORE_PATTERN)
|
|
2534
|
+
}
|
|
2535
|
+
};
|
|
2536
|
+
const EXPRESSION_ONLY_PATTERN = {
|
|
2537
|
+
expressions: exps => exps.length === 1,
|
|
2538
|
+
quasis: quasis => quasis.length === 2 && matches([{
|
|
2539
|
+
value: {
|
|
2540
|
+
cooked: ""
|
|
2541
|
+
}
|
|
2542
|
+
}, {
|
|
2543
|
+
value: {
|
|
2544
|
+
cooked: ""
|
|
2545
|
+
}
|
|
2546
|
+
}], quasis)
|
|
2547
|
+
};
|
|
2548
|
+
const INSIDE_JSX_ELEMENT_PATTERN = {
|
|
2549
|
+
parent: {
|
|
2550
|
+
type: TYPES.JSX_EXPRESSION_CONTAINER,
|
|
2551
|
+
parent: {
|
|
2552
|
+
type: TYPES.JSX_ELEMENT
|
|
2553
|
+
}
|
|
2554
|
+
},
|
|
2555
|
+
quasis: quasis => {
|
|
2556
|
+
var _quasis$, _last;
|
|
2557
|
+
|
|
2558
|
+
return !((_quasis$ = quasis[0]) !== null && _quasis$ !== void 0 && _quasis$.value.cooked.match(STARTS_WITH_SPACES_PATTERN)) && !((_last = ramda.last(quasis)) !== null && _last !== void 0 && _last.value.cooked.match(ENDS_WITH_SPACES_PATTERN));
|
|
2559
|
+
}
|
|
2560
|
+
};
|
|
2561
|
+
const REPLACEABLE_QUASIS_ONLY_PATTERN = {
|
|
2562
|
+
expressions: exps => exps.length === 0,
|
|
2563
|
+
quasis: quasis => quasis.length === 1 && matches([{
|
|
2564
|
+
value: {
|
|
2565
|
+
cooked: cooked => !cooked.match(STARTS_OR_ENDS_WITH_SPACES_PATTERN)
|
|
2566
|
+
}
|
|
2567
|
+
}], quasis)
|
|
2568
|
+
};
|
|
2642
2569
|
|
|
2643
2570
|
const doQusisHaveSpecialCharacters = ({
|
|
2644
2571
|
quasis
|
|
2645
|
-
}) => quasis.some(
|
|
2572
|
+
}) => quasis.some(matches(QUASI_WITH_SPECIAL_CHARACTERS_PATTERN));
|
|
2646
2573
|
|
|
2647
2574
|
const getTemplateContent = (context, {
|
|
2648
2575
|
expressions,
|
|
@@ -2653,12 +2580,6 @@
|
|
|
2653
2580
|
return `${acc}{${expressionCode}}${quasi}`;
|
|
2654
2581
|
}, `${quasis[0].value.cooked}`);
|
|
2655
2582
|
|
|
2656
|
-
const isExpressionOnly = node => node.expressions.length === 1 && node.quasis.length === 2 && node.quasis[0].value.cooked === "" && node.quasis[1].value.cooked === "";
|
|
2657
|
-
|
|
2658
|
-
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);
|
|
2659
|
-
|
|
2660
|
-
const isReplaceableQuasiOnly = node => node.expressions.length === 0 && node.quasis.length === 1 && !node.quasis[0].value.cooked.match(STARTS_OR_ENDS_WITH_SPACES_PATTERN);
|
|
2661
|
-
|
|
2662
2583
|
var noRedundantStringTemplates = {
|
|
2663
2584
|
meta: {
|
|
2664
2585
|
type: "problem",
|
|
@@ -2671,21 +2592,21 @@
|
|
|
2671
2592
|
TemplateLiteral(node) {
|
|
2672
2593
|
if (doQusisHaveSpecialCharacters(node)) return;
|
|
2673
2594
|
|
|
2674
|
-
if (
|
|
2595
|
+
if (matches(EXPRESSION_ONLY_PATTERN, node)) {
|
|
2675
2596
|
const fix = getCode$1(context, node.expressions[0]);
|
|
2676
2597
|
context.report({
|
|
2677
2598
|
node,
|
|
2678
2599
|
message: canBeReplacedWith(fix),
|
|
2679
2600
|
fix: fixer => fixer.replaceText(node, fix)
|
|
2680
2601
|
});
|
|
2681
|
-
} else if (
|
|
2602
|
+
} else if (matches(INSIDE_JSX_ELEMENT_PATTERN, node)) {
|
|
2682
2603
|
const fix = getTemplateContent(context, node);
|
|
2683
2604
|
context.report({
|
|
2684
2605
|
node,
|
|
2685
2606
|
message: canBeReplacedWith(fix),
|
|
2686
2607
|
fix: fixer => fixer.replaceText(node.parent, fix)
|
|
2687
2608
|
});
|
|
2688
|
-
} else if (
|
|
2609
|
+
} else if (matches(REPLACEABLE_QUASIS_ONLY_PATTERN, node)) {
|
|
2689
2610
|
const fix = `"${node.quasis[0].value.cooked}"`;
|
|
2690
2611
|
context.report({
|
|
2691
2612
|
node,
|
|
@@ -2750,6 +2671,12 @@
|
|
|
2750
2671
|
name: "length"
|
|
2751
2672
|
}
|
|
2752
2673
|
};
|
|
2674
|
+
const ARRAY_PATTERN = {
|
|
2675
|
+
body: {
|
|
2676
|
+
type: TYPES.ARRAY_EXPRESSION,
|
|
2677
|
+
elements: elmts => elmts.length === 2
|
|
2678
|
+
}
|
|
2679
|
+
};
|
|
2753
2680
|
const OBJ_KEY_LENGTH_PATTERN = {
|
|
2754
2681
|
type: TYPES.MEMBER_EXPRESSION,
|
|
2755
2682
|
object: {
|
|
@@ -2775,96 +2702,118 @@
|
|
|
2775
2702
|
APPEND: {
|
|
2776
2703
|
// x => [...x, y]
|
|
2777
2704
|
params: [{
|
|
2778
|
-
type:
|
|
2705
|
+
type: TYPES.IDENTIFIER
|
|
2779
2706
|
}],
|
|
2780
2707
|
body: {
|
|
2781
|
-
type:
|
|
2708
|
+
type: TYPES.ARRAY_EXPRESSION,
|
|
2782
2709
|
elements: [{
|
|
2783
|
-
type:
|
|
2710
|
+
type: TYPES.SPREAD_ELEMENT,
|
|
2784
2711
|
argument: {
|
|
2785
|
-
type:
|
|
2712
|
+
type: TYPES.IDENTIFIER,
|
|
2713
|
+
name: (name, root) => {
|
|
2714
|
+
var _root$params$;
|
|
2715
|
+
|
|
2716
|
+
return name === ((_root$params$ = root.params[0]) === null || _root$params$ === void 0 ? void 0 : _root$params$.name);
|
|
2717
|
+
}
|
|
2786
2718
|
}
|
|
2719
|
+
}, {
|
|
2720
|
+
type: notEquals(TYPES.SPREAD_ELEMENT)
|
|
2787
2721
|
}]
|
|
2788
2722
|
}
|
|
2789
2723
|
},
|
|
2790
2724
|
PREPEND: {
|
|
2791
2725
|
// x => [y, ...x]
|
|
2792
2726
|
params: [{
|
|
2793
|
-
type:
|
|
2727
|
+
type: TYPES.IDENTIFIER
|
|
2794
2728
|
}],
|
|
2795
2729
|
body: {
|
|
2796
|
-
type:
|
|
2797
|
-
elements: {
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2730
|
+
type: TYPES.ARRAY_EXPRESSION,
|
|
2731
|
+
elements: [{
|
|
2732
|
+
type: notEquals(TYPES.SPREAD_ELEMENT)
|
|
2733
|
+
}, {
|
|
2734
|
+
type: TYPES.SPREAD_ELEMENT,
|
|
2735
|
+
argument: {
|
|
2736
|
+
type: TYPES.IDENTIFIER,
|
|
2737
|
+
name: (name, root) => {
|
|
2738
|
+
var _root$params$2;
|
|
2739
|
+
|
|
2740
|
+
return name === ((_root$params$2 = root.params[0]) === null || _root$params$2 === void 0 ? void 0 : _root$params$2.name);
|
|
2802
2741
|
}
|
|
2803
2742
|
}
|
|
2804
|
-
}
|
|
2743
|
+
}]
|
|
2805
2744
|
}
|
|
2806
2745
|
},
|
|
2807
2746
|
CONCAT: {
|
|
2808
2747
|
// x => [...x, ...y]
|
|
2809
2748
|
params: [{
|
|
2810
|
-
type:
|
|
2749
|
+
type: TYPES.IDENTIFIER
|
|
2811
2750
|
}],
|
|
2812
2751
|
body: {
|
|
2813
|
-
type:
|
|
2752
|
+
type: TYPES.ARRAY_EXPRESSION,
|
|
2814
2753
|
elements: [{
|
|
2815
|
-
type:
|
|
2754
|
+
type: TYPES.SPREAD_ELEMENT,
|
|
2816
2755
|
argument: {
|
|
2817
|
-
type:
|
|
2756
|
+
type: TYPES.IDENTIFIER,
|
|
2757
|
+
name: (name, root) => {
|
|
2758
|
+
var _root$params$3;
|
|
2759
|
+
|
|
2760
|
+
return name === ((_root$params$3 = root.params[0]) === null || _root$params$3 === void 0 ? void 0 : _root$params$3.name);
|
|
2761
|
+
}
|
|
2818
2762
|
}
|
|
2819
2763
|
}, {
|
|
2820
|
-
type:
|
|
2764
|
+
type: TYPES.SPREAD_ELEMENT
|
|
2821
2765
|
}]
|
|
2822
2766
|
}
|
|
2823
2767
|
}
|
|
2824
2768
|
};
|
|
2825
2769
|
const ASSOC_PATTERN = {
|
|
2826
2770
|
// x => ({ ...x, y: 10 })
|
|
2827
|
-
params: [{
|
|
2828
|
-
type:
|
|
2829
|
-
}],
|
|
2771
|
+
params: params => params.length === 1 && matches([{
|
|
2772
|
+
type: TYPES.IDENTIFIER
|
|
2773
|
+
}], params),
|
|
2830
2774
|
body: {
|
|
2831
|
-
type:
|
|
2832
|
-
properties:
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2775
|
+
type: TYPES.OBJECT_EXPRESSION,
|
|
2776
|
+
properties: (props, root) => {
|
|
2777
|
+
var _root$params$4;
|
|
2778
|
+
|
|
2779
|
+
return props.length === 2 && matches([{
|
|
2780
|
+
type: TYPES.SPREAD_ELEMENT,
|
|
2781
|
+
argument: {
|
|
2782
|
+
type: TYPES.IDENTIFIER,
|
|
2783
|
+
name: (_root$params$4 = root.params[0]) === null || _root$params$4 === void 0 ? void 0 : _root$params$4.name
|
|
2784
|
+
}
|
|
2785
|
+
}, {
|
|
2786
|
+
type: TYPES.PROPERTY
|
|
2787
|
+
}], props);
|
|
2788
|
+
}
|
|
2840
2789
|
}
|
|
2841
2790
|
};
|
|
2842
2791
|
const JSON_EQUALS_PATTERN = {
|
|
2843
2792
|
// JSON.stringify(x) === JSON.stringify(y)
|
|
2844
2793
|
left: {
|
|
2845
|
-
type:
|
|
2794
|
+
type: TYPES.CALL_EXPRESSION,
|
|
2846
2795
|
callee: {
|
|
2847
|
-
type:
|
|
2796
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
2848
2797
|
object: {
|
|
2849
|
-
type:
|
|
2798
|
+
type: TYPES.IDENTIFIER,
|
|
2850
2799
|
name: "JSON"
|
|
2851
2800
|
},
|
|
2852
2801
|
property: {
|
|
2853
|
-
type:
|
|
2802
|
+
type: TYPES.IDENTIFIER,
|
|
2854
2803
|
name: "stringify"
|
|
2855
2804
|
}
|
|
2856
2805
|
}
|
|
2857
2806
|
},
|
|
2858
2807
|
right: {
|
|
2859
|
-
type:
|
|
2808
|
+
type: TYPES.CALL_EXPRESSION,
|
|
2860
2809
|
callee: {
|
|
2861
|
-
type:
|
|
2810
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
2862
2811
|
object: {
|
|
2863
|
-
type:
|
|
2812
|
+
type: TYPES.IDENTIFIER,
|
|
2864
2813
|
name: "JSON"
|
|
2865
2814
|
},
|
|
2866
2815
|
property: {
|
|
2867
|
-
type:
|
|
2816
|
+
type: TYPES.IDENTIFIER,
|
|
2868
2817
|
name: "stringify"
|
|
2869
2818
|
}
|
|
2870
2819
|
}
|
|
@@ -2877,108 +2826,138 @@
|
|
|
2877
2826
|
async: false,
|
|
2878
2827
|
expression: true,
|
|
2879
2828
|
params: [{
|
|
2880
|
-
type:
|
|
2829
|
+
type: TYPES.IDENTIFIER
|
|
2881
2830
|
}],
|
|
2882
2831
|
body: {
|
|
2883
|
-
type:
|
|
2832
|
+
type: TYPES.IDENTIFIER,
|
|
2833
|
+
name: (name, root) => {
|
|
2834
|
+
var _root$params$5;
|
|
2835
|
+
|
|
2836
|
+
return name === ((_root$params$5 = root.params[0]) === null || _root$params$5 === void 0 ? void 0 : _root$params$5.name);
|
|
2837
|
+
}
|
|
2884
2838
|
}
|
|
2885
2839
|
};
|
|
2886
2840
|
const MERGE_PATTERNS = [{
|
|
2887
2841
|
// x => ({ ...x, y: 10, z: 11 })
|
|
2888
|
-
params: [{
|
|
2889
|
-
type:
|
|
2890
|
-
}],
|
|
2842
|
+
params: params => params.length === 1 && matches([{
|
|
2843
|
+
type: TYPES.IDENTIFIER
|
|
2844
|
+
}], params),
|
|
2891
2845
|
body: {
|
|
2892
|
-
type:
|
|
2846
|
+
type: TYPES.OBJECT_EXPRESSION,
|
|
2893
2847
|
properties: [{
|
|
2894
|
-
type:
|
|
2848
|
+
type: TYPES.SPREAD_ELEMENT,
|
|
2895
2849
|
argument: {
|
|
2896
|
-
type:
|
|
2850
|
+
type: TYPES.IDENTIFIER,
|
|
2851
|
+
name: (name, root) => {
|
|
2852
|
+
var _root$params$6;
|
|
2853
|
+
|
|
2854
|
+
return name === ((_root$params$6 = root.params[0]) === null || _root$params$6 === void 0 ? void 0 : _root$params$6.name);
|
|
2855
|
+
}
|
|
2897
2856
|
}
|
|
2898
2857
|
}, {
|
|
2899
|
-
type:
|
|
2858
|
+
type: TYPES.PROPERTY
|
|
2900
2859
|
}, {
|
|
2901
|
-
type:
|
|
2860
|
+
type: TYPES.PROPERTY
|
|
2902
2861
|
}]
|
|
2903
2862
|
}
|
|
2904
2863
|
}, {
|
|
2905
2864
|
// x => ({ ...x, y: 10, ...z })
|
|
2906
|
-
params: [{
|
|
2907
|
-
type:
|
|
2908
|
-
}],
|
|
2865
|
+
params: params => params.length === 1 && matches([{
|
|
2866
|
+
type: TYPES.IDENTIFIER
|
|
2867
|
+
}], params),
|
|
2909
2868
|
body: {
|
|
2910
|
-
type:
|
|
2869
|
+
type: TYPES.OBJECT_EXPRESSION,
|
|
2911
2870
|
properties: [{
|
|
2912
|
-
type:
|
|
2871
|
+
type: TYPES.SPREAD_ELEMENT,
|
|
2913
2872
|
argument: {
|
|
2914
|
-
type:
|
|
2873
|
+
type: TYPES.IDENTIFIER,
|
|
2874
|
+
name: (name, root) => {
|
|
2875
|
+
var _root$params$7;
|
|
2876
|
+
|
|
2877
|
+
return name === ((_root$params$7 = root.params[0]) === null || _root$params$7 === void 0 ? void 0 : _root$params$7.name);
|
|
2878
|
+
}
|
|
2915
2879
|
}
|
|
2916
2880
|
}, {
|
|
2917
|
-
type:
|
|
2881
|
+
type: TYPES.PROPERTY
|
|
2918
2882
|
}, {
|
|
2919
|
-
type:
|
|
2883
|
+
type: TYPES.SPREAD_ELEMENT
|
|
2920
2884
|
}]
|
|
2921
2885
|
}
|
|
2922
2886
|
}, {
|
|
2923
2887
|
// x => ({ ...x, ...y })
|
|
2924
|
-
params: [{
|
|
2925
|
-
type:
|
|
2926
|
-
}],
|
|
2888
|
+
params: params => params.length === 1 && matches([{
|
|
2889
|
+
type: TYPES.IDENTIFIER
|
|
2890
|
+
}], params),
|
|
2927
2891
|
body: {
|
|
2928
|
-
type:
|
|
2892
|
+
type: TYPES.OBJECT_EXPRESSION,
|
|
2929
2893
|
properties: [{
|
|
2930
|
-
type:
|
|
2894
|
+
type: TYPES.SPREAD_ELEMENT,
|
|
2931
2895
|
argument: {
|
|
2932
|
-
type:
|
|
2896
|
+
type: TYPES.IDENTIFIER,
|
|
2897
|
+
name: (name, root) => {
|
|
2898
|
+
var _root$params$8;
|
|
2899
|
+
|
|
2900
|
+
return name === ((_root$params$8 = root.params[0]) === null || _root$params$8 === void 0 ? void 0 : _root$params$8.name);
|
|
2901
|
+
}
|
|
2933
2902
|
}
|
|
2934
2903
|
}, {
|
|
2935
|
-
type:
|
|
2904
|
+
type: TYPES.SPREAD_ELEMENT
|
|
2936
2905
|
}]
|
|
2937
2906
|
}
|
|
2938
2907
|
}];
|
|
2939
2908
|
const PLUCK_PATTERNS = {
|
|
2940
2909
|
OBJECT_ARROW_FUNCTION: {
|
|
2941
2910
|
callee: {
|
|
2942
|
-
type:
|
|
2911
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
2943
2912
|
property: {
|
|
2944
2913
|
name: "map"
|
|
2945
2914
|
}
|
|
2946
2915
|
},
|
|
2947
2916
|
arguments: [{
|
|
2948
|
-
type:
|
|
2917
|
+
type: TYPES.ARROW_FUNCTION_EXPRESSION
|
|
2949
2918
|
}]
|
|
2950
2919
|
},
|
|
2951
2920
|
IDENTIFIER: {
|
|
2952
2921
|
// abc.map(x => x.a);
|
|
2953
2922
|
params: [{
|
|
2954
|
-
type:
|
|
2923
|
+
type: TYPES.IDENTIFIER
|
|
2955
2924
|
}],
|
|
2956
2925
|
body: {
|
|
2957
|
-
type:
|
|
2926
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
2958
2927
|
object: {
|
|
2959
|
-
type:
|
|
2928
|
+
type: TYPES.IDENTIFIER,
|
|
2929
|
+
name: (name, root) => {
|
|
2930
|
+
var _root$params$9;
|
|
2931
|
+
|
|
2932
|
+
return name === ((_root$params$9 = root.params[0]) === null || _root$params$9 === void 0 ? void 0 : _root$params$9.name);
|
|
2933
|
+
}
|
|
2960
2934
|
},
|
|
2961
2935
|
property: {
|
|
2962
|
-
type:
|
|
2936
|
+
type: TYPES.IDENTIFIER
|
|
2963
2937
|
}
|
|
2964
2938
|
}
|
|
2965
2939
|
},
|
|
2966
2940
|
DESTRUCTURE: {
|
|
2967
2941
|
// abc.map(({ a }) => a);
|
|
2968
2942
|
params: [{
|
|
2969
|
-
type:
|
|
2943
|
+
type: TYPES.OBJECT_PATTERN,
|
|
2970
2944
|
properties: [{
|
|
2971
|
-
type:
|
|
2945
|
+
type: TYPES.PROPERTY,
|
|
2972
2946
|
key: {
|
|
2973
|
-
type:
|
|
2947
|
+
type: TYPES.IDENTIFIER
|
|
2974
2948
|
},
|
|
2975
2949
|
value: {
|
|
2976
|
-
type:
|
|
2950
|
+
type: TYPES.IDENTIFIER,
|
|
2951
|
+
name: (name, root) => {
|
|
2952
|
+
var _root$body;
|
|
2953
|
+
|
|
2954
|
+
return name === ((_root$body = root.body) === null || _root$body === void 0 ? void 0 : _root$body.name);
|
|
2955
|
+
}
|
|
2977
2956
|
}
|
|
2978
2957
|
}]
|
|
2979
2958
|
}],
|
|
2980
2959
|
body: {
|
|
2981
|
-
type:
|
|
2960
|
+
type: TYPES.IDENTIFIER
|
|
2982
2961
|
}
|
|
2983
2962
|
}
|
|
2984
2963
|
};
|
|
@@ -2989,16 +2968,21 @@
|
|
|
2989
2968
|
async: false,
|
|
2990
2969
|
expression: true,
|
|
2991
2970
|
params: [{
|
|
2992
|
-
type:
|
|
2971
|
+
type: TYPES.OBJECT_PATTERN,
|
|
2993
2972
|
properties: [{
|
|
2994
|
-
type:
|
|
2973
|
+
type: TYPES.PROPERTY,
|
|
2995
2974
|
value: {
|
|
2996
|
-
type:
|
|
2975
|
+
type: TYPES.IDENTIFIER,
|
|
2976
|
+
name: (name, root) => {
|
|
2977
|
+
var _root$body2;
|
|
2978
|
+
|
|
2979
|
+
return name === ((_root$body2 = root.body) === null || _root$body2 === void 0 ? void 0 : _root$body2.name);
|
|
2980
|
+
}
|
|
2997
2981
|
}
|
|
2998
2982
|
}]
|
|
2999
2983
|
}],
|
|
3000
2984
|
body: {
|
|
3001
|
-
type:
|
|
2985
|
+
type: TYPES.IDENTIFIER
|
|
3002
2986
|
}
|
|
3003
2987
|
},
|
|
3004
2988
|
IDENTITY: {
|
|
@@ -3007,62 +2991,67 @@
|
|
|
3007
2991
|
async: false,
|
|
3008
2992
|
expression: true,
|
|
3009
2993
|
params: [{
|
|
3010
|
-
type:
|
|
2994
|
+
type: TYPES.IDENTIFIER
|
|
3011
2995
|
}],
|
|
3012
2996
|
body: {
|
|
3013
|
-
type:
|
|
2997
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
3014
2998
|
object: {
|
|
3015
|
-
type:
|
|
2999
|
+
type: TYPES.IDENTIFIER,
|
|
3000
|
+
name: (name, root) => {
|
|
3001
|
+
var _root$params$10;
|
|
3002
|
+
|
|
3003
|
+
return name === ((_root$params$10 = root.params[0]) === null || _root$params$10 === void 0 ? void 0 : _root$params$10.name);
|
|
3004
|
+
}
|
|
3016
3005
|
},
|
|
3017
3006
|
property: {
|
|
3018
|
-
type:
|
|
3007
|
+
type: TYPES.IDENTIFIER
|
|
3019
3008
|
}
|
|
3020
3009
|
}
|
|
3021
3010
|
}
|
|
3022
3011
|
};
|
|
3023
3012
|
const SUM_PATTERN = {
|
|
3024
3013
|
callee: {
|
|
3025
|
-
type:
|
|
3014
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
3026
3015
|
property: {
|
|
3027
|
-
type:
|
|
3016
|
+
type: TYPES.IDENTIFIER,
|
|
3028
3017
|
name: "reduce"
|
|
3029
3018
|
}
|
|
3030
3019
|
},
|
|
3031
3020
|
arguments: [{
|
|
3032
|
-
type:
|
|
3021
|
+
type: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
3033
3022
|
generator: false,
|
|
3034
3023
|
async: false,
|
|
3035
3024
|
expression: true,
|
|
3036
3025
|
body: {
|
|
3037
|
-
type:
|
|
3026
|
+
type: TYPES.BINARY_EXPRESSION,
|
|
3038
3027
|
operator: "+"
|
|
3039
3028
|
},
|
|
3040
3029
|
params: [{
|
|
3041
|
-
type:
|
|
3030
|
+
type: TYPES.IDENTIFIER
|
|
3042
3031
|
}]
|
|
3043
3032
|
}, {
|
|
3044
|
-
type:
|
|
3033
|
+
type: TYPES.LITERAL,
|
|
3045
3034
|
value: 0
|
|
3046
3035
|
}]
|
|
3047
3036
|
};
|
|
3048
3037
|
const RAMDA_IMPORT_PATTERN = {
|
|
3049
|
-
type:
|
|
3038
|
+
type: TYPES.IMPORT_DECLARATION,
|
|
3050
3039
|
source: {
|
|
3051
|
-
type:
|
|
3040
|
+
type: TYPES.LITERAL,
|
|
3052
3041
|
value: "ramda"
|
|
3053
3042
|
},
|
|
3054
3043
|
specifiers: [{
|
|
3055
|
-
type:
|
|
3044
|
+
type: TYPES.IMPORT_SPECIFIER
|
|
3056
3045
|
}]
|
|
3057
3046
|
}; // when ({ name }) => name is used inside something.map(...), ignore it.
|
|
3058
3047
|
// It will be picked up by pluck function
|
|
3059
3048
|
|
|
3060
3049
|
const PROP_IGNORE_PATTERN = {
|
|
3061
|
-
type:
|
|
3050
|
+
type: TYPES.CALL_EXPRESSION,
|
|
3062
3051
|
callee: {
|
|
3063
|
-
type:
|
|
3052
|
+
type: TYPES.MEMBER_EXPRESSION,
|
|
3064
3053
|
property: {
|
|
3065
|
-
type:
|
|
3054
|
+
type: TYPES.IDENTIFIER,
|
|
3066
3055
|
name: "map"
|
|
3067
3056
|
}
|
|
3068
3057
|
}
|
|
@@ -3071,7 +3060,11 @@
|
|
|
3071
3060
|
{
|
|
3072
3061
|
operator: "||",
|
|
3073
3062
|
left: NIL_BINARY_EXP_PATTERN,
|
|
3074
|
-
right:
|
|
3063
|
+
right: (right, root) => {
|
|
3064
|
+
var _right$left, _root$left, _root$left$left;
|
|
3065
|
+
|
|
3066
|
+
return matches(NIL_BINARY_EXP_PATTERN, right) && ((_right$left = right.left) === null || _right$left === void 0 ? void 0 : _right$left.name) === ((_root$left = root.left) === null || _root$left === void 0 ? void 0 : (_root$left$left = _root$left.left) === null || _root$left$left === void 0 ? void 0 : _root$left$left.name);
|
|
3067
|
+
}
|
|
3075
3068
|
};
|
|
3076
3069
|
const EMPTY_PATTERN = [// array.length === 0, Object.keys(obj).length === 0, if(array.length === 0), while(array.length === 0)
|
|
3077
3070
|
{
|
|
@@ -3092,27 +3085,17 @@
|
|
|
3092
3085
|
const replacer = nodeReplacerWithImports(RAMDA_IMPORT_PATTERN);
|
|
3093
3086
|
|
|
3094
3087
|
var arrayInsertsLintCheck = {
|
|
3095
|
-
operateOn:
|
|
3088
|
+
operateOn: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
3096
3089
|
check: (context, node) => {
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
body
|
|
3100
|
-
} = node;
|
|
3101
|
-
|
|
3102
|
-
if (body.type !== TYPES.ARRAY_EXPRESSION || body.elements.length !== 2) {
|
|
3103
|
-
return;
|
|
3104
|
-
}
|
|
3105
|
-
|
|
3106
|
-
const {
|
|
3107
|
-
elements
|
|
3108
|
-
} = body;
|
|
3090
|
+
if (!matches(ARRAY_PATTERN, node)) return;
|
|
3091
|
+
const elements = node.body.elements;
|
|
3109
3092
|
let fix = null;
|
|
3110
3093
|
|
|
3111
|
-
if (matches(ARRAY_INSERTS_PATTERN.APPEND, node)
|
|
3094
|
+
if (matches(ARRAY_INSERTS_PATTERN.APPEND, node)) {
|
|
3112
3095
|
fix = `append(${getCode$1(context, elements[1])})`;
|
|
3113
|
-
} else if (matches(ARRAY_INSERTS_PATTERN.PREPEND, node)
|
|
3096
|
+
} else if (matches(ARRAY_INSERTS_PATTERN.PREPEND, node)) {
|
|
3114
3097
|
fix = `prepend(${getCode$1(context, elements[0])})`;
|
|
3115
|
-
} else if (matches(ARRAY_INSERTS_PATTERN.CONCAT, node)
|
|
3098
|
+
} else if (matches(ARRAY_INSERTS_PATTERN.CONCAT, node)) {
|
|
3116
3099
|
fix = `concat(${getCode$1(context, elements[1].argument)})`;
|
|
3117
3100
|
}
|
|
3118
3101
|
|
|
@@ -3141,15 +3124,12 @@
|
|
|
3141
3124
|
};
|
|
3142
3125
|
|
|
3143
3126
|
var assocLintCheck = {
|
|
3144
|
-
operateOn:
|
|
3127
|
+
operateOn: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
3145
3128
|
check: (context, node) => {
|
|
3146
|
-
if (node.params.length !== 1) return;
|
|
3147
3129
|
if (!matches(ASSOC_PATTERN, node)) return;
|
|
3148
|
-
if (node.body.properties.length !== 2) return;
|
|
3149
|
-
if (node.body.properties[0].argument.name !== node.params[0].name) return;
|
|
3150
3130
|
const property = node.body.properties[1];
|
|
3151
3131
|
const selfReferencingPattern = {
|
|
3152
|
-
type:
|
|
3132
|
+
type: TYPES.IDENTIFIER,
|
|
3153
3133
|
name: node.params[0].name
|
|
3154
3134
|
};
|
|
3155
3135
|
if (patternExistsDeep(selfReferencingPattern, property.value)) return;
|
|
@@ -3171,7 +3151,7 @@
|
|
|
3171
3151
|
};
|
|
3172
3152
|
|
|
3173
3153
|
var equalsLintCheck = {
|
|
3174
|
-
operateOn:
|
|
3154
|
+
operateOn: TYPES.BINARY_EXPRESSION,
|
|
3175
3155
|
check: (context, node) => {
|
|
3176
3156
|
if (matches(JSON_EQUALS_PATTERN, node)) {
|
|
3177
3157
|
const fix = `equals(${getCode$1(context, node.left.arguments[0])}, ${getCode$1(context, node.right.arguments[0])})`;
|
|
@@ -3193,9 +3173,9 @@
|
|
|
3193
3173
|
};
|
|
3194
3174
|
|
|
3195
3175
|
var identityLintCheck = {
|
|
3196
|
-
operateOn:
|
|
3176
|
+
operateOn: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
3197
3177
|
check: (context, node) => {
|
|
3198
|
-
if (matches(IDENTITY_PATTERN, node)
|
|
3178
|
+
if (matches(IDENTITY_PATTERN, node)) {
|
|
3199
3179
|
context.report({
|
|
3200
3180
|
node,
|
|
3201
3181
|
message: canBeReplacedWith("identity"),
|
|
@@ -3246,7 +3226,6 @@
|
|
|
3246
3226
|
operateOn: TYPES.LOGICAL_EXPRESSION,
|
|
3247
3227
|
check: (context, node) => {
|
|
3248
3228
|
if (!matches(NIL_PATTERN, node)) return;
|
|
3249
|
-
if (node.left.left.name !== node.right.left.name) return;
|
|
3250
3229
|
const fix = `isNil(${node.left.left.name})`;
|
|
3251
3230
|
reportSuggestion({
|
|
3252
3231
|
context,
|
|
@@ -3268,14 +3247,12 @@
|
|
|
3268
3247
|
};
|
|
3269
3248
|
|
|
3270
3249
|
var mergeLintCheck = {
|
|
3271
|
-
operateOn:
|
|
3250
|
+
operateOn: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
3272
3251
|
check: (context, node) => {
|
|
3273
|
-
if (node.params.length !== 1) return;
|
|
3274
3252
|
const matchIndex = findPatternIndex(node);
|
|
3275
3253
|
if (matchIndex < 0) return;
|
|
3276
|
-
if (node.body.properties[0].argument.name !== node.params[0].name) return;
|
|
3277
3254
|
const selfReferencingPattern = {
|
|
3278
|
-
type:
|
|
3255
|
+
type: TYPES.IDENTIFIER,
|
|
3279
3256
|
name: node.params[0].name
|
|
3280
3257
|
};
|
|
3281
3258
|
const properties = node.body.properties.slice(1);
|
|
@@ -3312,19 +3289,17 @@
|
|
|
3312
3289
|
});
|
|
3313
3290
|
|
|
3314
3291
|
var pluckLintCheck = {
|
|
3315
|
-
operateOn:
|
|
3292
|
+
operateOn: TYPES.CALL_EXPRESSION,
|
|
3316
3293
|
check: (context, node) => {
|
|
3317
3294
|
if (matches(PLUCK_PATTERNS.OBJECT_ARROW_FUNCTION, node)) {
|
|
3318
3295
|
const code = getCode$1(context, node.callee.object);
|
|
3319
3296
|
const func = node.arguments[0];
|
|
3320
3297
|
|
|
3321
3298
|
if (matches(PLUCK_PATTERNS.IDENTIFIER, func)) {
|
|
3322
|
-
if (func.params[0].name !== func.body.object.name) return;
|
|
3323
3299
|
const fix = `pluck("${func.body.property.name}", ${code})`;
|
|
3324
3300
|
reportViolation(context, node, fix);
|
|
3325
3301
|
} else if (matches(PLUCK_PATTERNS.DESTRUCTURE, func)) {
|
|
3326
3302
|
const propertyName = func.params[0].properties[0].value.name;
|
|
3327
|
-
if (propertyName !== func.body.name) return;
|
|
3328
3303
|
const fix = `pluck("${propertyName}", ${code})`;
|
|
3329
3304
|
reportViolation(context, node, fix);
|
|
3330
3305
|
}
|
|
@@ -3333,14 +3308,14 @@
|
|
|
3333
3308
|
};
|
|
3334
3309
|
|
|
3335
3310
|
var propLintCheck = {
|
|
3336
|
-
operateOn:
|
|
3311
|
+
operateOn: TYPES.ARROW_FUNCTION_EXPRESSION,
|
|
3337
3312
|
check: (context, node) => {
|
|
3338
3313
|
let fix = null;
|
|
3339
3314
|
if (matches(PROP_IGNORE_PATTERN, node.parent)) return;
|
|
3340
3315
|
|
|
3341
|
-
if (matches(PROP_PATTERNS.OBJECT, node)
|
|
3316
|
+
if (matches(PROP_PATTERNS.OBJECT, node)) {
|
|
3342
3317
|
fix = `prop("${node.body.name}")`;
|
|
3343
|
-
} else if (matches(PROP_PATTERNS.IDENTITY, node)
|
|
3318
|
+
} else if (matches(PROP_PATTERNS.IDENTITY, node)) {
|
|
3344
3319
|
fix = `prop("${node.body.property.name}")`;
|
|
3345
3320
|
} else {
|
|
3346
3321
|
return;
|
|
@@ -3383,7 +3358,7 @@
|
|
|
3383
3358
|
};
|
|
3384
3359
|
|
|
3385
3360
|
var sumLintCheck = {
|
|
3386
|
-
operateOn:
|
|
3361
|
+
operateOn: TYPES.CALL_EXPRESSION,
|
|
3387
3362
|
check: (context, node) => {
|
|
3388
3363
|
if (!matches(SUM_PATTERN, node)) return;
|
|
3389
3364
|
const reduceFunc = node.arguments[0];
|
|
@@ -3444,6 +3419,7 @@
|
|
|
3444
3419
|
}
|
|
3445
3420
|
};
|
|
3446
3421
|
|
|
3422
|
+
const VALID_URL_TYPES = [TYPES.LITERAL, TYPES.TEMPLATE_LITERAL];
|
|
3447
3423
|
const AXIOS_GET_PATTERN = {
|
|
3448
3424
|
callee: {
|
|
3449
3425
|
type: TYPES.MEMBER_EXPRESSION,
|
|
@@ -3455,15 +3431,20 @@
|
|
|
3455
3431
|
name: "get",
|
|
3456
3432
|
type: TYPES.IDENTIFIER
|
|
3457
3433
|
}
|
|
3458
|
-
}
|
|
3434
|
+
},
|
|
3435
|
+
arguments: [{
|
|
3436
|
+
type: ramda.includes(ramda.__, VALID_URL_TYPES)
|
|
3437
|
+
}]
|
|
3459
3438
|
};
|
|
3460
3439
|
const AXIOS_PATTERN = {
|
|
3461
3440
|
callee: {
|
|
3462
3441
|
name: "axios",
|
|
3463
3442
|
type: TYPES.IDENTIFIER
|
|
3464
|
-
}
|
|
3443
|
+
},
|
|
3444
|
+
arguments: [{
|
|
3445
|
+
type: ramda.includes(ramda.__, [TYPES.LITERAL, TYPES.TEMPLATE_LITERAL, TYPES.OBJECT_EXPRESSION])
|
|
3446
|
+
}]
|
|
3465
3447
|
};
|
|
3466
|
-
const VALID_URL_TYPES = [TYPES.LITERAL, TYPES.TEMPLATE_LITERAL];
|
|
3467
3448
|
|
|
3468
3449
|
const getPropValue = (configNode, name) => {
|
|
3469
3450
|
var _configNode$propertie;
|
|
@@ -3473,26 +3454,25 @@
|
|
|
3473
3454
|
}) => key.name === name)) === null || _configNode$propertie === void 0 ? void 0 : _configNode$propertie.value;
|
|
3474
3455
|
};
|
|
3475
3456
|
|
|
3476
|
-
const containsQuestionMark = ({
|
|
3477
|
-
quasis
|
|
3478
|
-
}) => quasis.some(({
|
|
3479
|
-
value
|
|
3480
|
-
}) => value.cooked.includes("?"));
|
|
3481
|
-
|
|
3482
3457
|
const checkAndReport = ({
|
|
3483
3458
|
context,
|
|
3484
3459
|
node,
|
|
3485
3460
|
urlNode
|
|
3486
3461
|
}) => {
|
|
3487
|
-
|
|
3488
|
-
const urlStringContainsQuery = urlNode.type === TYPES.LITERAL && urlNode.value.includes("?");
|
|
3462
|
+
let isQuestionMarkPresent = false;
|
|
3489
3463
|
|
|
3490
|
-
if (
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3464
|
+
if (urlNode.type === TYPES.LITERAL) {
|
|
3465
|
+
isQuestionMarkPresent = urlNode.value.includes("?");
|
|
3466
|
+
} else {
|
|
3467
|
+
isQuestionMarkPresent = urlNode.quasis.some(({
|
|
3468
|
+
value
|
|
3469
|
+
}) => value.cooked.includes("?"));
|
|
3495
3470
|
}
|
|
3471
|
+
|
|
3472
|
+
if (isQuestionMarkPresent) context.report({
|
|
3473
|
+
node,
|
|
3474
|
+
message: USE_AXIOS_CONFIG_FOR_PASSING_QUERY_PARAMETERS_MESSAGE
|
|
3475
|
+
});
|
|
3496
3476
|
};
|
|
3497
3477
|
|
|
3498
3478
|
var useAxiosConfigForPassingQueryParameters = {
|
|
@@ -3505,7 +3485,6 @@
|
|
|
3505
3485
|
create: context => ({
|
|
3506
3486
|
CallExpression(node) {
|
|
3507
3487
|
if (matches(AXIOS_GET_PATTERN, node)) {
|
|
3508
|
-
if (!VALID_URL_TYPES.includes(node.arguments[0].type)) return;
|
|
3509
3488
|
checkAndReport({
|
|
3510
3489
|
context,
|
|
3511
3490
|
node,
|
|
@@ -3517,21 +3496,16 @@
|
|
|
3517
3496
|
let methodNode = null;
|
|
3518
3497
|
let urlNode = null;
|
|
3519
3498
|
|
|
3520
|
-
if (
|
|
3521
|
-
urlNode = node.arguments[0];
|
|
3522
|
-
methodNode = getPropValue(node.arguments[1], "method");
|
|
3523
|
-
} else if (node.arguments[0].type === TYPES.OBJECT_EXPRESSION) {
|
|
3499
|
+
if (node.arguments[0].type === TYPES.OBJECT_EXPRESSION) {
|
|
3524
3500
|
urlNode = getPropValue(node.arguments[0], "url");
|
|
3525
3501
|
methodNode = getPropValue(node.arguments[0], "method");
|
|
3502
|
+
if (!VALID_URL_TYPES.includes(urlNode.type)) return;
|
|
3503
|
+
} else {
|
|
3504
|
+
urlNode = node.arguments[0];
|
|
3505
|
+
methodNode = getPropValue(node.arguments[1], "method");
|
|
3526
3506
|
}
|
|
3527
3507
|
|
|
3528
|
-
if (
|
|
3529
|
-
|
|
3530
|
-
if (((_methodNode = methodNode) === null || _methodNode === void 0 ? void 0 : _methodNode.value.toLowerCase()) !== "get") {
|
|
3531
|
-
return;
|
|
3532
|
-
}
|
|
3533
|
-
|
|
3534
|
-
if (!VALID_URL_TYPES.includes(urlNode.type)) return;
|
|
3508
|
+
if (((_methodNode = methodNode) === null || _methodNode === void 0 ? void 0 : _methodNode.value.toLowerCase()) !== "get") return;
|
|
3535
3509
|
checkAndReport({
|
|
3536
3510
|
context,
|
|
3537
3511
|
node,
|
|
@@ -3592,21 +3566,66 @@
|
|
|
3592
3566
|
const aliases = context.options[0];
|
|
3593
3567
|
if (ramda.isEmpty(aliases) || ramda.isNil(aliases)) return;
|
|
3594
3568
|
const importPath = node.source.value;
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3569
|
+
let importPathWithAlias = "";
|
|
3570
|
+
|
|
3571
|
+
if (importPath.startsWith("../")) {
|
|
3572
|
+
const filename = context.getFilename();
|
|
3573
|
+
const importFullPath = path__default["default"].resolve(filename, "../", importPath);
|
|
3574
|
+
const matches = Object.entries(aliases).filter(([, path]) => importFullPath.startsWith(path)).sort((first, second) => first.length - second.length);
|
|
3575
|
+
if (matches.length === 0) return;
|
|
3576
|
+
const aliasMatch = matches[matches.length - 1];
|
|
3577
|
+
importPathWithAlias = importFullPath.replace(aliasMatch[1], aliasMatch[0]);
|
|
3578
|
+
if (importPath.length < importPathWithAlias.length) return;
|
|
3579
|
+
} else {
|
|
3580
|
+
const aliasMatch = Object.entries(aliases).find(([, path]) => importPath.startsWith(path));
|
|
3581
|
+
if (!aliasMatch) return;
|
|
3582
|
+
importPathWithAlias = importPath.replace(aliasMatch[1], aliasMatch[0]);
|
|
3609
3583
|
}
|
|
3584
|
+
|
|
3585
|
+
context.report({
|
|
3586
|
+
node,
|
|
3587
|
+
message: canBeReplacedWith(importPathWithAlias),
|
|
3588
|
+
fix: fixer => fixer.replaceText(node.source, `"${importPathWithAlias}"`)
|
|
3589
|
+
});
|
|
3590
|
+
}
|
|
3591
|
+
|
|
3592
|
+
})
|
|
3593
|
+
};
|
|
3594
|
+
|
|
3595
|
+
const removeComments = json => JSON.parse(json.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => g ? "" : m));
|
|
3596
|
+
|
|
3597
|
+
const parseJsconfigData = ramda.memoizeWith(ramda.identity, jsconfigFilePath => {
|
|
3598
|
+
if (!jsconfigFilePath) return null;
|
|
3599
|
+
const jsonData = fs__default["default"].readFileSync(jsconfigFilePath).toString();
|
|
3600
|
+
const parsedJsonData = removeComments(jsonData);
|
|
3601
|
+
return parsedJsonData;
|
|
3602
|
+
});
|
|
3603
|
+
var webpackAliasesAndJsconfigPathsShouldBeInSync = {
|
|
3604
|
+
meta: {
|
|
3605
|
+
type: "problem",
|
|
3606
|
+
docs: {
|
|
3607
|
+
description: "Ensures that webpack alias and jsconfig are in sync"
|
|
3608
|
+
}
|
|
3609
|
+
},
|
|
3610
|
+
create: context => ({
|
|
3611
|
+
Property(node) {
|
|
3612
|
+
var _node$parent, _node$parent$parent, _node$parent$parent$k, _jsconfigData$compile;
|
|
3613
|
+
|
|
3614
|
+
const filename = context.getFilename();
|
|
3615
|
+
const isInsideAliasFile = filename.endsWith(WEBPACK_ALIAS_PATH);
|
|
3616
|
+
if (!isInsideAliasFile) return;
|
|
3617
|
+
const isInsideAliasProperty = ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : (_node$parent$parent = _node$parent.parent) === null || _node$parent$parent === void 0 ? void 0 : (_node$parent$parent$k = _node$parent$parent.key) === null || _node$parent$parent$k === void 0 ? void 0 : _node$parent$parent$k.name) === "alias";
|
|
3618
|
+
if (!isInsideAliasProperty) return;
|
|
3619
|
+
const jsconfigData = parseJsconfigData(context.options[0]);
|
|
3620
|
+
const jsconfigPaths = jsconfigData === null || jsconfigData === void 0 ? void 0 : (_jsconfigData$compile = jsconfigData.compilerOptions) === null || _jsconfigData$compile === void 0 ? void 0 : _jsconfigData$compile.paths;
|
|
3621
|
+
if (!jsconfigPaths) return;
|
|
3622
|
+
const aliasName = node.key.name;
|
|
3623
|
+
const matches = Object.keys(jsconfigPaths).some(ramda.includes(ramda.__, [aliasName, `${aliasName}/*`]));
|
|
3624
|
+
if (matches) return;
|
|
3625
|
+
context.report({
|
|
3626
|
+
node,
|
|
3627
|
+
message: addInJsconfig(aliasName)
|
|
3628
|
+
});
|
|
3610
3629
|
}
|
|
3611
3630
|
|
|
3612
3631
|
})
|
|
@@ -3639,7 +3658,8 @@
|
|
|
3639
3658
|
"use-constant-case": useConstantCase,
|
|
3640
3659
|
"use-common-routes": useCommonRoutes,
|
|
3641
3660
|
"use-snake-case-for-api-connector-filename": useSnakeCaseForApiConnectorFilename,
|
|
3642
|
-
"use-webpack-alias": useWebpackAlias
|
|
3661
|
+
"use-webpack-alias": useWebpackAlias,
|
|
3662
|
+
"webpack-aliases-and-jsconfig-paths-should-be-in-sync": webpackAliasesAndJsconfigPathsShouldBeInSync
|
|
3643
3663
|
}
|
|
3644
3664
|
};
|
|
3645
3665
|
|