@pob/eslint-plugin 65.4.1 → 65.5.0
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/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [65.5.0](https://github.com/christophehurpeau/eslint-config-pob/compare/v65.4.3...v65.5.0) (2026-06-12)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* add namespace error
|
|
11
|
+
* add test case for namespace import in react-named-import rule
|
|
12
|
+
|
|
6
13
|
## [65.4.1](https://github.com/christophehurpeau/eslint-config-pob/compare/v65.4.0...v65.4.1) (2026-05-01)
|
|
7
14
|
|
|
8
15
|
Note: no notable changes
|
|
@@ -17,21 +17,55 @@ export default {
|
|
|
17
17
|
},
|
|
18
18
|
|
|
19
19
|
create(context) {
|
|
20
|
-
const
|
|
20
|
+
const sourceCode = context.sourceCode;
|
|
21
|
+
|
|
22
|
+
const checkImportSpecifier = (node, messageId) => {
|
|
21
23
|
const importDeclaration = node.parent;
|
|
22
|
-
const importSource =
|
|
24
|
+
const importSource =
|
|
25
|
+
importDeclaration &&
|
|
26
|
+
importDeclaration.source &&
|
|
27
|
+
importDeclaration.source.value &&
|
|
28
|
+
String(importDeclaration.source.value).trim();
|
|
23
29
|
if (importSource !== "react") return;
|
|
24
|
-
context.report({
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
context.report({ node, messageId });
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const isReactDeclaredInScope = (node) => {
|
|
34
|
+
const scope = sourceCode.getScope ? sourceCode.getScope(node) : null;
|
|
35
|
+
return (
|
|
36
|
+
scope &&
|
|
37
|
+
((scope.set && scope.set.get("React")) ||
|
|
38
|
+
(scope.variables && scope.variables.find((v) => v.name === "React")))
|
|
39
|
+
);
|
|
28
40
|
};
|
|
41
|
+
|
|
42
|
+
const checkReactUsage = (node, messageId = "namespace") => {
|
|
43
|
+
if (!isReactDeclaredInScope(node)) {
|
|
44
|
+
context.report({ node, messageId });
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
29
48
|
return {
|
|
30
|
-
ImportNamespaceSpecifier: (node) =>
|
|
31
|
-
|
|
49
|
+
ImportNamespaceSpecifier: (node) =>
|
|
50
|
+
checkImportSpecifier(node, "namespace"),
|
|
51
|
+
ImportDefaultSpecifier: (node) => checkImportSpecifier(node, "default"),
|
|
52
|
+
MemberExpression: (node) => {
|
|
53
|
+
if (
|
|
54
|
+
node.object &&
|
|
55
|
+
node.object.type === "Identifier" &&
|
|
56
|
+
node.object.name === "React"
|
|
57
|
+
) {
|
|
58
|
+
checkReactUsage(node.object, "namespace");
|
|
59
|
+
}
|
|
32
60
|
},
|
|
33
|
-
|
|
34
|
-
|
|
61
|
+
TSQualifiedName: (node) => {
|
|
62
|
+
if (
|
|
63
|
+
node.left &&
|
|
64
|
+
node.left.type === "Identifier" &&
|
|
65
|
+
node.left.name === "React"
|
|
66
|
+
) {
|
|
67
|
+
checkReactUsage(node.left, "namespace");
|
|
68
|
+
}
|
|
35
69
|
},
|
|
36
70
|
};
|
|
37
71
|
},
|
|
@@ -28,6 +28,34 @@ ruleTester.run("react-named-import", rule, {
|
|
|
28
28
|
},
|
|
29
29
|
],
|
|
30
30
|
invalid: [
|
|
31
|
+
{
|
|
32
|
+
code: `
|
|
33
|
+
export const simpleElement: React.ReactNode = <p>paragraph</p>;
|
|
34
|
+
`,
|
|
35
|
+
errors: [
|
|
36
|
+
{
|
|
37
|
+
messageId: "namespace",
|
|
38
|
+
line: 2,
|
|
39
|
+
column: 35,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
code: `
|
|
45
|
+
import { ReactNode } from 'react';
|
|
46
|
+
import * as React from 'react';
|
|
47
|
+
|
|
48
|
+
export const a: ReactNode = <p>ok</p>;
|
|
49
|
+
export const b: React.ReactNode = <p>bad</p>;
|
|
50
|
+
`,
|
|
51
|
+
errors: [
|
|
52
|
+
{
|
|
53
|
+
messageId: "namespace",
|
|
54
|
+
line: 3,
|
|
55
|
+
column: 14,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
31
59
|
{
|
|
32
60
|
code: `
|
|
33
61
|
import React from 'react';
|
|
@@ -37,6 +65,8 @@ ruleTester.run("react-named-import", rule, {
|
|
|
37
65
|
errors: [
|
|
38
66
|
{
|
|
39
67
|
messageId: "default",
|
|
68
|
+
line: 2,
|
|
69
|
+
column: 14,
|
|
40
70
|
},
|
|
41
71
|
],
|
|
42
72
|
},
|
|
@@ -49,6 +79,8 @@ ruleTester.run("react-named-import", rule, {
|
|
|
49
79
|
errors: [
|
|
50
80
|
{
|
|
51
81
|
messageId: "namespace",
|
|
82
|
+
line: 2,
|
|
83
|
+
column: 14,
|
|
52
84
|
},
|
|
53
85
|
],
|
|
54
86
|
},
|
|
@@ -61,6 +93,22 @@ ruleTester.run("react-named-import", rule, {
|
|
|
61
93
|
errors: [
|
|
62
94
|
{
|
|
63
95
|
messageId: "namespace",
|
|
96
|
+
line: 2,
|
|
97
|
+
column: 19,
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
code: `
|
|
103
|
+
import * as R from 'react';
|
|
104
|
+
|
|
105
|
+
export const simpleElement: R.ReactNode = <p>paragraph</p>;
|
|
106
|
+
`,
|
|
107
|
+
errors: [
|
|
108
|
+
{
|
|
109
|
+
messageId: "namespace",
|
|
110
|
+
line: 2,
|
|
111
|
+
column: 14,
|
|
64
112
|
},
|
|
65
113
|
],
|
|
66
114
|
},
|