@agilebot/eslint-plugin 0.3.10 → 0.3.11
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 +207 -131
- package/package.json +4 -4
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,11 +1,11 @@
|
|
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.11
|
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
11
|
var eslintUtils = require('@agilebot/eslint-utils');
|
@@ -72,127 +72,6 @@ var enforceMuiIconAlias = eslintUtils.createESLintRule({
|
|
72
72
|
}
|
73
73
|
});
|
74
74
|
|
75
|
-
var funcNaming = eslintUtils.createESLintRule({
|
76
|
-
meta: {
|
77
|
-
type: 'problem',
|
78
|
-
docs: {
|
79
|
-
description: 'Enforce function naming convention'
|
80
|
-
},
|
81
|
-
schema: [{
|
82
|
-
type: 'object',
|
83
|
-
properties: {
|
84
|
-
format: {
|
85
|
-
type: 'string',
|
86
|
-
"enum": ['camelCase', 'PascalCase']
|
87
|
-
}
|
88
|
-
}
|
89
|
-
}],
|
90
|
-
messages: {
|
91
|
-
invalidFuncNaming: 'Invalid function naming for non-React component, expected {{format}}',
|
92
|
-
invalidReactFCNaming: 'Invalid naming convention for React functional component, expected PascalCase'
|
93
|
-
}
|
94
|
-
},
|
95
|
-
defaultOptions: [],
|
96
|
-
create(context) {
|
97
|
-
if (!context.options[0]) {
|
98
|
-
throw new Error('Missing options');
|
99
|
-
}
|
100
|
-
const format = context.options[0].format;
|
101
|
-
function validate({
|
102
|
-
node,
|
103
|
-
fnName
|
104
|
-
}) {
|
105
|
-
let isPass;
|
106
|
-
switch (format) {
|
107
|
-
case 'camelCase':
|
108
|
-
if (!eslintUtils.isCamelCase(fnName)) {
|
109
|
-
isPass = false;
|
110
|
-
}
|
111
|
-
break;
|
112
|
-
case 'PascalCase':
|
113
|
-
if (!eslintUtils.isPascalCase(fnName)) {
|
114
|
-
isPass = false;
|
115
|
-
}
|
116
|
-
break;
|
117
|
-
}
|
118
|
-
if (isPass === false) {
|
119
|
-
context.report({
|
120
|
-
node: node,
|
121
|
-
messageId: 'invalidFuncNaming',
|
122
|
-
data: {
|
123
|
-
format
|
124
|
-
}
|
125
|
-
});
|
126
|
-
}
|
127
|
-
}
|
128
|
-
function checkJSXElement(node) {
|
129
|
-
if (!node) {
|
130
|
-
return false;
|
131
|
-
}
|
132
|
-
if (node.type === 'JSXElement' || node.type === 'JSXFragment') {
|
133
|
-
return true;
|
134
|
-
}
|
135
|
-
if (node.type === 'BlockStatement') {
|
136
|
-
for (const statement of node.body) {
|
137
|
-
if (statement.type === 'ReturnStatement') {
|
138
|
-
if (checkJSXElement(statement.argument)) {
|
139
|
-
return true;
|
140
|
-
}
|
141
|
-
} else if (checkJSXElement(statement)) {
|
142
|
-
return true;
|
143
|
-
}
|
144
|
-
}
|
145
|
-
}
|
146
|
-
if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression') {
|
147
|
-
return checkJSXElement(node.body);
|
148
|
-
}
|
149
|
-
return false;
|
150
|
-
}
|
151
|
-
return {
|
152
|
-
MethodDefinition(node) {
|
153
|
-
if (node.kind === 'method') ;
|
154
|
-
},
|
155
|
-
FunctionDeclaration(node) {
|
156
|
-
if (node.type === 'FunctionDeclaration' && node.id) {
|
157
|
-
const fnName = node.id.name;
|
158
|
-
const isReactComponent = checkJSXElement(node.body);
|
159
|
-
if (!isReactComponent) {
|
160
|
-
validate({
|
161
|
-
node,
|
162
|
-
fnName
|
163
|
-
});
|
164
|
-
}
|
165
|
-
}
|
166
|
-
},
|
167
|
-
VariableDeclarator(node) {
|
168
|
-
if (node.id && node.init && ['FunctionExpression', 'ArrowFunctionExpression'].includes(node.init.type)) {
|
169
|
-
const fnName = node.id.name;
|
170
|
-
let isReactComponent = checkJSXElement(node.init.body);
|
171
|
-
if (node.id.typeAnnotation && node.id.typeAnnotation.typeAnnotation) {
|
172
|
-
const typeAnnotation = node.id.typeAnnotation.typeAnnotation;
|
173
|
-
if (typeAnnotation.type === 'TSTypeReference' && typeAnnotation.typeName.type === 'Identifier') {
|
174
|
-
const typeName = typeAnnotation.typeName.name;
|
175
|
-
const typeNameLast = typeName.split('.').pop();
|
176
|
-
if (['FC', 'FunctionComponent', 'VFC', 'VoidFunctionComponent'].includes(typeNameLast)) {
|
177
|
-
isReactComponent = true;
|
178
|
-
}
|
179
|
-
}
|
180
|
-
}
|
181
|
-
if (!isReactComponent) {
|
182
|
-
validate({
|
183
|
-
node,
|
184
|
-
fnName
|
185
|
-
});
|
186
|
-
}
|
187
|
-
}
|
188
|
-
},
|
189
|
-
Property(node) {
|
190
|
-
if (node.value.type === 'FunctionExpression') ;
|
191
|
-
}
|
192
|
-
};
|
193
|
-
}
|
194
|
-
});
|
195
|
-
|
196
75
|
function getSetting(context, name) {
|
197
76
|
return context.settings["agilebot/".concat(name)];
|
198
77
|
}
|
@@ -2679,10 +2558,206 @@ var tssUnusedClasses = eslintUtils.createESLintRule({
|
|
2679
2558
|
}
|
2680
2559
|
});
|
2681
2560
|
|
2561
|
+
const reactGlobalFuncs = new Set(['createContext', 'forwardRef', 'lazy', 'memo', 'combineProviders']);
|
2562
|
+
const reactFCTypes = new Set(['FC', 'FunctionComponent', 'VFC', 'VoidFunctionComponent']);
|
2563
|
+
const otherTypes = new Set(['StoryObj', 'StoryFn']);
|
2564
|
+
const defaultExcludes = ['^(__dirname|__filename)$', '(.*)Event$'];
|
2565
|
+
var varNaming = eslintUtils.createESLintRule({
|
2566
|
+
meta: {
|
2567
|
+
type: 'problem',
|
2568
|
+
docs: {
|
2569
|
+
description: 'Enforce variable and function naming convention',
|
2570
|
+
recommended: 'recommended'
|
2571
|
+
},
|
2572
|
+
schema: [{
|
2573
|
+
type: 'object',
|
2574
|
+
properties: {
|
2575
|
+
funcFormat: {
|
2576
|
+
type: 'array',
|
2577
|
+
items: {
|
2578
|
+
"enum": ['camelCase', 'PascalCase', 'UPPER_CASE']
|
2579
|
+
}
|
2580
|
+
},
|
2581
|
+
varFormat: {
|
2582
|
+
type: 'array',
|
2583
|
+
items: {
|
2584
|
+
"enum": ['camelCase', 'PascalCase', 'UPPER_CASE']
|
2585
|
+
}
|
2586
|
+
},
|
2587
|
+
exclude: {
|
2588
|
+
type: 'array',
|
2589
|
+
items: {
|
2590
|
+
type: 'string'
|
2591
|
+
}
|
2592
|
+
}
|
2593
|
+
}
|
2594
|
+
}],
|
2595
|
+
messages: {
|
2596
|
+
invalidFuncNaming: 'Invalid function naming for non-React component, expected {{formats}}',
|
2597
|
+
invalidReactFCNaming: 'Invalid naming convention for React functional component, expected PascalCase',
|
2598
|
+
invalidVarNaming: 'Invalid variable naming, expected {{formats}}'
|
2599
|
+
}
|
2600
|
+
},
|
2601
|
+
defaultOptions: [],
|
2602
|
+
create(context) {
|
2603
|
+
if (!context.options[0]) {
|
2604
|
+
context.options[0] = {};
|
2605
|
+
}
|
2606
|
+
const funcFormat = context.options[0].funcFormat || ['camelCase'];
|
2607
|
+
const varFormat = context.options[0].varFormat || ['camelCase', 'UPPER_CASE'];
|
2608
|
+
let exclude = context.options[0].exclude || [];
|
2609
|
+
exclude = [...defaultExcludes, ...exclude];
|
2610
|
+
function validate(type, {
|
2611
|
+
node,
|
2612
|
+
name
|
2613
|
+
}) {
|
2614
|
+
let isPass = false;
|
2615
|
+
let formats;
|
2616
|
+
let messageId;
|
2617
|
+
switch (type) {
|
2618
|
+
case 'func':
|
2619
|
+
formats = funcFormat;
|
2620
|
+
messageId = 'invalidFuncNaming';
|
2621
|
+
break;
|
2622
|
+
case 'var':
|
2623
|
+
formats = varFormat;
|
2624
|
+
messageId = 'invalidVarNaming';
|
2625
|
+
break;
|
2626
|
+
}
|
2627
|
+
for (const format of formats) {
|
2628
|
+
switch (format) {
|
2629
|
+
case 'camelCase':
|
2630
|
+
if (eslintUtils.isCamelCase(name)) {
|
2631
|
+
isPass = true;
|
2632
|
+
}
|
2633
|
+
break;
|
2634
|
+
case 'PascalCase':
|
2635
|
+
if (eslintUtils.isPascalCase(name)) {
|
2636
|
+
isPass = true;
|
2637
|
+
}
|
2638
|
+
break;
|
2639
|
+
case 'UPPER_CASE':
|
2640
|
+
if (eslintUtils.isUpperCase(name)) {
|
2641
|
+
isPass = true;
|
2642
|
+
}
|
2643
|
+
break;
|
2644
|
+
}
|
2645
|
+
}
|
2646
|
+
if (!isPass) {
|
2647
|
+
context.report({
|
2648
|
+
node: node,
|
2649
|
+
messageId: messageId,
|
2650
|
+
data: {
|
2651
|
+
formats: formats.join(', ')
|
2652
|
+
}
|
2653
|
+
});
|
2654
|
+
}
|
2655
|
+
}
|
2656
|
+
function checkJSXElement(node) {
|
2657
|
+
if (!node) {
|
2658
|
+
return false;
|
2659
|
+
}
|
2660
|
+
if (node.type === 'JSXElement' || node.type === 'JSXFragment') {
|
2661
|
+
return true;
|
2662
|
+
}
|
2663
|
+
if (node.type === 'BlockStatement') {
|
2664
|
+
for (const statement of node.body) {
|
2665
|
+
if (statement.type === 'ReturnStatement') {
|
2666
|
+
if (checkJSXElement(statement.argument)) {
|
2667
|
+
return true;
|
2668
|
+
}
|
2669
|
+
} else if (checkJSXElement(statement)) {
|
2670
|
+
return true;
|
2671
|
+
}
|
2672
|
+
}
|
2673
|
+
}
|
2674
|
+
if (node.type === 'ArrowFunctionExpression' || node.type === 'FunctionExpression') {
|
2675
|
+
return checkJSXElement(node.body);
|
2676
|
+
}
|
2677
|
+
return false;
|
2678
|
+
}
|
2679
|
+
return {
|
2680
|
+
FunctionDeclaration(node) {
|
2681
|
+
if (node.type === 'FunctionDeclaration' && node.id) {
|
2682
|
+
const fnName = node.id.name;
|
2683
|
+
const isReactComponent = checkJSXElement(node.body);
|
2684
|
+
if (!isReactComponent) {
|
2685
|
+
validate('func', {
|
2686
|
+
node,
|
2687
|
+
name: fnName
|
2688
|
+
});
|
2689
|
+
}
|
2690
|
+
}
|
2691
|
+
},
|
2692
|
+
VariableDeclarator(node) {
|
2693
|
+
if (node.id && node.init && ['FunctionExpression', 'ArrowFunctionExpression'].includes(node.init.type)) {
|
2694
|
+
const fnName = node.id.name;
|
2695
|
+
let isReactComponent = checkJSXElement(node.init.body);
|
2696
|
+
if (node.id.typeAnnotation && node.id.typeAnnotation.typeAnnotation) {
|
2697
|
+
const typeAnnotation = node.id.typeAnnotation.typeAnnotation;
|
2698
|
+
if (typeAnnotation.type === 'TSTypeReference' && typeAnnotation.typeName.type === 'Identifier') {
|
2699
|
+
const typeName = typeAnnotation.typeName.name;
|
2700
|
+
const typeNameLast = typeName.split('.').pop();
|
2701
|
+
if (reactFCTypes.has(typeNameLast)) {
|
2702
|
+
isReactComponent = true;
|
2703
|
+
}
|
2704
|
+
}
|
2705
|
+
}
|
2706
|
+
if (!isReactComponent) {
|
2707
|
+
validate('func', {
|
2708
|
+
node,
|
2709
|
+
name: fnName
|
2710
|
+
});
|
2711
|
+
}
|
2712
|
+
} else if (node.id) {
|
2713
|
+
const varName = node.id.name;
|
2714
|
+
for (const excludeRegex of exclude) {
|
2715
|
+
if (new RegExp(excludeRegex).test(varName)) {
|
2716
|
+
return;
|
2717
|
+
}
|
2718
|
+
}
|
2719
|
+
if (node.id.typeAnnotation && node.id.typeAnnotation.typeAnnotation) {
|
2720
|
+
const typeAnnotation = node.id.typeAnnotation.typeAnnotation;
|
2721
|
+
if (typeAnnotation.type === 'TSTypeReference' && typeAnnotation.typeName.type === 'Identifier') {
|
2722
|
+
const typeName = typeAnnotation.typeName.name;
|
2723
|
+
const typeNameLast = typeName.split('.').pop();
|
2724
|
+
if (otherTypes.has(typeNameLast)) {
|
2725
|
+
return;
|
2726
|
+
}
|
2727
|
+
}
|
2728
|
+
}
|
2729
|
+
if (node.id.parent && node.id.parent.init) {
|
2730
|
+
let calleeName;
|
2731
|
+
let shouldCheckReact = false;
|
2732
|
+
if (node.id.parent.init.type === 'CallExpression') {
|
2733
|
+
shouldCheckReact = true;
|
2734
|
+
calleeName = node.id.parent.init.callee.name;
|
2735
|
+
} else if (node.id.parent.init.type === 'TSAsExpression' && node.id.parent.init.expression && node.id.parent.init.expression.callee) {
|
2736
|
+
shouldCheckReact = true;
|
2737
|
+
calleeName = node.id.parent.init.expression.callee.name;
|
2738
|
+
}
|
2739
|
+
if (shouldCheckReact) {
|
2740
|
+
if (!calleeName) {
|
2741
|
+
return;
|
2742
|
+
}
|
2743
|
+
if (reactGlobalFuncs.has(calleeName) || reactGlobalFuncs.has(calleeName.split('.').pop())) {
|
2744
|
+
return;
|
2745
|
+
}
|
2746
|
+
}
|
2747
|
+
}
|
2748
|
+
validate('var', {
|
2749
|
+
node,
|
2750
|
+
name: varName
|
2751
|
+
});
|
2752
|
+
}
|
2753
|
+
}
|
2754
|
+
};
|
2755
|
+
}
|
2756
|
+
});
|
2757
|
+
|
2682
2758
|
var ruleFiles = /*#__PURE__*/Object.freeze({
|
2683
2759
|
__proto__: null,
|
2684
2760
|
rules_enforce_mui_icon_alias: enforceMuiIconAlias,
|
2685
|
-
rules_func_naming: funcNaming,
|
2686
2761
|
rules_import_monorepo: importMonorepo,
|
2687
2762
|
rules_intl_id_missing: intlIdMissing,
|
2688
2763
|
rules_intl_id_naming: intlIdNaming,
|
@@ -2700,7 +2775,8 @@ var ruleFiles = /*#__PURE__*/Object.freeze({
|
|
2700
2775
|
rules_tss_class_naming: tssClassNaming,
|
2701
2776
|
rules_tss_no_color_name: tssNoColorName,
|
2702
2777
|
rules_tss_no_color_value: tssNoColorValue,
|
2703
|
-
rules_tss_unused_classes: tssUnusedClasses
|
2778
|
+
rules_tss_unused_classes: tssUnusedClasses,
|
2779
|
+
rules_var_naming: varNaming
|
2704
2780
|
});
|
2705
2781
|
|
2706
2782
|
const plugin = {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@agilebot/eslint-plugin",
|
3
|
-
"version": "0.3.
|
3
|
+
"version": "0.3.11",
|
4
4
|
"description": "Agilebot's ESLint plugin",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -18,8 +18,8 @@
|
|
18
18
|
"node": "^18.18.0 || >=20.0.0"
|
19
19
|
},
|
20
20
|
"dependencies": {
|
21
|
-
"eslint-plugin-react": "^7.
|
22
|
-
"@agilebot/eslint-utils": "0.3.
|
21
|
+
"eslint-plugin-react": "^7.35.0",
|
22
|
+
"@agilebot/eslint-utils": "0.3.11"
|
23
23
|
},
|
24
24
|
"peerDependencies": {
|
25
25
|
"eslint": "^7.0.0 || ^8.0.0"
|
@@ -31,7 +31,7 @@
|
|
31
31
|
"@types/color-name": "^1.1.4",
|
32
32
|
"@types/estree": "^1.0.5",
|
33
33
|
"color-name": "^2.0.0",
|
34
|
-
"eslint-vitest-rule-tester": "^0.3.
|
34
|
+
"eslint-vitest-rule-tester": "^0.3.3",
|
35
35
|
"typescript-eslint": "^7.16.0"
|
36
36
|
},
|
37
37
|
"scripts": {
|