@agilebot/eslint-plugin 0.3.7 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +9 -9
- package/LICENSE.tpl +8 -8
- package/README.md +9 -9
- package/dist/index.js +173 -18
- package/package.json +4 -3
package/LICENSE
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2024 Agilebot, Inc.
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
-
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
-
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Agilebot, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/LICENSE.tpl
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
/**
|
2
|
-
* @license %(name)s v%(version)s
|
3
|
-
*
|
4
|
-
* Copyright (c) Agilebot, Inc. and its affiliates.
|
5
|
-
*
|
6
|
-
* This source code is licensed under the MIT license found in the
|
7
|
-
* LICENSE file in the root directory of this source tree.
|
8
|
-
*/
|
1
|
+
/**
|
2
|
+
* @license %(name)s v%(version)s
|
3
|
+
*
|
4
|
+
* Copyright (c) Agilebot, Inc. and its affiliates.
|
5
|
+
*
|
6
|
+
* This source code is licensed under the MIT license found in the
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
8
|
+
*/
|
package/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
# @agilebot/eslint-plugin
|
2
|
-
|
3
|
-
Agilebot extended ESLint rules. For @agilebot/eslint-config.
|
4
|
-
|
5
|
-
### Usage
|
6
|
-
|
7
|
-
```bash
|
8
|
-
npm install --save-dev eslint @agilebot/eslint-plugin
|
9
|
-
```
|
1
|
+
# @agilebot/eslint-plugin
|
2
|
+
|
3
|
+
Agilebot extended ESLint rules. For @agilebot/eslint-config.
|
4
|
+
|
5
|
+
### Usage
|
6
|
+
|
7
|
+
```bash
|
8
|
+
npm install --save-dev eslint @agilebot/eslint-plugin
|
9
|
+
```
|
package/dist/index.js
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
/**
|
2
|
-
* @license @agilebot/eslint-plugin v0.3.
|
3
|
-
*
|
4
|
-
* Copyright (c) Agilebot, Inc. and its affiliates.
|
5
|
-
*
|
6
|
-
* This source code is licensed under the MIT license found in the
|
7
|
-
* LICENSE file in the root directory of this source tree.
|
8
|
-
*/
|
1
|
+
/**
|
2
|
+
* @license @agilebot/eslint-plugin v0.3.9
|
3
|
+
*
|
4
|
+
* Copyright (c) Agilebot, Inc. and its affiliates.
|
5
|
+
*
|
6
|
+
* This source code is licensed under the MIT license found in the
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
8
|
+
*/
|
9
9
|
'use strict';
|
10
10
|
|
11
|
+
var eslintUtils = require('@agilebot/eslint-utils');
|
11
12
|
var fs = require('node:fs');
|
12
13
|
var path = require('node:path');
|
13
|
-
var eslintUtils = require('@agilebot/eslint-utils');
|
14
14
|
var utils = require('@typescript-eslint/utils');
|
15
15
|
|
16
16
|
function _interopNamespaceDefault(e) {
|
@@ -72,6 +72,123 @@ var enforceMuiIconAlias = {
|
|
72
72
|
}
|
73
73
|
};
|
74
74
|
|
75
|
+
var funcNaming = {
|
76
|
+
meta: {
|
77
|
+
docs: {
|
78
|
+
description: 'Enforce function naming convention'
|
79
|
+
},
|
80
|
+
schema: [{
|
81
|
+
type: 'object',
|
82
|
+
properties: {
|
83
|
+
format: {
|
84
|
+
"enum": ['camelCase', 'PascalCase']
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}],
|
88
|
+
messages: {
|
89
|
+
invalidFuncNaming: 'Invalid function naming for non-React component, expected {{format}}',
|
90
|
+
invalidReactFCNaming: 'Invalid naming convention for React functional component, expected PascalCase'
|
91
|
+
}
|
92
|
+
},
|
93
|
+
create(context) {
|
94
|
+
if (!context.options[0]) {
|
95
|
+
throw new Error('Missing options');
|
96
|
+
}
|
97
|
+
const format = context.options[0].format;
|
98
|
+
function validate({
|
99
|
+
node,
|
100
|
+
fnName
|
101
|
+
}) {
|
102
|
+
let isPass;
|
103
|
+
switch (format) {
|
104
|
+
case 'camelCase':
|
105
|
+
if (!eslintUtils.isCamelCase(fnName)) {
|
106
|
+
isPass = false;
|
107
|
+
}
|
108
|
+
break;
|
109
|
+
case 'PascalCase':
|
110
|
+
if (!eslintUtils.isPascalCase(fnName)) {
|
111
|
+
isPass = false;
|
112
|
+
}
|
113
|
+
break;
|
114
|
+
}
|
115
|
+
if (isPass === false) {
|
116
|
+
context.report({
|
117
|
+
node: node,
|
118
|
+
messageId: 'invalidFuncNaming',
|
119
|
+
data: {
|
120
|
+
format
|
121
|
+
}
|
122
|
+
});
|
123
|
+
}
|
124
|
+
}
|
125
|
+
function checkJSXElement(node) {
|
126
|
+
if (!node) {
|
127
|
+
return false;
|
128
|
+
}
|
129
|
+
if (node.type === 'JSXElement' || node.type === 'JSXFragment') {
|
130
|
+
return true;
|
131
|
+
}
|
132
|
+
if (node.type === 'BlockStatement') {
|
133
|
+
for (const statement of node.body) {
|
134
|
+
if (statement.type === 'ReturnStatement') {
|
135
|
+
if (checkJSXElement(statement.argument)) {
|
136
|
+
return true;
|
137
|
+
}
|
138
|
+
} else if (checkJSXElement(statement)) {
|
139
|
+
return true;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression') {
|
144
|
+
return checkJSXElement(node.body);
|
145
|
+
}
|
146
|
+
return false;
|
147
|
+
}
|
148
|
+
return {
|
149
|
+
MethodDefinition(node) {
|
150
|
+
if (node.kind === 'method') ;
|
151
|
+
},
|
152
|
+
FunctionDeclaration(node) {
|
153
|
+
if (node.type === 'FunctionDeclaration' && node.id) {
|
154
|
+
const fnName = node.id.name;
|
155
|
+
const isReactComponent = checkJSXElement(node.body);
|
156
|
+
if (!isReactComponent) {
|
157
|
+
validate({
|
158
|
+
node,
|
159
|
+
fnName
|
160
|
+
});
|
161
|
+
}
|
162
|
+
}
|
163
|
+
},
|
164
|
+
VariableDeclarator(node) {
|
165
|
+
if (node.id && node.init && ['FunctionExpression', 'ArrowFunctionExpression'].includes(node.init.type)) {
|
166
|
+
const fnName = node.id.name;
|
167
|
+
let isReactComponent = checkJSXElement(node.init.body);
|
168
|
+
if (node.id.typeAnnotation && node.id.typeAnnotation.typeAnnotation) {
|
169
|
+
const typeAnnotation = node.id.typeAnnotation.typeAnnotation;
|
170
|
+
if (typeAnnotation.type === 'TSTypeReference' && typeAnnotation.typeName.type === 'Identifier') {
|
171
|
+
const typeName = typeAnnotation.typeName.name;
|
172
|
+
if (['FC', 'React.FC', 'FunctionComponent', 'React.FunctionComponent'].includes(typeName)) {
|
173
|
+
isReactComponent = true;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
}
|
177
|
+
if (!isReactComponent) {
|
178
|
+
validate({
|
179
|
+
node,
|
180
|
+
fnName
|
181
|
+
});
|
182
|
+
}
|
183
|
+
}
|
184
|
+
},
|
185
|
+
Property(node) {
|
186
|
+
if (node.value.type === 'FunctionExpression') ;
|
187
|
+
}
|
188
|
+
};
|
189
|
+
}
|
190
|
+
};
|
191
|
+
|
75
192
|
function getSetting(context, name) {
|
76
193
|
return context.settings["agilebot/".concat(name)];
|
77
194
|
}
|
@@ -207,7 +324,12 @@ var intlIdMissing = {
|
|
207
324
|
category: 'Intl'
|
208
325
|
},
|
209
326
|
fixable: undefined,
|
210
|
-
schema: []
|
327
|
+
schema: [],
|
328
|
+
messages: {
|
329
|
+
missingId: 'Missing id: {{value}}',
|
330
|
+
missingIdPattern: 'Missing id pattern: {{value}}',
|
331
|
+
disallowInvoke: 'Do not invoke intl by {{value}}'
|
332
|
+
}
|
211
333
|
},
|
212
334
|
create: function (context) {
|
213
335
|
const translatedIds = getIntlIds(context);
|
@@ -222,7 +344,10 @@ var intlIdMissing = {
|
|
222
344
|
if (!isLiteralTranslated(node.value)) {
|
223
345
|
context.report({
|
224
346
|
node: node,
|
225
|
-
|
347
|
+
messageId: 'missingId',
|
348
|
+
data: {
|
349
|
+
value: node.value
|
350
|
+
}
|
226
351
|
});
|
227
352
|
}
|
228
353
|
}
|
@@ -232,7 +357,10 @@ var intlIdMissing = {
|
|
232
357
|
if (!isTemplateTranslated(re)) {
|
233
358
|
context.report({
|
234
359
|
node: node,
|
235
|
-
|
360
|
+
messageId: 'missingIdPattern',
|
361
|
+
data: {
|
362
|
+
value: templateLiteralDisplayStr(node)
|
363
|
+
}
|
236
364
|
});
|
237
365
|
}
|
238
366
|
}
|
@@ -248,7 +376,10 @@ var intlIdMissing = {
|
|
248
376
|
}
|
249
377
|
context.report({
|
250
378
|
node: node,
|
251
|
-
|
379
|
+
messageId: 'disallowInvoke',
|
380
|
+
data: {
|
381
|
+
value: node.value.type
|
382
|
+
}
|
252
383
|
});
|
253
384
|
}
|
254
385
|
return {
|
@@ -378,7 +509,10 @@ var intlIdPrefix = {
|
|
378
509
|
items: {
|
379
510
|
type: 'string'
|
380
511
|
}
|
381
|
-
}]
|
512
|
+
}],
|
513
|
+
messages: {
|
514
|
+
invalidIdPrefix: 'Invalid id prefix: {{value}}'
|
515
|
+
}
|
382
516
|
},
|
383
517
|
create: function (context) {
|
384
518
|
if (context.options[0].length === 0) {
|
@@ -389,7 +523,10 @@ var intlIdPrefix = {
|
|
389
523
|
if (!hasPrefix(value)) {
|
390
524
|
context.report({
|
391
525
|
node: node,
|
392
|
-
|
526
|
+
messageId: 'invalidIdPrefix',
|
527
|
+
data: {
|
528
|
+
value
|
529
|
+
}
|
393
530
|
});
|
394
531
|
}
|
395
532
|
}
|
@@ -517,13 +654,16 @@ var intlNoDefault = {
|
|
517
654
|
category: 'Intl'
|
518
655
|
},
|
519
656
|
fixable: undefined,
|
520
|
-
schema: []
|
657
|
+
schema: [],
|
658
|
+
messages: {
|
659
|
+
noDefaultMessage: 'Do not use defaultMessage'
|
660
|
+
}
|
521
661
|
},
|
522
662
|
create: function (context) {
|
523
663
|
function processAttrNode(node) {
|
524
664
|
context.report({
|
525
665
|
node: node,
|
526
|
-
|
666
|
+
messageId: 'noDefaultMessage'
|
527
667
|
});
|
528
668
|
}
|
529
669
|
return {
|
@@ -1959,7 +2099,8 @@ var reactPreferNamedPropertyAccess = utils.ESLintUtils.RuleCreator.withoutDocs({
|
|
1959
2099
|
recommended: 'recommended'
|
1960
2100
|
},
|
1961
2101
|
messages: {
|
1962
|
-
illegalReactPropertyAccess: 'Illegal React property access: {{name}}. Use named import instead.'
|
2102
|
+
illegalReactPropertyAccess: 'Illegal React property access: {{name}}. Use named import instead.',
|
2103
|
+
disallowImportReactEvent: 'Disallow importing React event types to avoid conflicts with global event types.'
|
1963
2104
|
},
|
1964
2105
|
schema: []
|
1965
2106
|
},
|
@@ -1996,6 +2137,19 @@ var reactPreferNamedPropertyAccess = utils.ESLintUtils.RuleCreator.withoutDocs({
|
|
1996
2137
|
yield* updateImportStatement(context, fixer, node.property.name);
|
1997
2138
|
}
|
1998
2139
|
});
|
2140
|
+
},
|
2141
|
+
ImportDeclaration(node) {
|
2142
|
+
if (node.source.value !== 'react' && node.source.value !== 'preact') {
|
2143
|
+
return;
|
2144
|
+
}
|
2145
|
+
node.specifiers.forEach(specifier => {
|
2146
|
+
if (specifier.type === 'ImportSpecifier' && specifier.imported.name && specifier.imported.name.endsWith('Event')) {
|
2147
|
+
context.report({
|
2148
|
+
node: specifier,
|
2149
|
+
messageId: 'disallowImportReactEvent'
|
2150
|
+
});
|
2151
|
+
}
|
2152
|
+
});
|
1999
2153
|
}
|
2000
2154
|
};
|
2001
2155
|
}
|
@@ -2511,6 +2665,7 @@ var tssUnusedClasses = {
|
|
2511
2665
|
var ruleFiles = /*#__PURE__*/Object.freeze({
|
2512
2666
|
__proto__: null,
|
2513
2667
|
rules_enforce_mui_icon_alias: enforceMuiIconAlias,
|
2668
|
+
rules_func_naming: funcNaming,
|
2514
2669
|
rules_import_monorepo: importMonorepo,
|
2515
2670
|
rules_intl_id_missing: intlIdMissing,
|
2516
2671
|
rules_intl_id_naming: intlIdNaming,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@agilebot/eslint-plugin",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.9",
|
4
4
|
"description": "Agilebot's ESLint plugin",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -20,7 +20,7 @@
|
|
20
20
|
"dependencies": {
|
21
21
|
"@typescript-eslint/utils": "~7.9.0",
|
22
22
|
"eslint-plugin-react": "^7.34.1",
|
23
|
-
"@agilebot/eslint-utils": "0.3.
|
23
|
+
"@agilebot/eslint-utils": "0.3.9"
|
24
24
|
},
|
25
25
|
"peerDependencies": {
|
26
26
|
"eslint": "^7.0.0 || ^8.0.0"
|
@@ -32,7 +32,8 @@
|
|
32
32
|
"@types/color-name": "^1.1.4",
|
33
33
|
"@types/estree": "^1.0.5",
|
34
34
|
"color-name": "^2.0.0",
|
35
|
-
"eslint-vitest-rule-tester": "^0.3.2"
|
35
|
+
"eslint-vitest-rule-tester": "^0.3.2",
|
36
|
+
"typescript-eslint": "^7.11.0"
|
36
37
|
},
|
37
38
|
"scripts": {
|
38
39
|
"build": "rollup -c rollup.config.mjs",
|