@haltcase/style 6.2.1 → 7.0.0-canary.10
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/browser.js +27 -0
- package/eslint/configs/cjs.js +13 -0
- package/eslint/configs/internal/base.js +178 -0
- package/eslint/configs/internal/commonjs.js +22 -0
- package/eslint/{rules → configs/internal}/es2015.js +17 -16
- package/eslint/configs/internal/simple-import-sort.js +27 -0
- package/eslint/configs/internal/tsdoc.js +20 -0
- package/eslint/{rules → configs/internal}/unicorn.js +118 -126
- package/eslint/configs/next.js +50 -0
- package/eslint/configs/node.js +27 -0
- package/eslint/configs/playwright-test.js +21 -0
- package/eslint/configs/react.js +109 -0
- package/eslint/configs/typescript.js +106 -0
- package/eslint/constants.js +23 -28
- package/eslint/index.js +33 -0
- package/eslint/rules/best-practice.js +250 -245
- package/eslint/rules/imports.js +94 -0
- package/eslint/rules/jsx-a11y.js +11 -10
- package/eslint/rules/playwright-test.js +25 -26
- package/eslint/rules/possible-errors.js +38 -45
- package/eslint/rules/react-x.js +78 -0
- package/eslint/rules/react.js +20 -113
- package/eslint/rules/stylistic-jsx.js +17 -0
- package/eslint/rules/stylistic.js +83 -84
- package/eslint/rules/typescript/extension.js +68 -39
- package/eslint/rules/typescript/import.js +16 -15
- package/eslint/rules/typescript/index.js +110 -121
- package/eslint/rules/typescript/naming-convention.js +121 -0
- package/eslint/rules/variables.js +34 -34
- package/eslint/withFiles.js +15 -0
- package/package.json +53 -59
- package/prettier/index.js +4 -11
- package/readme.md +183 -98
- package/stylelint/_base.js +2 -4
- package/stylelint/index.js +6 -7
- package/stylelint/modules.js +7 -8
- package/stylelint/standard.js +2 -5
- package/typescript/tsconfig.base.json +2 -1
- package/typescript/tsconfig.bundler.json +7 -3
- package/typescript/tsconfig.next.json +14 -6
- package/typescript/tsconfig.node.json +1 -1
- package/typescript/tsconfig.node18.json +4 -7
- package/typescript/tsconfig.node20.json +4 -7
- package/typescript/tsconfig.node22.json +10 -0
- package/typescript/tsconfig.web.json +1 -1
- package/eslint/_base.js +0 -82
- package/eslint/astro.js +0 -40
- package/eslint/browser.js +0 -8
- package/eslint/cjs.js +0 -12
- package/eslint/jest.js +0 -28
- package/eslint/next.js +0 -38
- package/eslint/node.js +0 -8
- package/eslint/playwright-test.js +0 -8
- package/eslint/react.js +0 -18
- package/eslint/rules/import.js +0 -92
- package/eslint/rules/jest.js +0 -28
- package/eslint/rules/simple-import-sort.js +0 -23
- package/eslint/rules/tsdoc.js +0 -17
- package/eslint/rules/typescript/strict.js +0 -18
- package/eslint/typescript.js +0 -26
- package/eslint/utils/require-package.js +0 -44
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haltcase/style",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0-canary.10",
|
|
4
4
|
"description": "haltcase's web ecosystem style guide & configurations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -17,18 +17,11 @@
|
|
|
17
17
|
},
|
|
18
18
|
"license": "MPL-2.0",
|
|
19
19
|
"author": "Bo Lingen <bo@haltcase.dev> (https://haltcase.dev)",
|
|
20
|
+
"type": "module",
|
|
20
21
|
"exports": {
|
|
22
|
+
"./eslint": "./eslint/index.js",
|
|
21
23
|
"./eslint/rules/*": "./eslint/rules/*.js",
|
|
22
24
|
"./eslint/rules/*.js": "./eslint/rules/*.js",
|
|
23
|
-
"./eslint/astro": "./eslint/astro.js",
|
|
24
|
-
"./eslint/browser": "./eslint/browser.js",
|
|
25
|
-
"./eslint/cjs": "./eslint/cjs.js",
|
|
26
|
-
"./eslint/jest": "./eslint/jest.js",
|
|
27
|
-
"./eslint/next": "./eslint/next.js",
|
|
28
|
-
"./eslint/node": "./eslint/node.js",
|
|
29
|
-
"./eslint/playwright-test": "./eslint/playwright-test.js",
|
|
30
|
-
"./eslint/react": "./eslint/react.js",
|
|
31
|
-
"./eslint/typescript": "./eslint/typescript.js",
|
|
32
25
|
"./prettier": "./prettier/index.js",
|
|
33
26
|
"./stylelint": "./stylelint/index.js",
|
|
34
27
|
"./stylelint/modules": "./stylelint/modules.js",
|
|
@@ -39,6 +32,7 @@
|
|
|
39
32
|
"./typescript/node": "./typescript/tsconfig.node.json",
|
|
40
33
|
"./typescript/node18": "./typescript/tsconfig.node18.json",
|
|
41
34
|
"./typescript/node20": "./typescript/tsconfig.node20.json",
|
|
35
|
+
"./typescript/node22": "./typescript/tsconfig.node22.json",
|
|
42
36
|
"./typescript/web": "./typescript/tsconfig.web.json"
|
|
43
37
|
},
|
|
44
38
|
"files": [
|
|
@@ -46,13 +40,12 @@
|
|
|
46
40
|
"prettier",
|
|
47
41
|
"stylelint",
|
|
48
42
|
"typescript",
|
|
49
|
-
"astro",
|
|
50
43
|
"next"
|
|
51
44
|
],
|
|
52
45
|
"scripts": {
|
|
53
46
|
"eslint-check": "eslint --max-warnings=0 .",
|
|
54
47
|
"format": "eslint --fix . && prettier --write .",
|
|
55
|
-
"prepare": "husky
|
|
48
|
+
"prepare": "husky",
|
|
56
49
|
"prettier-check": "prettier --check .",
|
|
57
50
|
"semantic-release": "semantic-release",
|
|
58
51
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -60,72 +53,73 @@
|
|
|
60
53
|
"lint-staged": {
|
|
61
54
|
"*.{js,jsx,ts,tsx,css,yml,yaml}": "pnpm prettier --write"
|
|
62
55
|
},
|
|
63
|
-
"prettier": "./prettier",
|
|
56
|
+
"prettier": "./prettier/index.js",
|
|
64
57
|
"stylelint": {
|
|
65
58
|
"extends": "./stylelint/index.js"
|
|
66
59
|
},
|
|
67
60
|
"dependencies": {
|
|
68
|
-
"@babel/core": "^7.
|
|
69
|
-
"@babel/eslint-parser": "^7.
|
|
70
|
-
"@
|
|
71
|
-
"@
|
|
72
|
-
"@
|
|
73
|
-
"eslint-
|
|
61
|
+
"@babel/core": "^7.26.0",
|
|
62
|
+
"@babel/eslint-parser": "^7.25.9",
|
|
63
|
+
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.1",
|
|
64
|
+
"@eslint-react/eslint-plugin": "^1.17.1",
|
|
65
|
+
"@next/eslint-plugin-next": "^15.0.3",
|
|
66
|
+
"@stylistic/eslint-plugin-jsx": "^2.11.0",
|
|
67
|
+
"eslint-config-prettier": "^9.1.0",
|
|
74
68
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
75
|
-
"eslint-import-resolver-typescript": "^3.6.
|
|
76
|
-
"eslint-plugin-
|
|
77
|
-
"eslint-plugin-
|
|
78
|
-
"eslint-plugin-
|
|
79
|
-
"eslint-plugin-
|
|
80
|
-
"eslint-plugin-
|
|
81
|
-
"eslint-plugin-
|
|
82
|
-
"eslint-plugin-
|
|
83
|
-
"eslint-plugin-
|
|
84
|
-
"eslint-plugin-
|
|
85
|
-
"eslint-plugin-
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"prettier-plugin-
|
|
89
|
-
"
|
|
90
|
-
"stylelint-config-clean-order": "^5.4.1",
|
|
69
|
+
"eslint-import-resolver-typescript": "^3.6.3",
|
|
70
|
+
"eslint-plugin-import-x": "^4.4.3",
|
|
71
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
72
|
+
"eslint-plugin-playwright": "^2.1.0",
|
|
73
|
+
"eslint-plugin-react": "^7.37.2",
|
|
74
|
+
"eslint-plugin-react-hooks": "^5.0.0",
|
|
75
|
+
"eslint-plugin-regexp": "^2.7.0",
|
|
76
|
+
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
77
|
+
"eslint-plugin-testing-library": "^6.5.0",
|
|
78
|
+
"eslint-plugin-tsdoc": "^0.4.0",
|
|
79
|
+
"eslint-plugin-unicorn": "^56.0.1",
|
|
80
|
+
"postcss-html": "^1.7.0",
|
|
81
|
+
"prettier-plugin-packagejson": "^2.5.6",
|
|
82
|
+
"prettier-plugin-tailwindcss": "^0.6.9",
|
|
83
|
+
"stylelint-config-clean-order": "^6.1.0",
|
|
91
84
|
"stylelint-config-html": "^1.1.0",
|
|
92
|
-
"stylelint-config-standard": "^36.0.
|
|
93
|
-
"stylelint-define-config": "^1.
|
|
85
|
+
"stylelint-config-standard": "^36.0.1",
|
|
86
|
+
"stylelint-define-config": "^1.7.0",
|
|
87
|
+
"typescript-eslint": "^8.16.0"
|
|
94
88
|
},
|
|
95
89
|
"devDependencies": {
|
|
96
|
-
"@actions/core": "^1.
|
|
90
|
+
"@actions/core": "^1.11.1",
|
|
97
91
|
"@actions/exec": "^1.1.1",
|
|
98
|
-
"@actions/github": "^
|
|
99
|
-
"@commitlint/cli": "^
|
|
100
|
-
"@commitlint/config-conventional": "^
|
|
101
|
-
"@
|
|
92
|
+
"@actions/github": "^6.0.0",
|
|
93
|
+
"@commitlint/cli": "^19.6.0",
|
|
94
|
+
"@commitlint/config-conventional": "^19.6.0",
|
|
95
|
+
"@eslint/eslintrc": "^3.2.0",
|
|
96
|
+
"@eslint/js": "^9.15.0",
|
|
97
|
+
"@octokit/types": "^13.6.2",
|
|
102
98
|
"@semantic-release/git": "^10.0.1",
|
|
103
|
-
"@types/
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"
|
|
107
|
-
"
|
|
108
|
-
"
|
|
109
|
-
"
|
|
110
|
-
"
|
|
99
|
+
"@types/eslint-config-prettier": "^6.11.3",
|
|
100
|
+
"@types/eslint__js": "^8.42.3",
|
|
101
|
+
"@types/node": "22",
|
|
102
|
+
"@typescript-eslint/types": "^8.16.0",
|
|
103
|
+
"eslint": "^9.15.0",
|
|
104
|
+
"eslint-define-config": "^2.1.0",
|
|
105
|
+
"globals": "^15.12.0",
|
|
106
|
+
"husky": "^9.1.7",
|
|
107
|
+
"lint-staged": "^15.2.10",
|
|
108
|
+
"prettier": "^3.4.1",
|
|
109
|
+
"semantic-release": "^24.2.0",
|
|
110
|
+
"stylelint": "^16.10.0",
|
|
111
|
+
"typescript": "^5.7.2"
|
|
111
112
|
},
|
|
112
113
|
"peerDependencies": {
|
|
113
|
-
"
|
|
114
|
-
"eslint": ">=8.40.0 <9",
|
|
114
|
+
"eslint": ">=9",
|
|
115
115
|
"prettier": ">=3.0.0 <4",
|
|
116
116
|
"stylelint": ">=16.3.1 <17",
|
|
117
117
|
"typescript": ">=5.0.0 <6"
|
|
118
118
|
},
|
|
119
119
|
"peerDependenciesMeta": {
|
|
120
|
-
"@next/eslint-plugin-next": {
|
|
121
|
-
"optional": true
|
|
122
|
-
},
|
|
123
120
|
"eslint": {
|
|
124
121
|
"optional": true
|
|
125
122
|
},
|
|
126
|
-
"eslint-plugin-astro": {
|
|
127
|
-
"optional": true
|
|
128
|
-
},
|
|
129
123
|
"prettier": {
|
|
130
124
|
"optional": true
|
|
131
125
|
},
|
|
@@ -136,7 +130,7 @@
|
|
|
136
130
|
"optional": true
|
|
137
131
|
}
|
|
138
132
|
},
|
|
139
|
-
"packageManager": "pnpm@
|
|
133
|
+
"packageManager": "pnpm@9.10.0+sha256.355a8ab8dbb6ad41befbef39bc4fd6b5df85e12761d2724bd01f13e878de4b13",
|
|
140
134
|
"engines": {
|
|
141
135
|
"node": ">=20"
|
|
142
136
|
},
|
package/prettier/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable import-x/no-default-export */
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Some of Prettier's defaults can be overridden by an EditorConfig file. We
|
|
@@ -13,17 +13,10 @@ const overridableDefaults = {
|
|
|
13
13
|
useTabs: true
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
export default {
|
|
17
17
|
...overridableDefaults,
|
|
18
18
|
singleQuote: false,
|
|
19
19
|
trailingComma: "none",
|
|
20
|
-
plugins: ["prettier-plugin-
|
|
21
|
-
|
|
22
|
-
{
|
|
23
|
-
files: "*.astro",
|
|
24
|
-
options: {
|
|
25
|
-
parser: "astro"
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
]
|
|
20
|
+
plugins: ["prettier-plugin-packagejson", "prettier-plugin-tailwindcss"],
|
|
21
|
+
tailwindAttributes: ["classNames", "clsx", "cx", "twMerge"]
|
|
29
22
|
};
|
package/readme.md
CHANGED
|
@@ -7,26 +7,27 @@
|
|
|
7
7
|
- [TypeScript](#typescript)
|
|
8
8
|
- [Stylelint](#stylelint)
|
|
9
9
|
|
|
10
|
-
> This package originated from [Vercel's style guide](https://github.com/vercel/style-guide)
|
|
10
|
+
> This package originated from [Vercel's style guide](https://github.com/vercel/style-guide),
|
|
11
|
+
> but has since diverged in both architecture and rules.
|
|
11
12
|
|
|
12
13
|
## installation
|
|
13
14
|
|
|
14
15
|
Install `@haltcase/style` with your preferred package manager:
|
|
15
16
|
|
|
16
17
|
```sh
|
|
18
|
+
# pnpm
|
|
19
|
+
pnpm add --save-dev @haltcase/style
|
|
20
|
+
|
|
17
21
|
# npm
|
|
18
22
|
npm i --save-dev @haltcase/style
|
|
19
23
|
|
|
20
|
-
# pnpm
|
|
21
|
-
pnpm i --save-dev @haltcase/style
|
|
22
|
-
|
|
23
24
|
# yarn
|
|
24
25
|
yarn add --dev @haltcase/style
|
|
25
26
|
```
|
|
26
27
|
|
|
27
28
|
> [!NOTE]
|
|
28
29
|
> Some scenarios require additional peer dependencies.
|
|
29
|
-
> See the [Prettier](#prettier)
|
|
30
|
+
> See the [Prettier](#prettier), [ESLint](#eslint), and [Stylelint](#stylelint) sections.
|
|
30
31
|
|
|
31
32
|
## usage
|
|
32
33
|
|
|
@@ -54,73 +55,158 @@ Add the following in `package.json`:
|
|
|
54
55
|
>
|
|
55
56
|
> See: https://eslint.org/docs/user-guide/getting-started#installation-and-usage
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
> [!IMPORTANT]
|
|
59
|
+
> This config requires ESLint 9+ and the use of
|
|
60
|
+
> [flat config](https://eslint.org/docs/latest/extend/plugin-migration-flat-config).
|
|
58
61
|
|
|
59
|
-
|
|
62
|
+
At its simplest, your config might look like this for a general purpose
|
|
63
|
+
project:
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
```js
|
|
66
|
+
// eslint.config.js
|
|
67
|
+
import { getEslintConfig } from "@haltcase/style/eslint";
|
|
63
68
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
69
|
+
export default getEslintConfig();
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
TypeScript support is enabled by default by applying TypeScript-specific
|
|
73
|
+
configurations to files with TypeScript file extensions
|
|
74
|
+
(`ts`, `tsx`, `mts`, and `mtsx`). You may need to apply your own project-specific
|
|
75
|
+
configurations — see [Configuring ESLint for TypeScript](#configuring-eslint-for-typescript)
|
|
76
|
+
for details on how to do so.
|
|
77
|
+
|
|
78
|
+
#### ESLint customization
|
|
79
|
+
|
|
80
|
+
You can enable more rules for your project with configuration options:
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
// eslint.config.js
|
|
84
|
+
import { getEslintConfig } from "@haltcase/style/eslint";
|
|
68
85
|
|
|
69
|
-
|
|
86
|
+
export default getEslintConfig({
|
|
87
|
+
// for browser environments
|
|
88
|
+
browser: true,
|
|
70
89
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
- `@haltcase/style/eslint/jest`
|
|
74
|
-
- `@haltcase/style/eslint/next` (requires `@next/eslint-plugin-next` to be installed at the same version as `next`)
|
|
75
|
-
- `@haltcase/style/eslint/playwright-test`
|
|
76
|
-
- `@haltcase/style/eslint/react`
|
|
77
|
-
- `@haltcase/style/eslint/typescript` (requires `typescript` to be installed and [additional configuration](#configuring-eslint-for-typescript))
|
|
90
|
+
// treat *.js files as CommonJS instead of ES Modules
|
|
91
|
+
commonjs: true,
|
|
78
92
|
|
|
79
|
-
|
|
93
|
+
// for Next.js projects (implies `react`)
|
|
94
|
+
nextjs: true,
|
|
80
95
|
|
|
81
|
-
|
|
82
|
-
|
|
96
|
+
// for Node.js projects
|
|
97
|
+
node: true,
|
|
98
|
+
|
|
99
|
+
// for React
|
|
100
|
+
react: true
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
And, of course, you may include configs as any part of a larger one:
|
|
83
105
|
|
|
84
106
|
```js
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
107
|
+
// eslint.config.js
|
|
108
|
+
import { getEslintConfig } from "@haltcase/style/eslint";
|
|
109
|
+
|
|
110
|
+
export default [
|
|
111
|
+
...getEslintConfig({
|
|
112
|
+
nextjs: true
|
|
113
|
+
}),
|
|
114
|
+
|
|
115
|
+
{
|
|
116
|
+
name: "Customizations",
|
|
117
|
+
files: ["src/lib/**"],
|
|
118
|
+
rules: {
|
|
119
|
+
"no-unused-vars": "warn"
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
];
|
|
92
123
|
```
|
|
93
124
|
|
|
125
|
+
You can be more granular with your customizations by using the modular configs
|
|
126
|
+
also exported from `@haltcase/style/eslint`:
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
// eslint.config.js
|
|
130
|
+
import {
|
|
131
|
+
getEslintBaseConfig,
|
|
132
|
+
getEslintBrowserConfig,
|
|
133
|
+
getEslintNodeConfig,
|
|
134
|
+
getEslintReactConfig,
|
|
135
|
+
withFiles
|
|
136
|
+
} from "@haltcase/style/eslint";
|
|
137
|
+
|
|
138
|
+
export default [
|
|
139
|
+
// use the base config for everything by default
|
|
140
|
+
...getEslintBaseConfig(),
|
|
141
|
+
|
|
142
|
+
// apply browser rules to some files
|
|
143
|
+
...getEslintBrowserConfig().map((config) => ({
|
|
144
|
+
...config,
|
|
145
|
+
files: ["src/client-only/**/*.js"]
|
|
146
|
+
})),
|
|
147
|
+
|
|
148
|
+
// apply React rules to some files
|
|
149
|
+
// (`withFiles` is equivalent to the above `map`)
|
|
150
|
+
...withFiles(getEslintReactConfig(), ["src/frontend/**/*.{ts,js,tsx,jsx}"]),
|
|
151
|
+
|
|
152
|
+
...withFiles(getEslintNodeConfig(), ["src/backend/**/*.{ts,js}"]),
|
|
153
|
+
|
|
154
|
+
{
|
|
155
|
+
name: "Customizations",
|
|
156
|
+
files: ["src/lib/**"],
|
|
157
|
+
rules: {
|
|
158
|
+
"no-unused-vars": "warn"
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
];
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
> [!TIP]
|
|
165
|
+
> See the ESLint documentation for more details on using configs:
|
|
166
|
+
> https://eslint.org/docs/latest/use/configure/combine-configs
|
|
167
|
+
|
|
94
168
|
#### Configuring ESLint for TypeScript
|
|
95
169
|
|
|
96
170
|
Some of the rules enabled in the TypeScript config require additional type
|
|
97
|
-
information
|
|
98
|
-
|
|
99
|
-
documentation.
|
|
171
|
+
information. By default, this config will configure `parserOptions` with
|
|
172
|
+
[`project: true`](https://typescript-eslint.io/packages/parser/#project).
|
|
100
173
|
|
|
101
|
-
|
|
174
|
+
You can customize this behavior with the `typescriptProject` option:
|
|
102
175
|
|
|
103
176
|
```js
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
177
|
+
import { getEslintConfig } from "@haltcase/style/eslint";
|
|
178
|
+
|
|
179
|
+
export default [
|
|
180
|
+
...getEslintConfig({
|
|
181
|
+
typescriptProject: [
|
|
182
|
+
"./packages/**/tsconfig.json",
|
|
183
|
+
"./separate-package/tsconfig.json"
|
|
184
|
+
]
|
|
185
|
+
})
|
|
186
|
+
];
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
If you need to further customize the TypeScript behavior, use a separate config
|
|
190
|
+
with your own options, for example:
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
import { getEslintConfig } from "@haltcase/style/eslint";
|
|
194
|
+
|
|
195
|
+
export default [
|
|
196
|
+
...getEslintConfig(),
|
|
197
|
+
|
|
198
|
+
{
|
|
199
|
+
files: ["*.{c,m,}ts{x,}"],
|
|
200
|
+
parserOptions: {
|
|
201
|
+
project: true,
|
|
202
|
+
tsConfigRootDir: "/custom/config/directory"
|
|
119
203
|
}
|
|
120
204
|
}
|
|
121
|
-
|
|
205
|
+
];
|
|
122
206
|
```
|
|
123
207
|
|
|
208
|
+
For more information, see: https://typescript-eslint.io/linting/typed-linting/
|
|
209
|
+
|
|
124
210
|
#### Configuring custom components for `jsx-a11y`
|
|
125
211
|
|
|
126
212
|
It's common practice for React apps to have shared components like `Button`
|
|
@@ -130,63 +216,51 @@ via the `components` setting.
|
|
|
130
216
|
The below list is not exhaustive.
|
|
131
217
|
|
|
132
218
|
```js
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
219
|
+
import { getEslintConfig } from "@haltcase/style/eslint";
|
|
220
|
+
|
|
221
|
+
export default [
|
|
222
|
+
getEslintConfig({
|
|
223
|
+
react: true
|
|
224
|
+
}),
|
|
225
|
+
|
|
226
|
+
{
|
|
227
|
+
settings: {
|
|
228
|
+
"jsx-a11y": {
|
|
229
|
+
components: {
|
|
230
|
+
Article: "article",
|
|
231
|
+
Button: "button",
|
|
232
|
+
Image: "img",
|
|
233
|
+
Input: "input",
|
|
234
|
+
Link: "a",
|
|
235
|
+
Video: "video"
|
|
236
|
+
}
|
|
145
237
|
}
|
|
146
238
|
}
|
|
147
239
|
}
|
|
148
|
-
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
#### Scoped configuration with `overrides`
|
|
152
|
-
|
|
153
|
-
ESLint configs can be scoped to include/exclude specific paths. This ensures
|
|
154
|
-
that rules don't "leak" into places where those rules don't apply.
|
|
155
|
-
|
|
156
|
-
In this example, Jest rules are only being applied to files matching Jest's
|
|
157
|
-
default test match pattern.
|
|
158
|
-
|
|
159
|
-
```js
|
|
160
|
-
module.exports = {
|
|
161
|
-
extends: [require.resolve("@haltcase/style/eslint/node")],
|
|
162
|
-
overrides: [
|
|
163
|
-
{
|
|
164
|
-
files: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"],
|
|
165
|
-
extends: [require.resolve("@haltcase/style/eslint/jest")]
|
|
166
|
-
}
|
|
167
|
-
]
|
|
168
|
-
};
|
|
240
|
+
];
|
|
169
241
|
```
|
|
170
242
|
|
|
171
243
|
##### A note on file extensions
|
|
172
244
|
|
|
173
|
-
By default, all TypeScript rules are scoped to files
|
|
174
|
-
|
|
245
|
+
By default, all TypeScript rules are scoped to files with extensions ending in
|
|
246
|
+
`ts` or `tsx`.
|
|
175
247
|
|
|
176
|
-
|
|
177
|
-
|
|
248
|
+
If you need to override configuration for TypeScript files, make sure to
|
|
249
|
+
specify the `files` property or ESLint will
|
|
250
|
+
[only target `*.js` files](https://eslint.org/docs/latest/use/configure/configuration-files#specifying-files-and-ignores).
|
|
178
251
|
|
|
179
252
|
```js
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
253
|
+
export default [
|
|
254
|
+
...getEslintConfig(),
|
|
255
|
+
|
|
256
|
+
{
|
|
257
|
+
// apply this config to js, ts, jsx, and tsx files
|
|
258
|
+
files: ["directory/**/*.[jt]s?(x)"],
|
|
259
|
+
rules: {
|
|
260
|
+
"my-rule": "off"
|
|
187
261
|
}
|
|
188
|
-
|
|
189
|
-
|
|
262
|
+
}
|
|
263
|
+
];
|
|
190
264
|
```
|
|
191
265
|
|
|
192
266
|
### TypeScript
|
|
@@ -198,9 +272,10 @@ Several Typescript configs are available to cover various scenarios:
|
|
|
198
272
|
| `@haltcase/style/typescript/base` | Baseline config, intended to be extended from. |
|
|
199
273
|
| `@haltcase/style/typescript/bundler` | For use in bundled projects, most commonly [Vite](https://vitejs.dev/) + [React](https://react.dev). |
|
|
200
274
|
| `@haltcase/style/typescript/next` | For use in [Next.js](https://nextjs.org/) projects. |
|
|
201
|
-
| `@haltcase/style/typescript/node` | Default Node config, currently targeting Node
|
|
275
|
+
| `@haltcase/style/typescript/node` | Default Node config, currently targeting Node 22. |
|
|
202
276
|
| `@haltcase/style/typescript/node18` | For projects targeting Node 18. |
|
|
203
277
|
| `@haltcase/style/typescript/node20` | For projects targeting Node 20. |
|
|
278
|
+
| `@haltcase/style/typescript/node22` | For projects targeting Node 22. |
|
|
204
279
|
| `@haltcase/style/typescript/web` | For use in web projects. |
|
|
205
280
|
|
|
206
281
|
Typically, you'll only need to extend from one of these:
|
|
@@ -225,6 +300,16 @@ You could also combine them with an `extends` array in [Typescript 5+](https://d
|
|
|
225
300
|
> [!TIP]
|
|
226
301
|
> Run `tsc --showConfig` to see the result of the combined configs.
|
|
227
302
|
|
|
303
|
+
#### TypeScript includes, excludes, and `paths` aliases
|
|
304
|
+
|
|
305
|
+
Some TypeScript configs set `include`, `exclude`, and `paths` for you with
|
|
306
|
+
common options. Currently:
|
|
307
|
+
|
|
308
|
+
| Name | Description |
|
|
309
|
+
| ------------------------------------ | --------------------------------------------------------------------------------- |
|
|
310
|
+
| `@haltcase/style/typescript/bundler` | Includes `@/*` → `src/*` path alias. |
|
|
311
|
+
| `@haltcase/style/typescript/next` | Includes `@/*` → `src/*` path alias and Next.js `include` and `exclude` settings. |
|
|
312
|
+
|
|
228
313
|
### Stylelint
|
|
229
314
|
|
|
230
315
|
To format and check CSS with Stylelint, install the `stylelint` package and
|
package/stylelint/_base.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { defineConfig } from "stylelint-define-config";
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
module.exports = defineConfig({
|
|
5
|
+
export const stylelintBase = defineConfig({
|
|
8
6
|
extends: [
|
|
9
7
|
"stylelint-config-standard",
|
|
10
8
|
"stylelint-config-html",
|
package/stylelint/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
+
/* eslint-disable import-x/no-default-export */
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import { defineConfig } from "stylelint-define-config";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
import { stylelintBase } from "./_base.js";
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
module.exports = defineConfig({
|
|
10
|
-
...base,
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
...stylelintBase,
|
|
11
10
|
|
|
12
11
|
rules: {
|
|
13
|
-
...
|
|
12
|
+
...stylelintBase.rules,
|
|
14
13
|
|
|
15
14
|
// disable identifier casing rules
|
|
16
15
|
"custom-media-pattern": null,
|
package/stylelint/modules.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
+
/* eslint-disable import-x/no-default-export */
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
import { defineConfig } from "stylelint-define-config";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
import { stylelintBase } from "./_base.js";
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
+
const camelCaseRegex = /^[a-z][a-zA-Z0-9]+$/;
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
module.exports = defineConfig({
|
|
12
|
-
...base,
|
|
10
|
+
export default defineConfig({
|
|
11
|
+
...stylelintBase,
|
|
13
12
|
|
|
14
13
|
rules: {
|
|
15
|
-
...
|
|
14
|
+
...stylelintBase.rules,
|
|
16
15
|
|
|
17
16
|
"custom-media-pattern": camelCaseRegex,
|
|
18
17
|
|
package/stylelint/standard.js
CHANGED