@prowise/eslint-config-linting-rules 2.2.0 → 2.2.1
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/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@prowise/eslint-config-linting-rules","version":"2.2.
|
|
1
|
+
{"name":"@prowise/eslint-config-linting-rules","version":"2.2.1","description":"Default Prowise linting rules for npm packages.","main":"index.js","type":"module","exports":{"./typescript":"./typescript.js","./backend":"./backend.js","./front-react":"./front-react.js","./front-solid":"./front-solid.js","./next":"./next.js"},"scripts":{"lint":"eslint","inspect":"eslint --inspect-config"},"repository":{"type":"git","url":"git+ssh://git@bitbucket.org/prowise/npm-linting-rules.git"},"author":"Prowise B.V.","license":"UNLICENSED","homepage":"https://bitbucket.org/prowise/npm-linting-rules#readme","dependencies":{"@next/eslint-plugin-next":"^15.1.7","@stylistic/eslint-plugin":"^4.1.0","confusing-browser-globals":"^1.0.11","eslint":"^9.21.0","eslint-import-resolver-typescript":"^3.8.3","eslint-plugin-file-progress":"^3.0.1","eslint-plugin-import-x":"^4.6.1","eslint-plugin-jsdoc":"^50.6.3","eslint-plugin-jsx-a11y":"^6.10.2","eslint-plugin-n":"^17.15.1","eslint-plugin-prefer-arrow-functions":"^3.6.2","eslint-plugin-react":"^7.37.4","eslint-plugin-react-hooks":"^5.1.0","eslint-plugin-solid":"^0.14.5","eslint-plugin-vitest":"^0.5.4","globals":"^16.0.0","typescript-eslint":"^8.25.0"},"devDependencies":{"@eslint/config-inspector":"^1.0.0"}}
|
|
@@ -7,8 +7,27 @@ const jsxElementRule = {
|
|
|
7
7
|
},
|
|
8
8
|
|
|
9
9
|
create: (context) => {
|
|
10
|
-
function
|
|
11
|
-
|
|
10
|
+
function getReturnType(node) {
|
|
11
|
+
if (node.type === "LogicalExpression") return node.right.type;
|
|
12
|
+
if (node.type === "ConditionalExpression") return node.consequent.type;
|
|
13
|
+
|
|
14
|
+
if (node.type === "BlockStatement") {
|
|
15
|
+
const returnStatement = node.body.find((stmt) => stmt.type === "ReturnStatement");
|
|
16
|
+
if (returnStatement) return returnStatement.argument.type === "LogicalExpression" ? returnStatement.argument.right.type : returnStatement.argument.type;
|
|
17
|
+
|
|
18
|
+
const switchStatement = node.body.find((stmt) => stmt.type === "SwitchStatement");
|
|
19
|
+
if (switchStatement) return switchStatement.cases[0].consequent.find((stmt) => stmt.type === "ReturnStatement")?.argument.type;
|
|
20
|
+
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return node.type;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isJSXNode(node) {
|
|
28
|
+
if (!node) return false;
|
|
29
|
+
const type = getReturnType(node);
|
|
30
|
+
return type === "JSXElement" || type === "JSXFragment";
|
|
12
31
|
}
|
|
13
32
|
|
|
14
33
|
function isPascalCase(name) {
|
|
@@ -22,11 +41,11 @@ const jsxElementRule = {
|
|
|
22
41
|
const functionName = node.id.name;
|
|
23
42
|
const returnStatement = node.body.body.find((stmt) => stmt.type === "ReturnStatement");
|
|
24
43
|
|
|
25
|
-
if (!
|
|
44
|
+
if (!isJSXNode(returnStatement?.argument) && isPascalCase(functionName)) {
|
|
26
45
|
context.report({ node, message: `Function-name "${functionName}" must be camelCase` });
|
|
27
46
|
}
|
|
28
47
|
|
|
29
|
-
if (
|
|
48
|
+
if (isJSXNode(returnStatement?.argument) && !isPascalCase(functionName)) {
|
|
30
49
|
context.report({ node, message: `JSX element-name "${functionName}" must be PascalCase` });
|
|
31
50
|
}
|
|
32
51
|
}
|
|
@@ -36,10 +55,10 @@ const jsxElementRule = {
|
|
|
36
55
|
ArrowFunctionExpression: (node) => {
|
|
37
56
|
if (node.parent.type === "VariableDeclarator") {
|
|
38
57
|
const functionName = node.parent.id.name;
|
|
39
|
-
if (!
|
|
58
|
+
if (!isJSXNode(node.body) && isPascalCase(functionName)) {
|
|
40
59
|
context.report({ node, message: `Function-name "${functionName}" must be camelCase` });
|
|
41
60
|
}
|
|
42
|
-
if (
|
|
61
|
+
if (isJSXNode(node.body) && !isPascalCase(functionName)) {
|
|
43
62
|
context.report({ node, message: `JSX element-name "${functionName}" must be PascalCase` });
|
|
44
63
|
}
|
|
45
64
|
}
|