@haltcase/style 7.0.0-canary.3 → 7.0.0-canary.4
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 +9 -1
- package/eslint/configs/cjs.js +13 -1
- package/eslint/configs/internal/base.js +7 -9
- package/eslint/configs/internal/commonjs.js +1 -1
- package/eslint/configs/internal/unicorn.js +0 -6
- package/eslint/configs/next.js +16 -2
- package/eslint/configs/node.js +9 -1
- package/eslint/configs/playwright-test.js +5 -1
- package/eslint/configs/react.js +15 -1
- package/eslint/configs/typescript.js +4 -1
- package/eslint/index.js +11 -5
- package/eslint/rules/typescript/naming-convention.js +33 -2
- package/package.json +1 -8
- package/readme.md +12 -10
|
@@ -7,10 +7,18 @@ import { getEslintBaseConfig } from "./internal/base.js";
|
|
|
7
7
|
* @param {import("./internal/base.js").HaltcaseStyleOptions} [options]
|
|
8
8
|
*/
|
|
9
9
|
export const getEslintBrowserConfig = (options = {}) =>
|
|
10
|
+
config(
|
|
11
|
+
...getEslintBaseConfig(options),
|
|
12
|
+
...getEslintBrowserConfigInternal(options)
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {import("./internal/base.js").HaltcaseStyleOptions} [_options]
|
|
17
|
+
*/
|
|
18
|
+
export const getEslintBrowserConfigInternal = (_options = {}) =>
|
|
10
19
|
config({
|
|
11
20
|
name: "Browser",
|
|
12
21
|
|
|
13
|
-
extends: [...getEslintBaseConfig(options)],
|
|
14
22
|
languageOptions: {
|
|
15
23
|
globals: {
|
|
16
24
|
...globals.browser
|
package/eslint/configs/cjs.js
CHANGED
|
@@ -1 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { config } from "typescript-eslint";
|
|
2
|
+
|
|
3
|
+
import { getEslintBaseConfig } from "./internal/base.js";
|
|
4
|
+
import { getEslintCommonJsConfigInternal } from "./internal/commonjs.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {import("./internal/base.js").HaltcaseStyleOptions} [options]
|
|
8
|
+
*/
|
|
9
|
+
export const getEslintCommonJsConfig = (options) =>
|
|
10
|
+
config(
|
|
11
|
+
...getEslintBaseConfig(options),
|
|
12
|
+
...getEslintCommonJsConfigInternal(options)
|
|
13
|
+
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @import {
|
|
4
|
+
* @import { ParserOptions } from "@typescript-eslint/types"
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import babelParser from "@babel/eslint-parser";
|
|
@@ -26,10 +26,8 @@ import { importRules } from "../../rules/imports.js";
|
|
|
26
26
|
import { possibleErrorsRules } from "../../rules/possible-errors.js";
|
|
27
27
|
import { stylisticRules } from "../../rules/stylistic.js";
|
|
28
28
|
import { variablesRules } from "../../rules/variables.js";
|
|
29
|
-
import { getEslintNextConfig } from "../next.js";
|
|
30
|
-
import { getEslintReactConfig } from "../react.js";
|
|
31
29
|
import { getEslintTypescriptConfig } from "../typescript.js";
|
|
32
|
-
import {
|
|
30
|
+
import { getEslintCommonJsConfigInternal } from "./commonjs.js";
|
|
33
31
|
import { eslintEs2015Config } from "./es2015.js";
|
|
34
32
|
import { eslintSimpleImportSortConfig } from "./simple-import-sort.js";
|
|
35
33
|
import { eslintUnicornConfig } from "./unicorn.js";
|
|
@@ -41,7 +39,10 @@ import { eslintUnicornConfig } from "./unicorn.js";
|
|
|
41
39
|
* @property {boolean} [nextjs] Whether to include Next.js rules (implies `react`).
|
|
42
40
|
* @property {boolean} [node] Whether to include Node.js rules.
|
|
43
41
|
* @property {boolean} [react] Whether to include React rules.
|
|
44
|
-
* @property {
|
|
42
|
+
* @property {ParserOptions["project"]} [typescriptProject = true] Custom TypeScript project options for the `typescript-eslint` parser.
|
|
43
|
+
* // use when VS Code supports `projectService`
|
|
44
|
+
* // https://github.com/microsoft/vscode-eslint/issues/1911
|
|
45
|
+
* property {ProjectServiceOptions} [typescriptProjectServiceOptions = true] Custom TypeScript project service options for the `typescript-eslint` parser.
|
|
45
46
|
*/
|
|
46
47
|
|
|
47
48
|
/**
|
|
@@ -155,9 +156,6 @@ export const getEslintBaseConfig = (options = {}) =>
|
|
|
155
156
|
|
|
156
157
|
...getEslintTypescriptConfig(options),
|
|
157
158
|
|
|
158
|
-
...(options.nextjs ? getEslintNextConfig(options) : []),
|
|
159
|
-
...(options.react || options.nextjs ? getEslintReactConfig(options) : []),
|
|
160
|
-
|
|
161
159
|
{
|
|
162
160
|
name: "@haltcase/internal/Third-party config files (e.g., next.config.mjs)",
|
|
163
161
|
files: configFiles,
|
|
@@ -176,5 +174,5 @@ export const getEslintBaseConfig = (options = {}) =>
|
|
|
176
174
|
}
|
|
177
175
|
},
|
|
178
176
|
|
|
179
|
-
...
|
|
177
|
+
...getEslintCommonJsConfigInternal(options)
|
|
180
178
|
);
|
|
@@ -5,7 +5,7 @@ import { commonJsFiles, commonJsOnlyFiles } from "../../constants.js";
|
|
|
5
5
|
/**
|
|
6
6
|
* @param {import("./base.js").HaltcaseStyleOptions} [options]
|
|
7
7
|
*/
|
|
8
|
-
export const
|
|
8
|
+
export const getEslintCommonJsConfigInternal = (options = {}) =>
|
|
9
9
|
config({
|
|
10
10
|
name: "@haltcase/internal/CommonJS files",
|
|
11
11
|
|
|
@@ -70,12 +70,6 @@ export const eslintUnicornConfig = config({
|
|
|
70
70
|
* 🚫 Not fixable - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/filename-case.md
|
|
71
71
|
*/
|
|
72
72
|
"unicorn/filename-case": "off",
|
|
73
|
-
/**
|
|
74
|
-
* Enforce specific import styles per module.
|
|
75
|
-
*
|
|
76
|
-
* 🚫 Not fixable - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/import-style.md
|
|
77
|
-
*/
|
|
78
|
-
"unicorn/import-style": "error",
|
|
79
73
|
/**
|
|
80
74
|
* Enforce the use of `new` for all builtins, except `String`, `Number`, `Boolean`, `Symbol` and `BigInt`.
|
|
81
75
|
*
|
package/eslint/configs/next.js
CHANGED
|
@@ -6,12 +6,26 @@ import {
|
|
|
6
6
|
nextJsApiRoutes,
|
|
7
7
|
nextJsPageFiles
|
|
8
8
|
} from "../constants.js";
|
|
9
|
+
import { getEslintBaseConfig } from "./internal/base.js";
|
|
10
|
+
import { getEslintNodeConfigInternal } from "./node.js";
|
|
11
|
+
import { getEslintReactConfigInternal } from "./react.js";
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
|
-
* @param {import("./internal/base.js").HaltcaseStyleOptions} [
|
|
14
|
+
* @param {import("./internal/base.js").HaltcaseStyleOptions} [options]
|
|
12
15
|
*/
|
|
13
|
-
export const getEslintNextConfig = (
|
|
16
|
+
export const getEslintNextConfig = (options = {}) =>
|
|
14
17
|
config(
|
|
18
|
+
...getEslintBaseConfig(options),
|
|
19
|
+
...getEslintNodeConfigInternal(options),
|
|
20
|
+
...getEslintNextConfigInternal(options)
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {import("./internal/base.js").HaltcaseStyleOptions} [options]
|
|
25
|
+
*/
|
|
26
|
+
export const getEslintNextConfigInternal = (options = {}) =>
|
|
27
|
+
config(
|
|
28
|
+
...getEslintReactConfigInternal(options),
|
|
15
29
|
{
|
|
16
30
|
name: "@haltcase/nextjs",
|
|
17
31
|
|
package/eslint/configs/node.js
CHANGED
|
@@ -7,10 +7,18 @@ import { getEslintBaseConfig } from "./internal/base.js";
|
|
|
7
7
|
* @param {import("./internal/base.js").HaltcaseStyleOptions} [options]
|
|
8
8
|
*/
|
|
9
9
|
export const getEslintNodeConfig = (options = {}) =>
|
|
10
|
+
config(
|
|
11
|
+
...getEslintNodeConfigInternal(options),
|
|
12
|
+
...getEslintBaseConfig(options)
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {import("./internal/base.js").HaltcaseStyleOptions} [_options]
|
|
17
|
+
*/
|
|
18
|
+
export const getEslintNodeConfigInternal = (_options = {}) =>
|
|
10
19
|
config({
|
|
11
20
|
name: "@haltcase/Node.js",
|
|
12
21
|
|
|
13
|
-
extends: [...getEslintBaseConfig(options)],
|
|
14
22
|
languageOptions: {
|
|
15
23
|
globals: {
|
|
16
24
|
...globals.node
|
|
@@ -3,14 +3,18 @@ import { config } from "typescript-eslint";
|
|
|
3
3
|
|
|
4
4
|
import { playwrightTestRules } from "../rules/playwright-test.js";
|
|
5
5
|
|
|
6
|
+
const playwrightRecommendedConfig =
|
|
7
|
+
eslintPluginPlaywright.configs["flat/recommended"];
|
|
8
|
+
|
|
6
9
|
/**
|
|
7
10
|
* @param {import("./internal/base.js").HaltcaseStyleOptions} [_options]
|
|
8
11
|
*/
|
|
9
12
|
export const getEslintPlaywrightTestConfig = (_options = {}) =>
|
|
10
13
|
config({
|
|
14
|
+
...playwrightRecommendedConfig,
|
|
15
|
+
|
|
11
16
|
name: "Playwright tests",
|
|
12
17
|
|
|
13
|
-
extends: [eslintPluginPlaywright.configs["flat/recommended"]],
|
|
14
18
|
rules: {
|
|
15
19
|
...playwrightTestRules
|
|
16
20
|
}
|
package/eslint/configs/react.js
CHANGED
|
@@ -2,26 +2,39 @@ import { FlatCompat } from "@eslint/eslintrc";
|
|
|
2
2
|
import eslintPluginImportX from "eslint-plugin-import-x";
|
|
3
3
|
import eslintPluginJsxA11y from "eslint-plugin-jsx-a11y";
|
|
4
4
|
import eslintPluginReact from "eslint-plugin-react";
|
|
5
|
+
// @ts-ignore
|
|
5
6
|
import eslintPluginReactHooks from "eslint-plugin-react-hooks";
|
|
6
7
|
import { config } from "typescript-eslint";
|
|
7
8
|
|
|
8
9
|
import { jsxA11yRules } from "../rules/jsx-a11y.js";
|
|
9
10
|
import { reactRules } from "../rules/react.js";
|
|
11
|
+
import { getEslintBaseConfig } from "./internal/base.js";
|
|
10
12
|
|
|
11
13
|
const compat = new FlatCompat();
|
|
12
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @param {import("./internal/base.js").HaltcaseStyleOptions} [options]
|
|
17
|
+
*/
|
|
18
|
+
export const getEslintReactConfig = (options) =>
|
|
19
|
+
config(
|
|
20
|
+
...getEslintBaseConfig(options),
|
|
21
|
+
...getEslintReactConfigInternal(options)
|
|
22
|
+
);
|
|
23
|
+
|
|
13
24
|
/**
|
|
14
25
|
* @param {import("./internal/base.js").HaltcaseStyleOptions} [_options]
|
|
15
26
|
*/
|
|
16
|
-
export const
|
|
27
|
+
export const getEslintReactConfigInternal = (_options = {}) =>
|
|
17
28
|
config({
|
|
18
29
|
name: "@haltcase/react",
|
|
19
30
|
|
|
20
31
|
extends: [
|
|
32
|
+
// @ts-ignore the modules types are incorrect
|
|
21
33
|
{
|
|
22
34
|
name: "@haltcase/react/recommended",
|
|
23
35
|
...eslintPluginReact.configs.flat.recommended
|
|
24
36
|
},
|
|
37
|
+
// @ts-ignore the modules types are incorrect
|
|
25
38
|
{
|
|
26
39
|
name: "@haltcase/react/jsx-runtime",
|
|
27
40
|
...eslintPluginReact.configs.flat["jsx-runtime"]
|
|
@@ -29,6 +42,7 @@ export const getEslintReactConfig = (_options = {}) =>
|
|
|
29
42
|
|
|
30
43
|
{
|
|
31
44
|
name: "@haltcase/react/hooks",
|
|
45
|
+
// @ts-ignore the modules types are incorrect
|
|
32
46
|
...compat.config(eslintPluginReactHooks.configs.recommended)
|
|
33
47
|
},
|
|
34
48
|
|
|
@@ -24,7 +24,10 @@ export const getEslintTypescriptConfig = (options = {}) => {
|
|
|
24
24
|
},
|
|
25
25
|
// https://github.com/typescript-eslint/typescript-eslint/issues/3788#issuecomment-905094436
|
|
26
26
|
jsxPragma: null,
|
|
27
|
-
|
|
27
|
+
project: options.typescriptProject ?? true
|
|
28
|
+
// use `projectService` when VS Code supports it properly
|
|
29
|
+
// https://github.com/microsoft/vscode-eslint/issues/1911
|
|
30
|
+
// projectService: options.typescriptProjectServiceOptions ?? true
|
|
28
31
|
}
|
|
29
32
|
};
|
|
30
33
|
|
package/eslint/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { config } from "typescript-eslint";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { getEslintBrowserConfigInternal } from "./configs/browser.js";
|
|
4
4
|
import { getEslintBaseConfig } from "./configs/internal/base.js";
|
|
5
|
-
import {
|
|
5
|
+
import { getEslintNextConfigInternal } from "./configs/next.js";
|
|
6
|
+
import { getEslintNodeConfigInternal } from "./configs/node.js";
|
|
7
|
+
import { getEslintReactConfigInternal } from "./configs/react.js";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* @param {import("./configs/internal/base.js").HaltcaseStyleOptions} [options]
|
|
@@ -10,8 +12,13 @@ import { getEslintNodeConfig } from "./configs/node.js";
|
|
|
10
12
|
export const getEslintConfig = (options) =>
|
|
11
13
|
config(
|
|
12
14
|
...getEslintBaseConfig(options),
|
|
13
|
-
...(options.browser ?
|
|
14
|
-
...(options.node ?
|
|
15
|
+
...(options.browser ? getEslintBrowserConfigInternal(options) : []),
|
|
16
|
+
...(options.node ? getEslintNodeConfigInternal(options) : []),
|
|
17
|
+
|
|
18
|
+
...(options.nextjs ? getEslintNextConfigInternal(options) : []),
|
|
19
|
+
...(options.react && !options.nextjs
|
|
20
|
+
? getEslintReactConfigInternal(options)
|
|
21
|
+
: [])
|
|
15
22
|
);
|
|
16
23
|
|
|
17
24
|
// eslint-disable-next-line import-x/no-default-export
|
|
@@ -19,7 +26,6 @@ export default getEslintConfig;
|
|
|
19
26
|
|
|
20
27
|
export { getEslintBrowserConfig } from "./configs/browser.js";
|
|
21
28
|
export { getEslintCommonJsConfig } from "./configs/cjs.js";
|
|
22
|
-
export { getEslintBaseConfig } from "./configs/internal/base.js";
|
|
23
29
|
export { getEslintNextConfig } from "./configs/next.js";
|
|
24
30
|
export { getEslintNodeConfig } from "./configs/node.js";
|
|
25
31
|
export { getEslintReactConfig } from "./configs/react.js";
|
|
@@ -17,6 +17,14 @@ export const getTypescriptNamingConventionRule = ({ isTsx = false } = {}) => ({
|
|
|
17
17
|
*/
|
|
18
18
|
"@typescript-eslint/naming-convention": [
|
|
19
19
|
"error",
|
|
20
|
+
// enforce that unused variable-likes are prefixed with `_`
|
|
21
|
+
{
|
|
22
|
+
format: ["camelCase", isTsx && "StrictPascalCase"].filter(Boolean),
|
|
23
|
+
leadingUnderscore: "require",
|
|
24
|
+
modifiers: ["unused"],
|
|
25
|
+
selector: "variableLike",
|
|
26
|
+
trailingUnderscore: "forbid"
|
|
27
|
+
},
|
|
20
28
|
// enforce that everything is camelCase by default
|
|
21
29
|
{
|
|
22
30
|
format: ["camelCase", isTsx && "StrictPascalCase"].filter(Boolean),
|
|
@@ -24,6 +32,15 @@ export const getTypescriptNamingConventionRule = ({ isTsx = false } = {}) => ({
|
|
|
24
32
|
selector: "default",
|
|
25
33
|
trailingUnderscore: "forbid"
|
|
26
34
|
},
|
|
35
|
+
// allow variable-likes called exactly "_"
|
|
36
|
+
{
|
|
37
|
+
filter: {
|
|
38
|
+
match: true,
|
|
39
|
+
regex: "^_$"
|
|
40
|
+
},
|
|
41
|
+
format: null,
|
|
42
|
+
selector: ["variableLike", "typeProperty"]
|
|
43
|
+
},
|
|
27
44
|
// anything type-like must be written in PascalCase
|
|
28
45
|
{
|
|
29
46
|
format: ["PascalCase"],
|
|
@@ -61,11 +78,25 @@ export const getTypescriptNamingConventionRule = ({ isTsx = false } = {}) => ({
|
|
|
61
78
|
{
|
|
62
79
|
format: null,
|
|
63
80
|
modifiers: ["destructured"],
|
|
64
|
-
|
|
81
|
+
prefix: [],
|
|
82
|
+
selector: ["variable", "parameter"]
|
|
65
83
|
},
|
|
84
|
+
// ignore destructured booleans; requires enough specificity to override
|
|
85
|
+
// the above rule enforcing prefixes
|
|
66
86
|
{
|
|
67
87
|
format: null,
|
|
68
|
-
|
|
88
|
+
leadingUnderscore: "forbid",
|
|
89
|
+
modifiers: ["destructured"],
|
|
90
|
+
prefix: [],
|
|
91
|
+
selector: "variable",
|
|
92
|
+
trailingUnderscore: "forbid",
|
|
93
|
+
types: ["boolean"]
|
|
94
|
+
},
|
|
95
|
+
// enforce that all type parameters begin with `T`
|
|
96
|
+
{
|
|
97
|
+
format: ["PascalCase"],
|
|
98
|
+
prefix: ["T"],
|
|
99
|
+
selector: "typeParameter"
|
|
69
100
|
}
|
|
70
101
|
]
|
|
71
102
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haltcase/style",
|
|
3
|
-
"version": "7.0.0-canary.
|
|
3
|
+
"version": "7.0.0-canary.4",
|
|
4
4
|
"description": "haltcase's web ecosystem style guide & configurations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -22,13 +22,6 @@
|
|
|
22
22
|
"./eslint": "./eslint/index.js",
|
|
23
23
|
"./eslint/rules/*": "./eslint/rules/*.js",
|
|
24
24
|
"./eslint/rules/*.js": "./eslint/rules/*.js",
|
|
25
|
-
"./eslint/browser": "./eslint/configs/browser.js",
|
|
26
|
-
"./eslint/cjs": "./eslint/configs/cjs.js",
|
|
27
|
-
"./eslint/next": "./eslint/configs/next.js",
|
|
28
|
-
"./eslint/node": "./eslint/configs/node.js",
|
|
29
|
-
"./eslint/playwright-test": "./eslint/configs/playwright-test.js",
|
|
30
|
-
"./eslint/react": "./eslint/configs/react.js",
|
|
31
|
-
"./eslint/typescript": "./eslint/configs/typescript.js",
|
|
32
25
|
"./prettier": "./prettier/index.js",
|
|
33
26
|
"./stylelint": "./stylelint/index.js",
|
|
34
27
|
"./stylelint/modules": "./stylelint/modules.js",
|
package/readme.md
CHANGED
|
@@ -129,7 +129,7 @@ also exported from `@haltcase/style/eslint`:
|
|
|
129
129
|
// eslint.config.js
|
|
130
130
|
import {
|
|
131
131
|
getEslintBaseConfig,
|
|
132
|
-
|
|
132
|
+
getEslintBrowserConfig,
|
|
133
133
|
getEslintNodeConfig,
|
|
134
134
|
getEslintReactConfig,
|
|
135
135
|
withFiles
|
|
@@ -139,10 +139,10 @@ export default [
|
|
|
139
139
|
// use the base config for everything by default
|
|
140
140
|
...getEslintBaseConfig(),
|
|
141
141
|
|
|
142
|
-
// apply
|
|
143
|
-
...
|
|
142
|
+
// apply browser rules to some files
|
|
143
|
+
...getEslintBrowserConfig().map((config) => ({
|
|
144
144
|
...config,
|
|
145
|
-
files: ["src/
|
|
145
|
+
files: ["src/client-only/**/*.js"]
|
|
146
146
|
})),
|
|
147
147
|
|
|
148
148
|
// apply React rules to some files
|
|
@@ -169,18 +169,19 @@ export default [
|
|
|
169
169
|
|
|
170
170
|
Some of the rules enabled in the TypeScript config require additional type
|
|
171
171
|
information. By default, this config will configure `parserOptions` with
|
|
172
|
-
[`
|
|
172
|
+
[`project: true`](https://typescript-eslint.io/packages/parser/#project).
|
|
173
173
|
|
|
174
|
-
You can customize this behavior with the `
|
|
174
|
+
You can customize this behavior with the `typescriptProject` option:
|
|
175
175
|
|
|
176
176
|
```js
|
|
177
177
|
import { getEslintConfig } from "@haltcase/style/eslint";
|
|
178
178
|
|
|
179
179
|
export default [
|
|
180
180
|
...getEslintConfig({
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
typescriptProject: [
|
|
182
|
+
"./packages/**/tsconfig.json",
|
|
183
|
+
"./separate-package/tsconfig.json"
|
|
184
|
+
]
|
|
184
185
|
})
|
|
185
186
|
];
|
|
186
187
|
```
|
|
@@ -197,7 +198,8 @@ export default [
|
|
|
197
198
|
{
|
|
198
199
|
files: ["*.{c,m,}ts{x,}"],
|
|
199
200
|
parserOptions: {
|
|
200
|
-
project: true
|
|
201
|
+
project: true,
|
|
202
|
+
tsConfigRootDir: "/custom/config/directory"
|
|
201
203
|
}
|
|
202
204
|
}
|
|
203
205
|
];
|