eslint-plugin-react-debug 2.0.0-next.0 → 2.0.0-next.2
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/dist/index.js +32 -54
- package/package.json +10 -18
- package/dist/index.d.mts +0 -43
- package/dist/index.mjs +0 -319
package/dist/index.js
CHANGED
|
@@ -1,33 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var tsPattern = require('ts-pattern');
|
|
10
|
-
var typescript = require('typescript');
|
|
11
|
-
|
|
12
|
-
function _interopNamespace(e) {
|
|
13
|
-
if (e && e.__esModule) return e;
|
|
14
|
-
var n = Object.create(null);
|
|
15
|
-
if (e) {
|
|
16
|
-
Object.keys(e).forEach(function (k) {
|
|
17
|
-
if (k !== 'default') {
|
|
18
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () { return e[k]; }
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
n.default = e;
|
|
27
|
-
return Object.freeze(n);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var ER2__namespace = /*#__PURE__*/_interopNamespace(ER2);
|
|
1
|
+
import { getDocsUrl, getSettingsFromContext, DEFAULT_ESLINT_REACT_SETTINGS } from '@eslint-react/shared';
|
|
2
|
+
import * as ER2 from '@eslint-react/core';
|
|
3
|
+
import { ESLintUtils, AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
4
|
+
import { flow } from '@eslint-react/eff';
|
|
5
|
+
import { JsxConfig, Reporter } from '@eslint-react/kit';
|
|
6
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/types';
|
|
7
|
+
import { match, P } from 'ts-pattern';
|
|
8
|
+
import { JsxEmit } from 'typescript';
|
|
31
9
|
|
|
32
10
|
var __defProp = Object.defineProperty;
|
|
33
11
|
var __export = (target, all) => {
|
|
@@ -51,13 +29,13 @@ var rules = {
|
|
|
51
29
|
"react-debug/jsx": "warn"
|
|
52
30
|
};
|
|
53
31
|
var settings = {
|
|
54
|
-
"react-x":
|
|
32
|
+
"react-x": DEFAULT_ESLINT_REACT_SETTINGS
|
|
55
33
|
};
|
|
56
34
|
|
|
57
35
|
// package.json
|
|
58
36
|
var name2 = "eslint-plugin-react-debug";
|
|
59
|
-
var version = "2.0.0-next.
|
|
60
|
-
var createRule =
|
|
37
|
+
var version = "2.0.0-next.2";
|
|
38
|
+
var createRule = ESLintUtils.RuleCreator(getDocsUrl("debug"));
|
|
61
39
|
|
|
62
40
|
// src/utils/stringify.ts
|
|
63
41
|
function stringify(value) {
|
|
@@ -86,7 +64,7 @@ var class_component_default = createRule({
|
|
|
86
64
|
defaultOptions: []
|
|
87
65
|
});
|
|
88
66
|
function create(context) {
|
|
89
|
-
const { ctx, listeners } =
|
|
67
|
+
const { ctx, listeners } = ER2.useComponentCollectorLegacy();
|
|
90
68
|
return {
|
|
91
69
|
...listeners,
|
|
92
70
|
"Program:exit"(program) {
|
|
@@ -125,12 +103,12 @@ var function_component_default = createRule({
|
|
|
125
103
|
defaultOptions: []
|
|
126
104
|
});
|
|
127
105
|
function create2(context) {
|
|
128
|
-
const { ctx, listeners } =
|
|
106
|
+
const { ctx, listeners } = ER2.useComponentCollector(
|
|
129
107
|
context,
|
|
130
108
|
{
|
|
131
109
|
collectDisplayName: true,
|
|
132
110
|
collectHookCalls: true,
|
|
133
|
-
hint:
|
|
111
|
+
hint: ER2.DEFAULT_COMPONENT_DETECTION_HINT
|
|
134
112
|
}
|
|
135
113
|
);
|
|
136
114
|
return {
|
|
@@ -145,9 +123,9 @@ function create2(context) {
|
|
|
145
123
|
json: stringify({
|
|
146
124
|
name: name3,
|
|
147
125
|
displayName: displayName == null ? "none" : context.sourceCode.getText(displayName),
|
|
148
|
-
forwardRef: (flag &
|
|
126
|
+
forwardRef: (flag & ER2.ComponentFlag.ForwardRef) > 0n,
|
|
149
127
|
hookCalls: hookCalls.length,
|
|
150
|
-
memo: (flag &
|
|
128
|
+
memo: (flag & ER2.ComponentFlag.Memo) > 0n
|
|
151
129
|
})
|
|
152
130
|
}
|
|
153
131
|
});
|
|
@@ -176,7 +154,7 @@ var hook_default = createRule({
|
|
|
176
154
|
defaultOptions: []
|
|
177
155
|
});
|
|
178
156
|
function create3(context) {
|
|
179
|
-
const { ctx, listeners } =
|
|
157
|
+
const { ctx, listeners } = ER2.useHookCollector();
|
|
180
158
|
return {
|
|
181
159
|
...listeners,
|
|
182
160
|
"Program:exit"(program) {
|
|
@@ -217,20 +195,20 @@ var is_from_react_default = createRule({
|
|
|
217
195
|
defaultOptions: []
|
|
218
196
|
});
|
|
219
197
|
function create4(context) {
|
|
220
|
-
const { importSource = "react" } =
|
|
198
|
+
const { importSource = "react" } = getSettingsFromContext(context);
|
|
221
199
|
function isFromReact(node, initialScope) {
|
|
222
200
|
const name3 = node.name;
|
|
223
201
|
switch (true) {
|
|
224
|
-
case (node.parent.type ===
|
|
225
|
-
return
|
|
226
|
-
case (node.parent.type ===
|
|
227
|
-
return
|
|
202
|
+
case (node.parent.type === AST_NODE_TYPES.MemberExpression && node.parent.property === node && node.parent.object.type === AST_NODE_TYPES.Identifier):
|
|
203
|
+
return ER2.isInitializedFromReact(node.parent.object.name, importSource, initialScope);
|
|
204
|
+
case (node.parent.type === AST_NODE_TYPES.JSXMemberExpression && node.parent.property === node && node.parent.object.type === AST_NODE_TYPES.JSXIdentifier):
|
|
205
|
+
return ER2.isInitializedFromReact(node.parent.object.name, importSource, initialScope);
|
|
228
206
|
default:
|
|
229
|
-
return
|
|
207
|
+
return ER2.isInitializedFromReact(name3, importSource, initialScope);
|
|
230
208
|
}
|
|
231
209
|
}
|
|
232
210
|
function visitorFunction(node) {
|
|
233
|
-
const shouldSkipDuplicate = node.parent.type ===
|
|
211
|
+
const shouldSkipDuplicate = node.parent.type === AST_NODE_TYPES.ImportSpecifier && node.parent.imported === node && node.parent.imported.name === node.parent.local.name;
|
|
234
212
|
if (shouldSkipDuplicate) return;
|
|
235
213
|
const name3 = node.name;
|
|
236
214
|
const initialScope = context.sourceCode.getScope(node);
|
|
@@ -272,8 +250,8 @@ var jsx_default = createRule({
|
|
|
272
250
|
defaultOptions: []
|
|
273
251
|
});
|
|
274
252
|
function create5(context) {
|
|
275
|
-
const jsxConfigFromContext =
|
|
276
|
-
const jsxConfigFromAnnotation =
|
|
253
|
+
const jsxConfigFromContext = JsxConfig.getFromContext(context);
|
|
254
|
+
const jsxConfigFromAnnotation = JsxConfig.getFromAnnotation(context);
|
|
277
255
|
const jsxConfig = {
|
|
278
256
|
...jsxConfigFromContext,
|
|
279
257
|
...jsxConfigFromAnnotation
|
|
@@ -284,19 +262,19 @@ function create5(context) {
|
|
|
284
262
|
node,
|
|
285
263
|
data: {
|
|
286
264
|
json: stringify({
|
|
287
|
-
kind:
|
|
288
|
-
type:
|
|
289
|
-
jsx:
|
|
265
|
+
kind: match(node).with({ type: AST_NODE_TYPES$1.JSXElement }, (n) => ER2.isFragmentElement(context2, n) ? "fragment" : "element").with({ type: AST_NODE_TYPES$1.JSXFragment }, () => "fragment").exhaustive(),
|
|
266
|
+
type: ER2.getElementType(context2, node),
|
|
267
|
+
jsx: match(jsxConfig.jsx).with(JsxEmit.None, () => "none").with(JsxEmit.ReactJSX, () => "react-jsx").with(JsxEmit.ReactJSXDev, () => "react-jsx-dev").with(JsxEmit.React, () => "react").with(JsxEmit.ReactNative, () => "react-native").with(JsxEmit.Preserve, () => "preserve").otherwise(() => "unknown"),
|
|
290
268
|
jsxFactory: jsxConfig.jsxFactory,
|
|
291
269
|
jsxFragmentFactory: jsxConfig.jsxFragmentFactory,
|
|
292
270
|
jsxImportSource: jsxConfig.jsxImportSource,
|
|
293
|
-
jsxRuntime:
|
|
271
|
+
jsxRuntime: match(jsxConfig.jsx).with(P.union(JsxEmit.None, JsxEmit.ReactJSX, JsxEmit.ReactJSXDev), () => "automatic").otherwise(() => "classic")
|
|
294
272
|
})
|
|
295
273
|
}
|
|
296
274
|
});
|
|
297
275
|
}
|
|
298
276
|
return {
|
|
299
|
-
"JSXElement, JSXFragment":
|
|
277
|
+
"JSXElement, JSXFragment": flow(getReportDescriptor(context), Reporter.make(context).send)
|
|
300
278
|
};
|
|
301
279
|
}
|
|
302
280
|
|
|
@@ -338,4 +316,4 @@ var index_default = {
|
|
|
338
316
|
}
|
|
339
317
|
};
|
|
340
318
|
|
|
341
|
-
|
|
319
|
+
export { index_default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-debug",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.2",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for debugging related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -22,22 +22,14 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"author": "Rel1cx<rel1cx@proton.me>",
|
|
24
24
|
"sideEffects": false,
|
|
25
|
+
"type": "module",
|
|
25
26
|
"exports": {
|
|
26
27
|
".": {
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
"default": "./dist/index.mjs"
|
|
30
|
-
},
|
|
31
|
-
"require": {
|
|
32
|
-
"types": "./dist/index.d.ts",
|
|
33
|
-
"default": "./dist/index.js"
|
|
34
|
-
}
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js"
|
|
35
30
|
},
|
|
36
31
|
"./package.json": "./package.json"
|
|
37
32
|
},
|
|
38
|
-
"main": "dist/index.js",
|
|
39
|
-
"module": "dist/index.mjs",
|
|
40
|
-
"types": "./dist/index.d.ts",
|
|
41
33
|
"files": [
|
|
42
34
|
"dist",
|
|
43
35
|
"./package.json"
|
|
@@ -49,12 +41,12 @@
|
|
|
49
41
|
"@typescript-eslint/utils": "^8.30.1",
|
|
50
42
|
"string-ts": "^2.2.1",
|
|
51
43
|
"ts-pattern": "^5.7.0",
|
|
52
|
-
"@eslint-react/
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/
|
|
56
|
-
"@eslint-react/shared": "2.0.0-next.
|
|
57
|
-
"@eslint-react/
|
|
44
|
+
"@eslint-react/core": "2.0.0-next.2",
|
|
45
|
+
"@eslint-react/eff": "2.0.0-next.2",
|
|
46
|
+
"@eslint-react/ast": "2.0.0-next.2",
|
|
47
|
+
"@eslint-react/kit": "2.0.0-next.2",
|
|
48
|
+
"@eslint-react/shared": "2.0.0-next.2",
|
|
49
|
+
"@eslint-react/var": "2.0.0-next.2"
|
|
58
50
|
},
|
|
59
51
|
"devDependencies": {
|
|
60
52
|
"@types/react": "^19.1.2",
|
package/dist/index.d.mts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
2
|
-
import { RulePreset } from '@eslint-react/kit';
|
|
3
|
-
|
|
4
|
-
declare const _default: {
|
|
5
|
-
configs: {
|
|
6
|
-
all: {
|
|
7
|
-
plugins: {
|
|
8
|
-
"react-debug": {
|
|
9
|
-
readonly meta: {
|
|
10
|
-
readonly name: string;
|
|
11
|
-
readonly version: string;
|
|
12
|
-
};
|
|
13
|
-
readonly rules: {
|
|
14
|
-
readonly "class-component": _typescript_eslint_utils_ts_eslint.RuleModule<"classComponent", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
15
|
-
readonly "function-component": _typescript_eslint_utils_ts_eslint.RuleModule<"functionComponent", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
16
|
-
readonly hook: _typescript_eslint_utils_ts_eslint.RuleModule<"hook", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
17
|
-
readonly "is-from-react": _typescript_eslint_utils_ts_eslint.RuleModule<"isFromReact", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
18
|
-
readonly jsx: _typescript_eslint_utils_ts_eslint.RuleModule<"jsx", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
name: string;
|
|
23
|
-
rules: RulePreset;
|
|
24
|
-
};
|
|
25
|
-
"all-legacy": {
|
|
26
|
-
plugins: string[];
|
|
27
|
-
rules: RulePreset;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
meta: {
|
|
31
|
-
readonly name: string;
|
|
32
|
-
readonly version: string;
|
|
33
|
-
};
|
|
34
|
-
rules: {
|
|
35
|
-
readonly "class-component": _typescript_eslint_utils_ts_eslint.RuleModule<"classComponent", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
36
|
-
readonly "function-component": _typescript_eslint_utils_ts_eslint.RuleModule<"functionComponent", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
37
|
-
readonly hook: _typescript_eslint_utils_ts_eslint.RuleModule<"hook", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
38
|
-
readonly "is-from-react": _typescript_eslint_utils_ts_eslint.RuleModule<"isFromReact", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
39
|
-
readonly jsx: _typescript_eslint_utils_ts_eslint.RuleModule<"jsx", [], unknown, _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export { _default as default };
|
package/dist/index.mjs
DELETED
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
import { getDocsUrl, getSettingsFromContext, DEFAULT_ESLINT_REACT_SETTINGS } from '@eslint-react/shared';
|
|
2
|
-
import * as ER2 from '@eslint-react/core';
|
|
3
|
-
import { ESLintUtils, AST_NODE_TYPES } from '@typescript-eslint/utils';
|
|
4
|
-
import { flow } from '@eslint-react/eff';
|
|
5
|
-
import { JsxConfig, Reporter } from '@eslint-react/kit';
|
|
6
|
-
import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from '@typescript-eslint/types';
|
|
7
|
-
import { match, P } from 'ts-pattern';
|
|
8
|
-
import { JsxEmit } from 'typescript';
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __export = (target, all) => {
|
|
12
|
-
for (var name3 in all)
|
|
13
|
-
__defProp(target, name3, { get: all[name3], enumerable: true });
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// src/configs/all.ts
|
|
17
|
-
var all_exports = {};
|
|
18
|
-
__export(all_exports, {
|
|
19
|
-
name: () => name,
|
|
20
|
-
rules: () => rules,
|
|
21
|
-
settings: () => settings
|
|
22
|
-
});
|
|
23
|
-
var name = "react-debug/all";
|
|
24
|
-
var rules = {
|
|
25
|
-
"react-debug/class-component": "warn",
|
|
26
|
-
"react-debug/function-component": "warn",
|
|
27
|
-
"react-debug/hook": "warn",
|
|
28
|
-
"react-debug/is-from-react": "warn",
|
|
29
|
-
"react-debug/jsx": "warn"
|
|
30
|
-
};
|
|
31
|
-
var settings = {
|
|
32
|
-
"react-x": DEFAULT_ESLINT_REACT_SETTINGS
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// package.json
|
|
36
|
-
var name2 = "eslint-plugin-react-debug";
|
|
37
|
-
var version = "2.0.0-next.0";
|
|
38
|
-
var createRule = ESLintUtils.RuleCreator(getDocsUrl("debug"));
|
|
39
|
-
|
|
40
|
-
// src/utils/stringify.ts
|
|
41
|
-
function stringify(value) {
|
|
42
|
-
return JSON.stringify(value, null, 2);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// src/rules/class-component.ts
|
|
46
|
-
var RULE_NAME = "class-component";
|
|
47
|
-
var RULE_FEATURES = [
|
|
48
|
-
"DBG"
|
|
49
|
-
];
|
|
50
|
-
var class_component_default = createRule({
|
|
51
|
-
meta: {
|
|
52
|
-
type: "problem",
|
|
53
|
-
docs: {
|
|
54
|
-
description: "Reports all class components.",
|
|
55
|
-
[Symbol.for("rule_features")]: RULE_FEATURES
|
|
56
|
-
},
|
|
57
|
-
messages: {
|
|
58
|
-
classComponent: "{{json}}"
|
|
59
|
-
},
|
|
60
|
-
schema: []
|
|
61
|
-
},
|
|
62
|
-
name: RULE_NAME,
|
|
63
|
-
create,
|
|
64
|
-
defaultOptions: []
|
|
65
|
-
});
|
|
66
|
-
function create(context) {
|
|
67
|
-
const { ctx, listeners } = ER2.useComponentCollectorLegacy();
|
|
68
|
-
return {
|
|
69
|
-
...listeners,
|
|
70
|
-
"Program:exit"(program) {
|
|
71
|
-
const components = ctx.getAllComponents(program);
|
|
72
|
-
for (const { name: name3 = "anonymous", node: component } of components.values()) {
|
|
73
|
-
context.report({
|
|
74
|
-
messageId: "classComponent",
|
|
75
|
-
node: component,
|
|
76
|
-
data: {
|
|
77
|
-
json: stringify({ name: name3 })
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
var RULE_NAME2 = "function-component";
|
|
85
|
-
var RULE_FEATURES2 = [
|
|
86
|
-
"DBG"
|
|
87
|
-
];
|
|
88
|
-
var function_component_default = createRule({
|
|
89
|
-
meta: {
|
|
90
|
-
type: "problem",
|
|
91
|
-
docs: {
|
|
92
|
-
description: "Reports all function components.",
|
|
93
|
-
[Symbol.for("rule_features")]: RULE_FEATURES2
|
|
94
|
-
},
|
|
95
|
-
messages: {
|
|
96
|
-
functionComponent: "{{json}}"
|
|
97
|
-
// "[function component] name: {{name}}, memo: {{memo}}, forwardRef: {{forwardRef}}, hookCalls: {{hookCalls}}, displayName: {{displayName}}.",
|
|
98
|
-
},
|
|
99
|
-
schema: []
|
|
100
|
-
},
|
|
101
|
-
name: RULE_NAME2,
|
|
102
|
-
create: create2,
|
|
103
|
-
defaultOptions: []
|
|
104
|
-
});
|
|
105
|
-
function create2(context) {
|
|
106
|
-
const { ctx, listeners } = ER2.useComponentCollector(
|
|
107
|
-
context,
|
|
108
|
-
{
|
|
109
|
-
collectDisplayName: true,
|
|
110
|
-
collectHookCalls: true,
|
|
111
|
-
hint: ER2.DEFAULT_COMPONENT_DETECTION_HINT
|
|
112
|
-
}
|
|
113
|
-
);
|
|
114
|
-
return {
|
|
115
|
-
...listeners,
|
|
116
|
-
"Program:exit"(program) {
|
|
117
|
-
const components = ctx.getAllComponents(program);
|
|
118
|
-
for (const { name: name3 = "anonymous", node, displayName, flag, hookCalls } of components.values()) {
|
|
119
|
-
context.report({
|
|
120
|
-
messageId: "functionComponent",
|
|
121
|
-
node,
|
|
122
|
-
data: {
|
|
123
|
-
json: stringify({
|
|
124
|
-
name: name3,
|
|
125
|
-
displayName: displayName == null ? "none" : context.sourceCode.getText(displayName),
|
|
126
|
-
forwardRef: (flag & ER2.ComponentFlag.ForwardRef) > 0n,
|
|
127
|
-
hookCalls: hookCalls.length,
|
|
128
|
-
memo: (flag & ER2.ComponentFlag.Memo) > 0n
|
|
129
|
-
})
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
var RULE_NAME3 = "hook";
|
|
137
|
-
var RULE_FEATURES3 = [
|
|
138
|
-
"DBG"
|
|
139
|
-
];
|
|
140
|
-
var hook_default = createRule({
|
|
141
|
-
meta: {
|
|
142
|
-
type: "problem",
|
|
143
|
-
docs: {
|
|
144
|
-
description: "Reports all React Hooks.",
|
|
145
|
-
[Symbol.for("rule_features")]: RULE_FEATURES3
|
|
146
|
-
},
|
|
147
|
-
messages: {
|
|
148
|
-
hook: "{{json}}"
|
|
149
|
-
},
|
|
150
|
-
schema: []
|
|
151
|
-
},
|
|
152
|
-
name: RULE_NAME3,
|
|
153
|
-
create: create3,
|
|
154
|
-
defaultOptions: []
|
|
155
|
-
});
|
|
156
|
-
function create3(context) {
|
|
157
|
-
const { ctx, listeners } = ER2.useHookCollector();
|
|
158
|
-
return {
|
|
159
|
-
...listeners,
|
|
160
|
-
"Program:exit"(program) {
|
|
161
|
-
const allHooks = ctx.getAllHooks(program);
|
|
162
|
-
for (const { name: name3, node, hookCalls } of allHooks.values()) {
|
|
163
|
-
context.report({
|
|
164
|
-
messageId: "hook",
|
|
165
|
-
node,
|
|
166
|
-
data: {
|
|
167
|
-
json: stringify({
|
|
168
|
-
name: name3,
|
|
169
|
-
hookCalls: hookCalls.length
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
var RULE_NAME4 = "is-from-react";
|
|
178
|
-
var RULE_FEATURES4 = [
|
|
179
|
-
"DBG"
|
|
180
|
-
];
|
|
181
|
-
var is_from_react_default = createRule({
|
|
182
|
-
meta: {
|
|
183
|
-
type: "problem",
|
|
184
|
-
docs: {
|
|
185
|
-
description: "Reports all identifiers that are initialized from React.",
|
|
186
|
-
[Symbol.for("rule_features")]: RULE_FEATURES4
|
|
187
|
-
},
|
|
188
|
-
messages: {
|
|
189
|
-
isFromReact: "{{json}}"
|
|
190
|
-
},
|
|
191
|
-
schema: []
|
|
192
|
-
},
|
|
193
|
-
name: RULE_NAME4,
|
|
194
|
-
create: create4,
|
|
195
|
-
defaultOptions: []
|
|
196
|
-
});
|
|
197
|
-
function create4(context) {
|
|
198
|
-
const { importSource = "react" } = getSettingsFromContext(context);
|
|
199
|
-
function isFromReact(node, initialScope) {
|
|
200
|
-
const name3 = node.name;
|
|
201
|
-
switch (true) {
|
|
202
|
-
case (node.parent.type === AST_NODE_TYPES.MemberExpression && node.parent.property === node && node.parent.object.type === AST_NODE_TYPES.Identifier):
|
|
203
|
-
return ER2.isInitializedFromReact(node.parent.object.name, importSource, initialScope);
|
|
204
|
-
case (node.parent.type === AST_NODE_TYPES.JSXMemberExpression && node.parent.property === node && node.parent.object.type === AST_NODE_TYPES.JSXIdentifier):
|
|
205
|
-
return ER2.isInitializedFromReact(node.parent.object.name, importSource, initialScope);
|
|
206
|
-
default:
|
|
207
|
-
return ER2.isInitializedFromReact(name3, importSource, initialScope);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
function visitorFunction(node) {
|
|
211
|
-
const shouldSkipDuplicate = node.parent.type === AST_NODE_TYPES.ImportSpecifier && node.parent.imported === node && node.parent.imported.name === node.parent.local.name;
|
|
212
|
-
if (shouldSkipDuplicate) return;
|
|
213
|
-
const name3 = node.name;
|
|
214
|
-
const initialScope = context.sourceCode.getScope(node);
|
|
215
|
-
if (!isFromReact(node, initialScope)) return;
|
|
216
|
-
context.report({
|
|
217
|
-
messageId: "isFromReact",
|
|
218
|
-
node,
|
|
219
|
-
data: {
|
|
220
|
-
json: stringify({
|
|
221
|
-
name: name3,
|
|
222
|
-
importSource
|
|
223
|
-
})
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
return {
|
|
228
|
-
Identifier: visitorFunction,
|
|
229
|
-
JSXIdentifier: visitorFunction
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
var RULE_NAME5 = "jsx";
|
|
233
|
-
var RULE_FEATURES5 = [
|
|
234
|
-
"DBG"
|
|
235
|
-
];
|
|
236
|
-
var jsx_default = createRule({
|
|
237
|
-
meta: {
|
|
238
|
-
type: "problem",
|
|
239
|
-
docs: {
|
|
240
|
-
description: "Reports all JSX elements and fragments.",
|
|
241
|
-
[Symbol.for("rule_features")]: RULE_FEATURES5
|
|
242
|
-
},
|
|
243
|
-
messages: {
|
|
244
|
-
jsx: "{{json}}"
|
|
245
|
-
},
|
|
246
|
-
schema: []
|
|
247
|
-
},
|
|
248
|
-
name: RULE_NAME5,
|
|
249
|
-
create: create5,
|
|
250
|
-
defaultOptions: []
|
|
251
|
-
});
|
|
252
|
-
function create5(context) {
|
|
253
|
-
const jsxConfigFromContext = JsxConfig.getFromContext(context);
|
|
254
|
-
const jsxConfigFromAnnotation = JsxConfig.getFromAnnotation(context);
|
|
255
|
-
const jsxConfig = {
|
|
256
|
-
...jsxConfigFromContext,
|
|
257
|
-
...jsxConfigFromAnnotation
|
|
258
|
-
};
|
|
259
|
-
function getReportDescriptor(context2) {
|
|
260
|
-
return (node) => ({
|
|
261
|
-
messageId: "jsx",
|
|
262
|
-
node,
|
|
263
|
-
data: {
|
|
264
|
-
json: stringify({
|
|
265
|
-
kind: match(node).with({ type: AST_NODE_TYPES$1.JSXElement }, (n) => ER2.isFragmentElement(context2, n) ? "fragment" : "element").with({ type: AST_NODE_TYPES$1.JSXFragment }, () => "fragment").exhaustive(),
|
|
266
|
-
type: ER2.getElementType(context2, node),
|
|
267
|
-
jsx: match(jsxConfig.jsx).with(JsxEmit.None, () => "none").with(JsxEmit.ReactJSX, () => "react-jsx").with(JsxEmit.ReactJSXDev, () => "react-jsx-dev").with(JsxEmit.React, () => "react").with(JsxEmit.ReactNative, () => "react-native").with(JsxEmit.Preserve, () => "preserve").otherwise(() => "unknown"),
|
|
268
|
-
jsxFactory: jsxConfig.jsxFactory,
|
|
269
|
-
jsxFragmentFactory: jsxConfig.jsxFragmentFactory,
|
|
270
|
-
jsxImportSource: jsxConfig.jsxImportSource,
|
|
271
|
-
jsxRuntime: match(jsxConfig.jsx).with(P.union(JsxEmit.None, JsxEmit.ReactJSX, JsxEmit.ReactJSXDev), () => "automatic").otherwise(() => "classic")
|
|
272
|
-
})
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
return {
|
|
277
|
-
"JSXElement, JSXFragment": flow(getReportDescriptor(context), Reporter.make(context).send)
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// src/plugin.ts
|
|
282
|
-
var plugin = {
|
|
283
|
-
meta: {
|
|
284
|
-
name: name2,
|
|
285
|
-
version
|
|
286
|
-
},
|
|
287
|
-
rules: {
|
|
288
|
-
["class-component"]: class_component_default,
|
|
289
|
-
["function-component"]: function_component_default,
|
|
290
|
-
["hook"]: hook_default,
|
|
291
|
-
["is-from-react"]: is_from_react_default,
|
|
292
|
-
["jsx"]: jsx_default
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
// src/index.ts
|
|
297
|
-
function makeConfig(config) {
|
|
298
|
-
return {
|
|
299
|
-
...config,
|
|
300
|
-
plugins: {
|
|
301
|
-
"react-debug": plugin
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
function makeLegacyConfig({ rules: rules2 }) {
|
|
306
|
-
return {
|
|
307
|
-
plugins: ["react-debug"],
|
|
308
|
-
rules: rules2
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
var index_default = {
|
|
312
|
-
...plugin,
|
|
313
|
-
configs: {
|
|
314
|
-
["all"]: makeConfig(all_exports),
|
|
315
|
-
["all-legacy"]: makeLegacyConfig(all_exports)
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
export { index_default as default };
|