@haltcase/style 7.0.0-canary.7 → 7.0.0-canary.8
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/eslint/configs/next.js +2 -1
- package/eslint/configs/react.js +67 -45
- package/eslint/configs/typescript.js +20 -0
- package/eslint/constants.js +12 -1
- package/eslint/rules/react-x.js +18 -7
- package/eslint/rules/react.js +7 -1
- package/eslint/rules/typescript/naming-convention.js +13 -3
- package/package.json +1 -1
package/eslint/configs/next.js
CHANGED
|
@@ -4,6 +4,7 @@ import { config } from "typescript-eslint";
|
|
|
4
4
|
import {
|
|
5
5
|
javascriptFiles,
|
|
6
6
|
nextJsApiRoutes,
|
|
7
|
+
nextJsMetadataFiles,
|
|
7
8
|
nextJsPageFiles
|
|
8
9
|
} from "../constants.js";
|
|
9
10
|
import { getEslintBaseConfig } from "./internal/base.js";
|
|
@@ -41,7 +42,7 @@ export const getEslintNextConfigInternal = (options = {}) =>
|
|
|
41
42
|
{
|
|
42
43
|
name: "Next.js page files and API routes",
|
|
43
44
|
|
|
44
|
-
files: [...nextJsPageFiles, ...nextJsApiRoutes],
|
|
45
|
+
files: [...nextJsPageFiles, ...nextJsApiRoutes, ...nextJsMetadataFiles],
|
|
45
46
|
rules: {
|
|
46
47
|
"import-x/no-default-export": "off"
|
|
47
48
|
}
|
package/eslint/configs/react.js
CHANGED
|
@@ -6,6 +6,7 @@ import eslintPluginReactOriginal from "eslint-plugin-react";
|
|
|
6
6
|
import eslintPluginReactHooks from "eslint-plugin-react-hooks";
|
|
7
7
|
import { config } from "typescript-eslint";
|
|
8
8
|
|
|
9
|
+
import { jsxFiles, typescriptJsxFiles } from "../constants.js";
|
|
9
10
|
import { jsxA11yRules } from "../rules/jsx-a11y.js";
|
|
10
11
|
import { reactRules } from "../rules/react.js";
|
|
11
12
|
import { reactXRules } from "../rules/react-x.js";
|
|
@@ -25,63 +26,84 @@ export const getEslintReactConfig = (options) =>
|
|
|
25
26
|
* @type {import("./internal/base.js").HaltcaseStyleCreator}
|
|
26
27
|
*/
|
|
27
28
|
export const getEslintReactConfigInternal = (_options = {}) =>
|
|
28
|
-
config(
|
|
29
|
-
|
|
29
|
+
config(
|
|
30
|
+
{
|
|
31
|
+
name: "@haltcase/react",
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
{
|
|
33
|
-
...eslintPluginReact.configs["recommended-type-checked"],
|
|
34
|
-
name: "@haltcase/react/recommended-type-checked"
|
|
35
|
-
},
|
|
33
|
+
files: jsxFiles,
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
extends: [
|
|
36
|
+
{
|
|
37
|
+
name: "@haltcase/react/jsx-eslint/react",
|
|
38
|
+
plugins: {
|
|
39
|
+
// @ts-expect-error see https://github.com/jsx-eslint/eslint-plugin-react/pull/3840
|
|
40
|
+
react: eslintPluginReactOriginal
|
|
41
|
+
},
|
|
42
|
+
rules: {
|
|
43
|
+
...reactRules
|
|
44
|
+
}
|
|
42
45
|
},
|
|
43
|
-
rules: {
|
|
44
|
-
...reactRules
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
{
|
|
48
|
+
name: "@haltcase/react/stylistic",
|
|
49
|
+
plugins: {
|
|
50
|
+
"@stylistic/jsx": eslintStylisticJsx
|
|
51
|
+
},
|
|
52
|
+
rules: {
|
|
53
|
+
...stylisticJsxRules
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
name: "@haltcase/react/hooks",
|
|
59
|
+
plugins: {
|
|
60
|
+
"react-hooks": eslintPluginReactHooks
|
|
61
|
+
},
|
|
62
|
+
rules: {
|
|
63
|
+
...eslintPluginReactHooks.configs.recommended.rules
|
|
64
|
+
}
|
|
52
65
|
},
|
|
53
|
-
rules: {
|
|
54
|
-
...stylisticJsxRules
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
66
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"react-hooks": eslintPluginReactHooks
|
|
67
|
+
{
|
|
68
|
+
name: "@haltcase/react/jsx-a11y",
|
|
69
|
+
...eslintPluginJsxA11y.flatConfigs.recommended
|
|
62
70
|
},
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
|
|
72
|
+
{
|
|
73
|
+
name: "@haltcase/react/import-x",
|
|
74
|
+
...eslintPluginImportX.flatConfigs.react
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
settings: {
|
|
78
|
+
react: {
|
|
79
|
+
version: "detect"
|
|
65
80
|
}
|
|
66
81
|
},
|
|
67
82
|
|
|
68
|
-
{
|
|
69
|
-
|
|
70
|
-
...eslintPluginJsxA11y.flatConfigs.recommended
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
name: "@haltcase/react/import-x",
|
|
74
|
-
...eslintPluginImportX.flatConfigs.react
|
|
83
|
+
rules: {
|
|
84
|
+
...jsxA11yRules
|
|
75
85
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
{
|
|
89
|
+
...eslintPluginReact.configs.recommended,
|
|
90
|
+
|
|
91
|
+
name: "@haltcase/react/recommended",
|
|
92
|
+
|
|
93
|
+
files: typescriptJsxFiles,
|
|
94
|
+
rules: {
|
|
95
|
+
...reactXRules
|
|
80
96
|
}
|
|
81
97
|
},
|
|
82
98
|
|
|
83
|
-
|
|
84
|
-
...
|
|
85
|
-
|
|
99
|
+
{
|
|
100
|
+
...eslintPluginReact.configs["recommended-type-checked"],
|
|
101
|
+
|
|
102
|
+
name: "@haltcase/react/recommended-type-checked",
|
|
103
|
+
|
|
104
|
+
files: typescriptJsxFiles,
|
|
105
|
+
rules: {
|
|
106
|
+
...reactXRules
|
|
107
|
+
}
|
|
86
108
|
}
|
|
87
|
-
|
|
109
|
+
);
|
|
@@ -81,6 +81,26 @@ export const getEslintTypescriptConfig = (options = {}) => {
|
|
|
81
81
|
isTsx: true
|
|
82
82
|
})
|
|
83
83
|
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
// special accommodations for non-TSX component-like files;
|
|
87
|
+
// specifically, this was added to allow PascaleCase'd declarations
|
|
88
|
+
// of extended components with Mantine, which uses e.g., `Button.extend()`
|
|
89
|
+
// to create a customized instance of a UI component
|
|
90
|
+
name: "@haltcase/internal/TypeScript component files",
|
|
91
|
+
|
|
92
|
+
files: ["**/components/*.ts"],
|
|
93
|
+
languageOptions,
|
|
94
|
+
|
|
95
|
+
plugins: {
|
|
96
|
+
"@typescript-eslint": plugin
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
rules: {
|
|
100
|
+
...getTypescriptNamingConventionRule({
|
|
101
|
+
isComponentLike: true
|
|
102
|
+
})
|
|
103
|
+
}
|
|
84
104
|
}
|
|
85
105
|
);
|
|
86
106
|
};
|
package/eslint/constants.js
CHANGED
|
@@ -4,6 +4,7 @@ export const commonJsOnlyFiles = ["**/*.cjs"];
|
|
|
4
4
|
export const commonJsFiles = ["**/*.{c,}js"];
|
|
5
5
|
export const javascriptFiles = ["**/*.{m,}js{x,}"];
|
|
6
6
|
export const typescriptFiles = ["**/*.{m,}ts{x,}"];
|
|
7
|
+
export const javascriptJsxFiles = ["**/*.{m,}jsx"];
|
|
7
8
|
export const typescriptJsxFiles = ["**/*.{m,}tsx"];
|
|
8
9
|
export const jsxFiles = ["**/*.{c,m,}{js,ts}x"];
|
|
9
10
|
|
|
@@ -11,6 +12,16 @@ export const configFiles = ["**/*.config.{m,}{js,ts}"];
|
|
|
11
12
|
export const scriptFiles = ["**/scripts/*", "**/prisma/*"];
|
|
12
13
|
|
|
13
14
|
export const nextJsPageFiles = ["**/{pages,app}/**/*.{m,}{js,ts}x"];
|
|
14
|
-
export const nextJsApiRoutes = [
|
|
15
|
+
export const nextJsApiRoutes = [
|
|
16
|
+
"**/pages/api/**/*.{m,}{js,ts}",
|
|
17
|
+
"**/app/**/route.{m,}{js,ts}x"
|
|
18
|
+
];
|
|
19
|
+
export const nextJsMetadataFiles = [
|
|
20
|
+
"**/app/{apple-,}icon.{js,ts}x",
|
|
21
|
+
"**/app/manifest.{js,ts}",
|
|
22
|
+
"**/app/robots.{js,ts}",
|
|
23
|
+
"**/app/sitemap.{js,ts}",
|
|
24
|
+
"**/app/{opengraph,twitter}-image.{js,ts}x"
|
|
25
|
+
];
|
|
15
26
|
|
|
16
27
|
export const allSupportedFiles = ["**/*.{c,m,}{js,ts}{x,}"];
|
package/eslint/rules/react-x.js
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
* @import { Linter } from "eslint"
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Rules we've decided to disable from the preset config.
|
|
7
|
+
*
|
|
8
|
+
* @type {Linter.RulesRecord}
|
|
9
|
+
*/
|
|
10
|
+
const disabledRules = {
|
|
11
|
+
/**
|
|
12
|
+
* Enforces that function components props are read-only.
|
|
13
|
+
*
|
|
14
|
+
* We have other checks that already disallow changing function parameters.
|
|
15
|
+
*
|
|
16
|
+
* 🚫 Not fixable - https://eslint-react.xyz/docs/rules/prefer-read-only-props
|
|
17
|
+
*/
|
|
18
|
+
"@eslint-react/prefer-read-only-props": "off"
|
|
19
|
+
};
|
|
20
|
+
|
|
5
21
|
/**
|
|
6
22
|
* Additional rules to enable on top of the preset config from
|
|
7
23
|
* `@eslint-react/eslint-plugin`
|
|
@@ -9,6 +25,8 @@
|
|
|
9
25
|
* @type {Linter.RulesRecord}
|
|
10
26
|
*/
|
|
11
27
|
export const reactXRules = {
|
|
28
|
+
...disabledRules,
|
|
29
|
+
|
|
12
30
|
/**
|
|
13
31
|
* Prevents using useless `fragment` components or `<>` syntax.
|
|
14
32
|
*
|
|
@@ -44,13 +62,6 @@ export const reactXRules = {
|
|
|
44
62
|
*/
|
|
45
63
|
"@eslint-react/naming-convention/component-name": "warn",
|
|
46
64
|
|
|
47
|
-
/**
|
|
48
|
-
* Enforces naming convention for JSX files.
|
|
49
|
-
*
|
|
50
|
-
* 🚫 Not fixable - https://eslint-react.xyz/docs/rules/naming-convention-filename
|
|
51
|
-
*/
|
|
52
|
-
"@eslint-react/naming-convention/filename": "warn",
|
|
53
|
-
|
|
54
65
|
/**
|
|
55
66
|
* Enforces consistent use of the JSX file extension.
|
|
56
67
|
*
|
package/eslint/rules/react.js
CHANGED
|
@@ -14,5 +14,11 @@ export const reactRules = {
|
|
|
14
14
|
*
|
|
15
15
|
* 🔧 Fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/HEAD/docs/rules/function-component-definition.md
|
|
16
16
|
*/
|
|
17
|
-
"react/function-component-definition":
|
|
17
|
+
"react/function-component-definition": [
|
|
18
|
+
"error",
|
|
19
|
+
{
|
|
20
|
+
namedComponents: "arrow-function",
|
|
21
|
+
unnamedComponents: "arrow-function"
|
|
22
|
+
}
|
|
23
|
+
]
|
|
18
24
|
};
|
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @param {object} [options]
|
|
7
|
+
* @param {boolean} [options.isComponentLike = false] - Whether to treat as component-like (e.g., themed components without TSX/JSX).
|
|
7
8
|
* @param {boolean} [options.isTsx = false] - Whether to lint as TSX (JSX).
|
|
8
9
|
* @returns {Linter.RulesRecord}
|
|
9
10
|
*/
|
|
10
|
-
export const getTypescriptNamingConventionRule = ({
|
|
11
|
+
export const getTypescriptNamingConventionRule = ({
|
|
12
|
+
isComponentLike = false,
|
|
13
|
+
isTsx = false
|
|
14
|
+
} = {}) => ({
|
|
11
15
|
/**
|
|
12
16
|
* Require consistent naming conventions.
|
|
13
17
|
*
|
|
@@ -19,7 +23,10 @@ export const getTypescriptNamingConventionRule = ({ isTsx = false } = {}) => ({
|
|
|
19
23
|
"error",
|
|
20
24
|
// enforce that unused variable-likes are prefixed with `_`
|
|
21
25
|
{
|
|
22
|
-
format: [
|
|
26
|
+
format: [
|
|
27
|
+
"camelCase",
|
|
28
|
+
(isComponentLike || isTsx) && "StrictPascalCase"
|
|
29
|
+
].filter(Boolean),
|
|
23
30
|
leadingUnderscore: "require",
|
|
24
31
|
modifiers: ["unused"],
|
|
25
32
|
selector: "variableLike",
|
|
@@ -27,7 +34,10 @@ export const getTypescriptNamingConventionRule = ({ isTsx = false } = {}) => ({
|
|
|
27
34
|
},
|
|
28
35
|
// enforce that everything is camelCase by default
|
|
29
36
|
{
|
|
30
|
-
format: [
|
|
37
|
+
format: [
|
|
38
|
+
"camelCase",
|
|
39
|
+
(isComponentLike || isTsx) && "StrictPascalCase"
|
|
40
|
+
].filter(Boolean),
|
|
31
41
|
leadingUnderscore: "forbid",
|
|
32
42
|
selector: "default",
|
|
33
43
|
trailingUnderscore: "forbid"
|