@prowise/eslint-config-linting-rules 2.1.7 → 2.2.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/front-react.js +5 -14
- package/next.js +5 -13
- package/package.json +1 -1
- package/rules/jsx-pascal-case-rule.js +51 -0
- package/rules/plugin-react-rules.js +1 -1
- package/rules/plugin-jest-rules.js +0 -66
package/front-react.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import globals from "globals";
|
|
2
2
|
import base from "./base.js";
|
|
3
|
+
import jsx from "./rules/jsx-pascal-case-rule.js";
|
|
3
4
|
import react from "./rules/plugin-react-rules.js";
|
|
4
5
|
import typescript from "./rules/plugin-typescript-rules.js";
|
|
5
6
|
import vitest from "./rules/plugin-vitest-rules.js";
|
|
@@ -10,7 +11,7 @@ export default [
|
|
|
10
11
|
react,
|
|
11
12
|
vitest,
|
|
12
13
|
{
|
|
13
|
-
plugins: { "@typescript-eslint": typescript.plugins["@typescript-eslint"] },
|
|
14
|
+
plugins: { "@typescript-eslint": typescript.plugins["@typescript-eslint"], jsx },
|
|
14
15
|
settings: { react: { version: "detect" } },
|
|
15
16
|
languageOptions: {
|
|
16
17
|
globals: {
|
|
@@ -21,22 +22,12 @@ export default [
|
|
|
21
22
|
},
|
|
22
23
|
rules: {
|
|
23
24
|
"style/quote-props": ["error", "as-needed", { keywords: false, unnecessary: true, numbers: false }],
|
|
24
|
-
// override the default typescript rule to allow PascalCase function names for function components in React
|
|
25
25
|
"@typescript-eslint/naming-convention": [
|
|
26
26
|
"error",
|
|
27
|
-
{
|
|
28
|
-
|
|
29
|
-
format: ["camelCase", "PascalCase", "UPPER_CASE"],
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
selector: "function",
|
|
33
|
-
format: ["camelCase", "PascalCase"],
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
selector: "typeLike",
|
|
37
|
-
format: ["PascalCase"],
|
|
38
|
-
},
|
|
27
|
+
{ selector: "variable", format: ["camelCase", "PascalCase", "UPPER_CASE"] },
|
|
28
|
+
{ selector: "typeLike", format: ["PascalCase"] },
|
|
39
29
|
],
|
|
30
|
+
"jsx/jsx-element-pascal-case": "error",
|
|
40
31
|
},
|
|
41
32
|
},
|
|
42
33
|
];
|
package/next.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import globals from "globals";
|
|
2
2
|
import base from "./base.js";
|
|
3
|
+
import jsx from "./rules/jsx-pascal-case-rule.js";
|
|
3
4
|
import next from "./rules/plugin-next-rules.js";
|
|
4
5
|
import react from "./rules/plugin-react-rules.js";
|
|
5
6
|
import typescript from "./rules/plugin-typescript-rules.js";
|
|
@@ -12,6 +13,7 @@ export default [
|
|
|
12
13
|
next,
|
|
13
14
|
vitest,
|
|
14
15
|
{
|
|
16
|
+
plugins: { "@typescript-eslint": typescript.plugins["@typescript-eslint"], jsx },
|
|
15
17
|
settings: { react: { version: "detect" } },
|
|
16
18
|
languageOptions: {
|
|
17
19
|
globals: {
|
|
@@ -23,22 +25,12 @@ export default [
|
|
|
23
25
|
},
|
|
24
26
|
rules: {
|
|
25
27
|
"style/quote-props": ["error", "as-needed", { keywords: false, unnecessary: true, numbers: false }],
|
|
26
|
-
// override the default typescript rule to allow PascalCase function names for function components in React
|
|
27
28
|
"@typescript-eslint/naming-convention": [
|
|
28
29
|
"error",
|
|
29
|
-
{
|
|
30
|
-
|
|
31
|
-
format: ["camelCase", "PascalCase", "UPPER_CASE"],
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
selector: "function",
|
|
35
|
-
format: ["camelCase", "PascalCase"],
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
selector: "typeLike",
|
|
39
|
-
format: ["PascalCase"],
|
|
40
|
-
},
|
|
30
|
+
{ selector: "variable", format: ["camelCase", "PascalCase", "UPPER_CASE"] },
|
|
31
|
+
{ selector: "typeLike", format: ["PascalCase"] },
|
|
41
32
|
],
|
|
33
|
+
"jsx/jsx-element-pascal-case": "error",
|
|
42
34
|
},
|
|
43
35
|
},
|
|
44
36
|
];
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@prowise/eslint-config-linting-rules","version":"2.
|
|
1
|
+
{"name":"@prowise/eslint-config-linting-rules","version":"2.2.0","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"}}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/require-jsdoc */
|
|
2
|
+
const jsxElementRule = {
|
|
3
|
+
meta: {
|
|
4
|
+
type: "stylistic",
|
|
5
|
+
docs: { description: "Enforce PascalCase for any function which returns a JSX element" },
|
|
6
|
+
schema: [],
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
create: (context) => {
|
|
10
|
+
function isJSX(node) {
|
|
11
|
+
return node && node.type === "JSXElement";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function isPascalCase(name) {
|
|
15
|
+
return /^[A-Z][a-zA-Z0-9]*$/.test(name) &&
|
|
16
|
+
// allow exceptions for the following names
|
|
17
|
+
!["GET", "HEAD", "POST", "PUT", "DELETE", "CONNECT", "OPTIONS", "TRACE", "PATCH"].includes(name);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function checkFunction(node) {
|
|
21
|
+
if (!node.id || !node.id.name) return;
|
|
22
|
+
const functionName = node.id.name;
|
|
23
|
+
const returnStatement = node.body.body.find((stmt) => stmt.type === "ReturnStatement");
|
|
24
|
+
|
|
25
|
+
if (!isJSX(returnStatement?.argument) && isPascalCase(functionName)) {
|
|
26
|
+
context.report({ node, message: `Function-name "${functionName}" must be camelCase` });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (isJSX(returnStatement?.argument) && !isPascalCase(functionName)) {
|
|
30
|
+
context.report({ node, message: `JSX element-name "${functionName}" must be PascalCase` });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
FunctionDeclaration: checkFunction,
|
|
36
|
+
ArrowFunctionExpression: (node) => {
|
|
37
|
+
if (node.parent.type === "VariableDeclarator") {
|
|
38
|
+
const functionName = node.parent.id.name;
|
|
39
|
+
if (!isJSX(node.body) && isPascalCase(functionName)) {
|
|
40
|
+
context.report({ node, message: `Function-name "${functionName}" must be camelCase` });
|
|
41
|
+
}
|
|
42
|
+
if (isJSX(node.body) && !isPascalCase(functionName)) {
|
|
43
|
+
context.report({ node, message: `JSX element-name "${functionName}" must be PascalCase` });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default { rules: { "jsx-element-pascal-case": jsxElementRule } };
|
|
@@ -661,7 +661,7 @@ export default {
|
|
|
661
661
|
* Enforce PascalCase for user-defined JSX components
|
|
662
662
|
* https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md.
|
|
663
663
|
*/
|
|
664
|
-
"react/jsx-pascal-case": ["error", { allowAllCaps: true, allowNamespace: true, ignore: [] }],
|
|
664
|
+
// "react/jsx-pascal-case": ["error", { allowAllCaps: true, allowNamespace: true, ignore: [] }],
|
|
665
665
|
|
|
666
666
|
/**
|
|
667
667
|
* Disallow multiple spaces between inline JSX props 🔧
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import jestPlugin from "eslint-plugin-jest";
|
|
2
|
-
import globals from "globals";
|
|
3
|
-
import { commonRules } from "./test-rules.js";
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
plugins: { jest: jestPlugin },
|
|
7
|
-
|
|
8
|
-
languageOptions: {
|
|
9
|
-
globals: {
|
|
10
|
-
process: true,
|
|
11
|
-
...globals.jest,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
rules: {
|
|
16
|
-
...commonRules("jest"),
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Disallow confusing usages of jest.setTimeout
|
|
20
|
-
* https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-confusing-set-timeout.md
|
|
21
|
-
*/
|
|
22
|
-
// "jest/no-confusing-set-timeout": "off",
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Disallow use of deprecated functions ✅ 🔧
|
|
26
|
-
* https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-deprecated-functions.md
|
|
27
|
-
*/
|
|
28
|
-
"jest/no-deprecated-functions": "error",
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Disallow using a callback in asynchronous tests and hooks ✅
|
|
32
|
-
* Jest: https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-done-callback.md
|
|
33
|
-
*/
|
|
34
|
-
"jest/no-done-callback": "warn",
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Disallow using exports in files containing tests ✅
|
|
38
|
-
* https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-export.md
|
|
39
|
-
*/
|
|
40
|
-
"jest/no-export": "error",
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Disallow Jasmine globals ✅ 🔧
|
|
44
|
-
* https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-jasmine-globals.md
|
|
45
|
-
*/
|
|
46
|
-
"jest/no-jasmine-globals": "error",
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Disallow specific jest. methods
|
|
50
|
-
* https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-restricted-jest-methods.md
|
|
51
|
-
*/
|
|
52
|
-
// "jest/no-restricted-jest-methods": "off",
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Disallow using jest.mock() factories without an explicit type parameter
|
|
56
|
-
* https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/no-untyped-mock-factory.md
|
|
57
|
-
*/
|
|
58
|
-
// "jest/no-untyped-mock-factory": "off",
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Require promises that have expectations in their chain to be valid ✅
|
|
62
|
-
* https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/valid-expect-in-promise.md
|
|
63
|
-
*/
|
|
64
|
-
"jest/valid-expect-in-promise": "error",
|
|
65
|
-
},
|
|
66
|
-
};
|