@haltcase/style 7.0.0-canary.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.
@@ -4,13 +4,21 @@ import { config } from "typescript-eslint";
4
4
  import { getEslintBaseConfig } from "./internal/base.js";
5
5
 
6
6
  /**
7
- * @param {import("./internal/base.js").HaltcaseStyleOptions} [options]
7
+ * @type {import("./internal/base.js").HaltcaseStyleCreator}
8
8
  */
9
9
  export const getEslintBrowserConfig = (options = {}) =>
10
+ config(
11
+ ...getEslintBaseConfig(options),
12
+ ...getEslintBrowserConfigInternal(options)
13
+ );
14
+
15
+ /**
16
+ * @type {import("./internal/base.js").HaltcaseStyleCreator}
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
+ * @type {import("./internal/base.js").HaltcaseStyleCreator}
8
+ */
9
+ export const getEslintCommonJsConfig = (options) =>
10
+ config(
11
+ ...getEslintBaseConfig(options),
12
+ ...getEslintCommonJsConfigInternal(options)
13
+ );
@@ -1,16 +1,12 @@
1
- // @ts-check
2
-
3
1
  /**
4
- * @import { ProjectServiceOptions } from "@typescript-eslint/types"
2
+ * @import { ParserOptions } from "@typescript-eslint/types"
5
3
  */
6
4
 
7
5
  import babelParser from "@babel/eslint-parser";
8
6
  import eslint from "@eslint/js";
9
7
  import eslintPluginEslintComments from "@eslint-community/eslint-plugin-eslint-comments";
10
- // eslint-disable-next-line import-x/default
11
8
  import eslintConfigPrettier from "eslint-config-prettier";
12
9
  import eslintPluginImportX from "eslint-plugin-import-x";
13
- // eslint-disable-next-line import-x/default
14
10
  import eslintRegexp from "eslint-plugin-regexp";
15
11
  import { config } from "typescript-eslint";
16
12
 
@@ -26,10 +22,8 @@ import { importRules } from "../../rules/imports.js";
26
22
  import { possibleErrorsRules } from "../../rules/possible-errors.js";
27
23
  import { stylisticRules } from "../../rules/stylistic.js";
28
24
  import { variablesRules } from "../../rules/variables.js";
29
- import { getEslintNextConfig } from "../next.js";
30
- import { getEslintReactConfig } from "../react.js";
31
25
  import { getEslintTypescriptConfig } from "../typescript.js";
32
- import { getEslintCommonJsConfig } from "./commonjs.js";
26
+ import { getEslintCommonJsConfigInternal } from "./commonjs.js";
33
27
  import { eslintEs2015Config } from "./es2015.js";
34
28
  import { eslintSimpleImportSortConfig } from "./simple-import-sort.js";
35
29
  import { eslintUnicornConfig } from "./unicorn.js";
@@ -41,13 +35,20 @@ import { eslintUnicornConfig } from "./unicorn.js";
41
35
  * @property {boolean} [nextjs] Whether to include Next.js rules (implies `react`).
42
36
  * @property {boolean} [node] Whether to include Node.js rules.
43
37
  * @property {boolean} [react] Whether to include React rules.
44
- * @property {ProjectServiceOptions} [typescriptProjectServiceOptions = true] Custom TypeScript project service options for the `typescript-eslint` parser.
38
+ * @property {ParserOptions["project"]} [typescriptProject = true] Custom TypeScript project options for the `typescript-eslint` parser.
39
+ * // use when VS Code supports `projectService`
40
+ * // https://github.com/microsoft/vscode-eslint/issues/1911
41
+ * property {ProjectServiceOptions} [typescriptProjectServiceOptions = true] Custom TypeScript project service options for the `typescript-eslint` parser.
42
+ */
43
+
44
+ /**
45
+ * @typedef {(options?: HaltcaseStyleOptions) => Awaited<import("typescript-eslint").Config>} HaltcaseStyleCreator
45
46
  */
46
47
 
47
48
  /**
48
49
  * Get the common ESLint config for Node and browsers.
49
50
  *
50
- * @param {HaltcaseStyleOptions} options
51
+ * @type {HaltcaseStyleCreator}
51
52
  */
52
53
  export const getEslintBaseConfig = (options = {}) =>
53
54
  config(
@@ -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
  );
@@ -3,9 +3,9 @@ import { config } from "typescript-eslint";
3
3
  import { commonJsFiles, commonJsOnlyFiles } from "../../constants.js";
4
4
 
5
5
  /**
6
- * @param {import("./base.js").HaltcaseStyleOptions} [options]
6
+ * @type {import("./base.js").HaltcaseStyleCreator}
7
7
  */
8
- export const getEslintCommonJsConfig = (options = {}) =>
8
+ export const getEslintCommonJsConfigInternal = (options = {}) =>
9
9
  config({
10
10
  name: "@haltcase/internal/CommonJS files",
11
11
 
@@ -1,5 +1,8 @@
1
1
  import { config } from "typescript-eslint";
2
2
 
3
+ /**
4
+ * @type {ReturnType<import("./base.js").HaltcaseStyleCreator>}
5
+ */
3
6
  export const eslintEs2015Config = config({
4
7
  name: "@haltcase/internal/ES2015",
5
8
 
@@ -1,6 +1,9 @@
1
1
  import eslintPluginSimpleImportSort from "eslint-plugin-simple-import-sort";
2
2
  import { config } from "typescript-eslint";
3
3
 
4
+ /**
5
+ * @type {ReturnType<import("./base.js").HaltcaseStyleCreator>}
6
+ */
4
7
  export const eslintSimpleImportSortConfig = config({
5
8
  name: "@haltcase/internal/Import & export sorting",
6
9
 
@@ -1,6 +1,9 @@
1
1
  import eslintPluginTsdoc from "eslint-plugin-tsdoc";
2
2
  import { config } from "typescript-eslint";
3
3
 
4
+ /**
5
+ * @type {ReturnType<import("./base.js").HaltcaseStyleCreator>}
6
+ */
4
7
  export const eslintTsdocConfig = config({
5
8
  name: "@haltcase/internal/TSDoc comments",
6
9
  plugins: {
@@ -1,6 +1,9 @@
1
1
  import eslintPluginUnicorn from "eslint-plugin-unicorn";
2
2
  import { config } from "typescript-eslint";
3
3
 
4
+ /**
5
+ * @type {ReturnType<import("./base.js").HaltcaseStyleCreator>}
6
+ */
4
7
  export const eslintUnicornConfig = config({
5
8
  name: "@haltcase/internal/Unicorn",
6
9
 
@@ -70,12 +73,6 @@ export const eslintUnicornConfig = config({
70
73
  * 🚫 Not fixable - https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/filename-case.md
71
74
  */
72
75
  "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
76
  /**
80
77
  * Enforce the use of `new` for all builtins, except `String`, `Number`, `Boolean`, `Symbol` and `BigInt`.
81
78
  *
@@ -2,24 +2,38 @@ import pluginNextjs from "@next/eslint-plugin-next";
2
2
  import { config } from "typescript-eslint";
3
3
 
4
4
  import {
5
- javascriptFiles,
5
+ allSupportedFiles,
6
6
  nextJsApiRoutes,
7
+ nextJsMetadataFiles,
7
8
  nextJsPageFiles
8
9
  } from "../constants.js";
10
+ import { getEslintBaseConfig } from "./internal/base.js";
11
+ import { getEslintNodeConfigInternal } from "./node.js";
12
+ import { getEslintReactConfigInternal } from "./react.js";
9
13
 
10
14
  /**
11
- * @param {import("./internal/base.js").HaltcaseStyleOptions} [_options]
15
+ * @type {import("./internal/base.js").HaltcaseStyleCreator}
12
16
  */
13
- export const getEslintNextConfig = (_options = {}) =>
17
+ export const getEslintNextConfig = (options = {}) =>
14
18
  config(
19
+ ...getEslintBaseConfig(options),
20
+ ...getEslintNodeConfigInternal(options),
21
+ ...getEslintNextConfigInternal(options)
22
+ );
23
+
24
+ /**
25
+ * @type {import("./internal/base.js").HaltcaseStyleCreator}
26
+ */
27
+ export const getEslintNextConfigInternal = (options = {}) =>
28
+ config(
29
+ ...getEslintReactConfigInternal(options),
15
30
  {
16
31
  name: "@haltcase/nextjs",
17
32
 
18
- files: javascriptFiles,
33
+ files: allSupportedFiles,
19
34
  plugins: {
20
35
  "@next/next": pluginNextjs
21
36
  },
22
- // @ts-expect-error inference issue
23
37
  rules: {
24
38
  ...pluginNextjs.configs.recommended.rules,
25
39
  ...pluginNextjs.configs["core-web-vitals"].rules
@@ -28,7 +42,7 @@ export const getEslintNextConfig = (_options = {}) =>
28
42
  {
29
43
  name: "Next.js page files and API routes",
30
44
 
31
- files: [...nextJsPageFiles, ...nextJsApiRoutes],
45
+ files: [...nextJsPageFiles, ...nextJsApiRoutes, ...nextJsMetadataFiles],
32
46
  rules: {
33
47
  "import-x/no-default-export": "off"
34
48
  }
@@ -4,13 +4,21 @@ import { config } from "typescript-eslint";
4
4
  import { getEslintBaseConfig } from "./internal/base.js";
5
5
 
6
6
  /**
7
- * @param {import("./internal/base.js").HaltcaseStyleOptions} [options]
7
+ * @type {import("./internal/base.js").HaltcaseStyleCreator}
8
8
  */
9
9
  export const getEslintNodeConfig = (options = {}) =>
10
+ config(
11
+ ...getEslintNodeConfigInternal(options),
12
+ ...getEslintBaseConfig(options)
13
+ );
14
+
15
+ /**
16
+ * @type {import("./internal/base.js").HaltcaseStyleCreator}
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
- * @param {import("./internal/base.js").HaltcaseStyleOptions} [_options]
10
+ * @type {import("./internal/base.js").HaltcaseStyleCreator}
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,54 +1,109 @@
1
- import { FlatCompat } from "@eslint/eslintrc";
1
+ import eslintPluginReact from "@eslint-react/eslint-plugin";
2
+ import eslintStylisticJsx from "@stylistic/eslint-plugin-jsx";
2
3
  import eslintPluginImportX from "eslint-plugin-import-x";
3
4
  import eslintPluginJsxA11y from "eslint-plugin-jsx-a11y";
4
- import eslintPluginReact from "eslint-plugin-react";
5
+ import eslintPluginReactOriginal from "eslint-plugin-react";
5
6
  import eslintPluginReactHooks from "eslint-plugin-react-hooks";
6
7
  import { config } from "typescript-eslint";
7
8
 
9
+ import { jsxFiles, typescriptJsxFiles } from "../constants.js";
8
10
  import { jsxA11yRules } from "../rules/jsx-a11y.js";
9
11
  import { reactRules } from "../rules/react.js";
12
+ import { reactXRules } from "../rules/react-x.js";
13
+ import { stylisticJsxRules } from "../rules/stylistic-jsx.js";
14
+ import { getEslintBaseConfig } from "./internal/base.js";
10
15
 
11
- const compat = new FlatCompat();
16
+ /**
17
+ * @type {import("./internal/base.js").HaltcaseStyleCreator}
18
+ */
19
+ export const getEslintReactConfig = (options) =>
20
+ config(
21
+ ...getEslintBaseConfig(options),
22
+ ...getEslintReactConfigInternal(options)
23
+ );
12
24
 
13
25
  /**
14
- * @param {import("./internal/base.js").HaltcaseStyleOptions} [_options]
26
+ * @type {import("./internal/base.js").HaltcaseStyleCreator}
15
27
  */
16
- export const getEslintReactConfig = (_options = {}) =>
17
- config({
18
- name: "@haltcase/react",
19
-
20
- extends: [
21
- {
22
- name: "@haltcase/react/recommended",
23
- ...eslintPluginReact.configs.flat.recommended
24
- },
25
- {
26
- name: "@haltcase/react/jsx-runtime",
27
- ...eslintPluginReact.configs.flat["jsx-runtime"]
28
- },
28
+ export const getEslintReactConfigInternal = (_options = {}) =>
29
+ config(
30
+ {
31
+ name: "@haltcase/react",
29
32
 
30
- {
31
- name: "@haltcase/react/hooks",
32
- ...compat.config(eslintPluginReactHooks.configs.recommended)
33
- },
33
+ files: jsxFiles,
34
+
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
+ }
45
+ },
46
+
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
+ }
65
+ },
66
+
67
+ {
68
+ name: "@haltcase/react/jsx-a11y",
69
+ ...eslintPluginJsxA11y.flatConfigs.recommended
70
+ },
34
71
 
35
- {
36
- name: "@haltcase/react/jsx-a11y",
37
- ...eslintPluginJsxA11y.flatConfigs.recommended
72
+ {
73
+ name: "@haltcase/react/import-x",
74
+ ...eslintPluginImportX.flatConfigs.react
75
+ }
76
+ ],
77
+ settings: {
78
+ react: {
79
+ version: "detect"
80
+ }
38
81
  },
39
- {
40
- name: "@haltcase/react/import-x",
41
- ...eslintPluginImportX.flatConfigs.react
82
+
83
+ rules: {
84
+ ...jsxA11yRules
42
85
  }
43
- ],
44
- settings: {
45
- react: {
46
- version: "detect"
86
+ },
87
+
88
+ {
89
+ ...eslintPluginReact.configs.recommended,
90
+
91
+ name: "@haltcase/react/recommended",
92
+
93
+ files: typescriptJsxFiles,
94
+ rules: {
95
+ ...reactXRules
47
96
  }
48
97
  },
49
98
 
50
- rules: {
51
- ...reactRules,
52
- ...jsxA11yRules
99
+ {
100
+ ...eslintPluginReact.configs["recommended-type-checked"],
101
+
102
+ name: "@haltcase/react/recommended-type-checked",
103
+
104
+ files: typescriptJsxFiles,
105
+ rules: {
106
+ ...reactXRules
107
+ }
53
108
  }
54
- });
109
+ );
@@ -1,4 +1,3 @@
1
- // eslint-disable-next-line import-x/default
2
1
  import eslintConfigPrettier from "eslint-config-prettier";
3
2
  import eslintPluginImportX from "eslint-plugin-import-x";
4
3
  import { config, configs, parser, plugin } from "typescript-eslint";
@@ -11,7 +10,7 @@ import { getTypescriptNamingConventionRule } from "../rules/typescript/naming-co
11
10
  import { eslintTsdocConfig } from "./internal/tsdoc.js";
12
11
 
13
12
  /**
14
- * @param {import("./internal/base.js").HaltcaseStyleOptions} [options]
13
+ * @type {import("./internal/base.js").HaltcaseStyleCreator}
15
14
  */
16
15
  export const getEslintTypescriptConfig = (options = {}) => {
17
16
  /** @type {import("typescript-eslint").ConfigWithExtends["languageOptions"]} */
@@ -24,7 +23,10 @@ export const getEslintTypescriptConfig = (options = {}) => {
24
23
  },
25
24
  // https://github.com/typescript-eslint/typescript-eslint/issues/3788#issuecomment-905094436
26
25
  jsxPragma: null,
27
- projectService: options.typescriptProjectServiceOptions ?? true
26
+ project: options.typescriptProject ?? true
27
+ // use `projectService` when VS Code supports it properly
28
+ // https://github.com/microsoft/vscode-eslint/issues/1911
29
+ // projectService: options.typescriptProjectServiceOptions ?? true
28
30
  }
29
31
  };
30
32
 
@@ -79,6 +81,26 @@ export const getEslintTypescriptConfig = (options = {}) => {
79
81
  isTsx: true
80
82
  })
81
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
+ }
82
104
  }
83
105
  );
84
106
  };
@@ -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 = ["**/{pages,app}/api/**/*.{m,}{js,ts}"];
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/index.js CHANGED
@@ -1,17 +1,24 @@
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
- * @param {import("./configs/internal/base.js").HaltcaseStyleOptions} [options]
10
+ * @type {import("./configs/internal/base.js").HaltcaseStyleCreator}
9
11
  */
10
- export const getEslintConfig = (options) =>
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";
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @import { Linter } from "eslint"
3
+ */
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
+
21
+ /**
22
+ * Additional rules to enable on top of the preset config from
23
+ * `@eslint-react/eslint-plugin`
24
+ *
25
+ * @type {Linter.RulesRecord}
26
+ */
27
+ export const reactXRules = {
28
+ ...disabledRules,
29
+
30
+ /**
31
+ * Prevents using useless `fragment` components or `<>` syntax.
32
+ *
33
+ * 🚫 Not fixable - https://eslint-react.xyz/docs/rules/no-useless-fragment
34
+ */
35
+ "@eslint-react/no-useless-fragment": "error",
36
+
37
+ /**
38
+ * Enforces using shorthand syntax for boolean attributes.
39
+ *
40
+ * 🔧 Fixable - https://eslint-react.xyz/docs/rules/prefer-shorthand-boolean
41
+ */
42
+ "@eslint-react/prefer-shorthand-boolean": "error",
43
+
44
+ /**
45
+ * Enforces using shorthand syntax for fragments.
46
+ *
47
+ * 🚫 Not fixable - https://eslint-react.xyz/docs/rules/prefer-shorthand-fragment
48
+ */
49
+ "@eslint-react/prefer-shorthand-fragment": "error",
50
+
51
+ /**
52
+ * Warns function calls made inside `useState` calls.
53
+ *
54
+ * 🚫 Not fixable - https://eslint-react.xyz/docs/rules/hooks-extra-prefer-use-state-lazy-initialization
55
+ */
56
+ "@eslint-react/hooks-extra/prefer-use-state-lazy-initialization": "error",
57
+
58
+ /**
59
+ * Enforces naming conventions for components.
60
+ *
61
+ * 🚫 Not fixable - https://eslint-react.xyz/docs/rules/naming-convention-component-name
62
+ */
63
+ "@eslint-react/naming-convention/component-name": "warn",
64
+
65
+ /**
66
+ * Enforces consistent use of the JSX file extension.
67
+ *
68
+ * 🚫 Not fixable - https://eslint-react.xyz/docs/rules/naming-convention-filename-extension
69
+ */
70
+ "@eslint-react/naming-convention/filename-extension": "warn",
71
+
72
+ /**
73
+ * Enforces destructuring and symmetric naming of useState hook value and setter variables.
74
+ *
75
+ * 🚫 Not fixable - https://eslint-react.xyz/docs/rules/naming-convention-use-state
76
+ */
77
+ "@eslint-react/naming-convention/use-state": "warn"
78
+ };
@@ -3,116 +3,22 @@
3
3
  */
4
4
 
5
5
  /**
6
- * These are enabled by `react/recommended`, but we've made the decision to
7
- * disable them.
6
+ * We primarily use `@eslint-react/eslint-plugin`, but it's not quite complete
7
+ * compared to the official plugin. We enable missing rules selectively here.
8
8
  *
9
9
  * @type {Linter.RulesRecord}
10
10
  */
11
- const disabledRules = {
12
- // This is better handled by TypeScript.
13
- "react/no-unknown-property": "off",
14
- // This is better handled by TypeScript, and `prop-types` also bloats
15
- // the project's build size.
16
- "react/prop-types": "off",
17
- // Disable requiring React to be imported, as this is no longer required.
18
- "react/react-in-jsx-scope": "off"
19
- };
20
-
21
- /**
22
- * @type {Linter.RulesRecord}
23
- */
24
11
  export const reactRules = {
25
- ...disabledRules,
26
- /**
27
- * Require an explicit type when using button elements.
28
- *
29
- * 🚫 Not fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/button-has-type.md
30
- */
31
- "react/button-has-type": "warn",
32
12
  /**
33
13
  * Require consistent function type for function components.
34
14
  *
35
15
  * 🔧 Fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/HEAD/docs/rules/function-component-definition.md
36
16
  */
37
- "react/function-component-definition": "warn",
38
- /**
39
- * Require destructuring and symmetric naming of `useState` hook value and setter variables.
40
- *
41
- * 🚫 Not fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/hook-use-state.md
42
- */
43
- "react/hook-use-state": "warn",
44
- /**
45
- * Require consistent boolean attributes notation in JSX.
46
- *
47
- * 🔧 Fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-boolean-value.md
48
- */
49
- "react/jsx-boolean-value": "warn",
50
- /**
51
- * Disallow unnecessary curly braces in JSX props and children.
52
- *
53
- * 🔧 Fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md
54
- */
55
- "react/jsx-curly-brace-presence": "warn",
56
- /**
57
- * Require using shorthand form for React fragments, unless required.
58
- *
59
- * 🔧 Fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-fragments.md
60
- */
61
- "react/jsx-fragments": "warn",
62
- /**
63
- * Prevent problematic leaked values from being rendered.
64
- *
65
- * 🔧 Fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-leaked-render.md
66
- */
67
- "react/jsx-no-leaked-render": "warn",
68
- /**
69
- * Prevents usage of unsafe `target='_blank'`.
70
- *
71
- * This rule is a part of `react/recommended`, but we've modified it to
72
- * allow referrer.
73
- *
74
- * 🔧 Fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-target-blank.md
75
- */
76
- "react/jsx-no-target-blank": [
17
+ "react/function-component-definition": [
77
18
  "error",
78
19
  {
79
- allowReferrer: true
20
+ namedComponents: "arrow-function",
21
+ unnamedComponents: "arrow-function"
80
22
  }
81
- ],
82
- /**
83
- * Disallow empty React fragments.
84
- *
85
- * 🔧 Fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-useless-fragment.md
86
- */
87
- "react/jsx-no-useless-fragment": ["warn", { allowExpressions: true }],
88
- /**
89
- * Require the use of PascalCase for user-defined JSX components.
90
- *
91
- * 🚫 Not fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-pascal-case.md
92
- */
93
- "react/jsx-pascal-case": "warn",
94
- /**
95
- * Require props to be sorted alphabetically.
96
- *
97
- * 🔧 Fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-sort-props.md
98
- */
99
- "react/jsx-sort-props": "warn",
100
- /**
101
- * Disallow usage of Array index in keys.
102
- *
103
- * 🚫 Not fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md
104
- */
105
- "react/no-array-index-key": "warn",
106
- /**
107
- * Disallow creating unstable components inside components.
108
- *
109
- * 🚫 Not fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unstable-nested-components.md
110
- */
111
- "react/no-unstable-nested-components": "error",
112
- /**
113
- * Disallow closing tags for components without children.
114
- *
115
- * 🔧 Fixable - https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/self-closing-comp.md
116
- */
117
- "react/self-closing-comp": "warn"
23
+ ]
118
24
  };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @import { Linter } from "eslint"
3
+ */
4
+
5
+ /**
6
+ * @type {Linter.RulesRecord}
7
+ */
8
+ export const stylisticJsxRules = {
9
+ /**
10
+ * Disallow extra closing tags for components without children.
11
+ *
12
+ * Components without children can be self-closed to avoid unnecessary extra closing tag.
13
+ *
14
+ * 🔧 Fixable - https://eslint.style/rules/jsx/jsx-self-closing-comp
15
+ */
16
+ "@stylistic/jsx/jsx-self-closing-comp": "error"
17
+ };
@@ -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
  }
@@ -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 = ({ isTsx = false } = {}) => ({
11
+ export const getTypescriptNamingConventionRule = ({
12
+ isComponentLike = false,
13
+ isTsx = false
14
+ } = {}) => ({
11
15
  /**
12
16
  * Require consistent naming conventions.
13
17
  *
@@ -17,13 +21,45 @@ export const getTypescriptNamingConventionRule = ({ isTsx = false } = {}) => ({
17
21
  */
18
22
  "@typescript-eslint/naming-convention": [
19
23
  "error",
24
+ // enforce that unused variable-likes are prefixed with `_`
25
+ {
26
+ format: [
27
+ "camelCase",
28
+ (isComponentLike || isTsx) && "StrictPascalCase"
29
+ ].filter(Boolean),
30
+ leadingUnderscore: "require",
31
+ modifiers: ["unused"],
32
+ selector: "variableLike",
33
+ trailingUnderscore: "forbid"
34
+ },
20
35
  // enforce that everything is camelCase by default
21
36
  {
22
- format: ["camelCase", isTsx && "StrictPascalCase"].filter(Boolean),
37
+ format: [
38
+ "camelCase",
39
+ (isComponentLike || isTsx) && "StrictPascalCase"
40
+ ].filter(Boolean),
23
41
  leadingUnderscore: "forbid",
24
42
  selector: "default",
25
43
  trailingUnderscore: "forbid"
26
44
  },
45
+ // allow HTTP methods in UPPER_CASE
46
+ {
47
+ filter: {
48
+ match: true,
49
+ regex: "^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)$"
50
+ },
51
+ format: null,
52
+ selector: ["variableLike"]
53
+ },
54
+ // allow variable-likes called exactly "_"
55
+ {
56
+ filter: {
57
+ match: true,
58
+ regex: "^_$"
59
+ },
60
+ format: null,
61
+ selector: ["variableLike", "typeProperty"]
62
+ },
27
63
  // anything type-like must be written in PascalCase
28
64
  {
29
65
  format: ["PascalCase"],
@@ -61,11 +97,25 @@ export const getTypescriptNamingConventionRule = ({ isTsx = false } = {}) => ({
61
97
  {
62
98
  format: null,
63
99
  modifiers: ["destructured"],
64
- selector: "variable"
100
+ prefix: [],
101
+ selector: ["variable", "parameter"]
65
102
  },
103
+ // ignore destructured booleans; requires enough specificity to override
104
+ // the above rule enforcing prefixes
66
105
  {
67
106
  format: null,
68
- selector: "typeProperty"
107
+ leadingUnderscore: "forbid",
108
+ modifiers: ["destructured"],
109
+ prefix: [],
110
+ selector: "variable",
111
+ trailingUnderscore: "forbid",
112
+ types: ["boolean"]
113
+ },
114
+ // enforce that all type parameters begin with `T`
115
+ {
116
+ format: ["PascalCase"],
117
+ prefix: ["T"],
118
+ selector: "typeParameter"
69
119
  }
70
120
  ]
71
121
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haltcase/style",
3
- "version": "7.0.0-canary.1",
3
+ "version": "7.0.0-canary.10",
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",
@@ -68,63 +61,62 @@
68
61
  "@babel/core": "^7.26.0",
69
62
  "@babel/eslint-parser": "^7.25.9",
70
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",
71
67
  "eslint-config-prettier": "^9.1.0",
72
68
  "eslint-import-resolver-alias": "^1.1.2",
73
69
  "eslint-import-resolver-typescript": "^3.6.3",
74
- "eslint-plugin-import-x": "^4.4.0",
70
+ "eslint-plugin-import-x": "^4.4.3",
75
71
  "eslint-plugin-jsx-a11y": "^6.10.2",
76
- "eslint-plugin-playwright": "^2.0.0",
72
+ "eslint-plugin-playwright": "^2.1.0",
77
73
  "eslint-plugin-react": "^7.37.2",
78
74
  "eslint-plugin-react-hooks": "^5.0.0",
79
- "eslint-plugin-regexp": "^2.6.0",
75
+ "eslint-plugin-regexp": "^2.7.0",
80
76
  "eslint-plugin-simple-import-sort": "^12.1.1",
81
- "eslint-plugin-testing-library": "^6.4.0",
82
- "eslint-plugin-tsdoc": "^0.3.0",
83
- "eslint-plugin-unicorn": "^56.0.0",
77
+ "eslint-plugin-testing-library": "^6.5.0",
78
+ "eslint-plugin-tsdoc": "^0.4.0",
79
+ "eslint-plugin-unicorn": "^56.0.1",
84
80
  "postcss-html": "^1.7.0",
85
- "prettier-plugin-packagejson": "^2.5.3",
86
- "prettier-plugin-tailwindcss": "^0.6.8",
81
+ "prettier-plugin-packagejson": "^2.5.6",
82
+ "prettier-plugin-tailwindcss": "^0.6.9",
87
83
  "stylelint-config-clean-order": "^6.1.0",
88
84
  "stylelint-config-html": "^1.1.0",
89
85
  "stylelint-config-standard": "^36.0.1",
90
- "stylelint-define-config": "^1.7.0"
86
+ "stylelint-define-config": "^1.7.0",
87
+ "typescript-eslint": "^8.16.0"
91
88
  },
92
89
  "devDependencies": {
93
90
  "@actions/core": "^1.11.1",
94
91
  "@actions/exec": "^1.1.1",
95
92
  "@actions/github": "^6.0.0",
96
- "@commitlint/cli": "^19.5.0",
97
- "@commitlint/config-conventional": "^19.5.0",
98
- "@eslint/eslintrc": "^3.1.0",
99
- "@eslint/js": "^9.14.0",
100
- "@octokit/types": "^13.6.1",
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",
101
98
  "@semantic-release/git": "^10.0.1",
102
99
  "@types/eslint-config-prettier": "^6.11.3",
103
100
  "@types/eslint__js": "^8.42.3",
104
101
  "@types/node": "22",
105
- "@typescript-eslint/types": "^8.12.2",
106
- "eslint": "^9.14.0",
102
+ "@typescript-eslint/types": "^8.16.0",
103
+ "eslint": "^9.15.0",
107
104
  "eslint-define-config": "^2.1.0",
108
- "globals": "^15.11.0",
109
- "husky": "^9.1.6",
105
+ "globals": "^15.12.0",
106
+ "husky": "^9.1.7",
110
107
  "lint-staged": "^15.2.10",
111
- "prettier": "^3.3.3",
108
+ "prettier": "^3.4.1",
112
109
  "semantic-release": "^24.2.0",
113
110
  "stylelint": "^16.10.0",
114
- "typescript": "^5.6.3",
115
- "typescript-eslint": "^8.12.2"
111
+ "typescript": "^5.7.2"
116
112
  },
117
113
  "peerDependencies": {
118
- "@next/eslint-plugin-next": ">=14 <16",
119
114
  "eslint": ">=9",
120
115
  "prettier": ">=3.0.0 <4",
121
116
  "stylelint": ">=16.3.1 <17",
122
117
  "typescript": ">=5.0.0 <6"
123
118
  },
124
119
  "peerDependenciesMeta": {
125
- "@next/eslint-plugin-next": {
126
- "optional": true
127
- },
128
120
  "eslint": {
129
121
  "optional": true
130
122
  },
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
  ];