@haltcase/style 7.0.0-canary.3 → 7.0.0-canary.5

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.
@@ -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
@@ -1 +1,13 @@
1
- export { getEslintCommonJsConfig } from "./internal/commonjs.js";
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 { ProjectServiceOptions } from "@typescript-eslint/types"
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 { getEslintCommonJsConfig } from "./commonjs.js";
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 {ProjectServiceOptions} [typescriptProjectServiceOptions = true] Custom TypeScript project service options for the `typescript-eslint` parser.
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
- ...getEslintCommonJsConfig(options)
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 getEslintCommonJsConfig = (options = {}) =>
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
  *
@@ -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} [_options]
14
+ * @param {import("./internal/base.js").HaltcaseStyleOptions} [options]
12
15
  */
13
- export const getEslintNextConfig = (_options = {}) =>
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
 
@@ -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
  }
@@ -1,4 +1,3 @@
1
- import { FlatCompat } from "@eslint/eslintrc";
2
1
  import eslintPluginImportX from "eslint-plugin-import-x";
3
2
  import eslintPluginJsxA11y from "eslint-plugin-jsx-a11y";
4
3
  import eslintPluginReact from "eslint-plugin-react";
@@ -7,21 +6,31 @@ import { config } from "typescript-eslint";
7
6
 
8
7
  import { jsxA11yRules } from "../rules/jsx-a11y.js";
9
8
  import { reactRules } from "../rules/react.js";
9
+ import { getEslintBaseConfig } from "./internal/base.js";
10
10
 
11
- const compat = new FlatCompat();
11
+ /**
12
+ * @param {import("./internal/base.js").HaltcaseStyleOptions} [options]
13
+ */
14
+ export const getEslintReactConfig = (options) =>
15
+ config(
16
+ ...getEslintBaseConfig(options),
17
+ ...getEslintReactConfigInternal(options)
18
+ );
12
19
 
13
20
  /**
14
21
  * @param {import("./internal/base.js").HaltcaseStyleOptions} [_options]
15
22
  */
16
- export const getEslintReactConfig = (_options = {}) =>
23
+ export const getEslintReactConfigInternal = (_options = {}) =>
17
24
  config({
18
25
  name: "@haltcase/react",
19
26
 
20
27
  extends: [
28
+ // @ts-ignore the modules types are incorrect
21
29
  {
22
30
  name: "@haltcase/react/recommended",
23
31
  ...eslintPluginReact.configs.flat.recommended
24
32
  },
33
+ // @ts-ignore the modules types are incorrect
25
34
  {
26
35
  name: "@haltcase/react/jsx-runtime",
27
36
  ...eslintPluginReact.configs.flat["jsx-runtime"]
@@ -29,7 +38,12 @@ export const getEslintReactConfig = (_options = {}) =>
29
38
 
30
39
  {
31
40
  name: "@haltcase/react/hooks",
32
- ...compat.config(eslintPluginReactHooks.configs.recommended)
41
+ plugins: {
42
+ "react-hooks": eslintPluginReactHooks
43
+ },
44
+ rules: {
45
+ ...eslintPluginReactHooks.configs.recommended.rules
46
+ }
33
47
  },
34
48
 
35
49
  {
@@ -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
- projectService: options.typescriptProjectServiceOptions ?? true
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 { getEslintBrowserConfig } from "./configs/browser.js";
3
+ import { getEslintBrowserConfigInternal } from "./configs/browser.js";
4
4
  import { getEslintBaseConfig } from "./configs/internal/base.js";
5
- import { getEslintNodeConfig } from "./configs/node.js";
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 ? getEslintBrowserConfig(options) : []),
14
- ...(options.node ? getEslintNodeConfig(options) : [])
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";
@@ -94,9 +94,11 @@ export const reactRules = {
94
94
  /**
95
95
  * Require props to be sorted alphabetically.
96
96
  *
97
+ * Disabled because it can be annoying when enabled while not having a lot of upside.
98
+ *
97
99
  * 🔧 Fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md
98
100
  */
99
- "react/jsx-sort-props": "warn",
101
+ "react/jsx-sort-props": "off",
100
102
  /**
101
103
  * Disallow usage of Array index in keys.
102
104
  *
@@ -57,5 +57,18 @@ export const typescriptExtensionRules = {
57
57
  *
58
58
  * 🚫 Not fixable - https://typescript-eslint.io/rules/no-useless-constructor/
59
59
  */
60
- "@typescript-eslint/no-useless-constructor": "error"
60
+ "@typescript-eslint/no-useless-constructor": "error",
61
+ /**
62
+ * Enforce template literal expressions to be of string type.
63
+ *
64
+ * 🚫 Not fixable - https://typescript-eslint.io/rules/restrict-template-expressions/
65
+ */
66
+ "@typescript-eslint/restrict-template-expressions": [
67
+ "error",
68
+ {
69
+ allow: [{ from: "lib", name: ["Error", "URL", "URLSearchParams"] }],
70
+ allowBoolean: true,
71
+ allowNumber: true
72
+ }
73
+ ]
61
74
  };
@@ -92,6 +92,7 @@ export const typescriptBaseRules = {
92
92
  "error",
93
93
  {
94
94
  ignorePrimitives: {
95
+ number: true,
95
96
  string: true
96
97
  }
97
98
  }
@@ -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
- selector: "variable"
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
- selector: "typeProperty"
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",
3
+ "version": "7.0.0-canary.5",
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
- getEslintCommonJsConfig,
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 Common JS rules to some files
143
- ...getEslintCommonJsConfig().map((config) => ({
142
+ // apply browser rules to some files
143
+ ...getEslintBrowserConfig().map((config) => ({
144
144
  ...config,
145
- files: ["src/legacy/cjs/**/*.js"]
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
- [`projectService: true`](https://typescript-eslint.io/packages/parser#projectservice).
172
+ [`project: true`](https://typescript-eslint.io/packages/parser/#project).
173
173
 
174
- You can customize this behavior with the `typescriptProjectServiceOptions` option:
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
- typescriptProjectServiceOptions: {
182
- allowDefaultProject: ["*.js"]
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
  ];