@haltcase/style 8.0.0-canary.1 → 8.0.0-canary.3

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.
@@ -1,3 +1,13 @@
1
+ /**
2
+ * @typedef {Object} TypeScriptProjectServiceOptions
3
+ * @property {true} projectService Use the TypeScript ESLint [project service](https://typescript-eslint.io/packages/parser#projectservice).
4
+ * @property {string | string[] | undefined} [tsconfigPaths] Paths to tsconfig.json files for resolving and linting imports.
5
+ * This defaults to `<root>/tsconfig.json` or `<root>/jsconfig.json` and
6
+ * [project references](https://www.typescriptlang.org/docs/handbook/project-references.html) are supported.
7
+ */
8
+ /**
9
+ * @typedef {ParserOptions["project"] | TypeScriptProjectServiceOptions} TypeScriptProjectOptions
10
+ */
1
11
  /**
2
12
  * @typedef {Object} HaltcaseStyleOptions
3
13
  * @property {boolean} [browser] Whether to include browser rules and globals.
@@ -5,10 +15,8 @@
5
15
  * @property {boolean} [nextjs] Whether to include Next.js rules (implies `react`).
6
16
  * @property {boolean} [node] Whether to include Node.js rules.
7
17
  * @property {boolean} [react] Whether to include React rules.
8
- * @property {ParserOptions["project"]} [typescriptProject = true] Custom TypeScript project options for the `typescript-eslint` parser.
9
- * // use when VS Code supports `projectService`
10
- * // https://github.com/microsoft/vscode-eslint/issues/1911
11
- * property {ProjectServiceOptions} [typescriptProjectServiceOptions = true] Custom TypeScript project service options for the `typescript-eslint` parser.
18
+ * @property {TypeScriptProjectOptions} [typescriptProject] Custom TypeScript project options for
19
+ * the `typescript-eslint` parser and `eslint-import-resolver-typescript`.
12
20
  */
13
21
  /**
14
22
  * @typedef {(options?: HaltcaseStyleOptions) => Awaited<import("typescript-eslint").Config>} HaltcaseStyleCreator
@@ -19,6 +27,19 @@
19
27
  * @type {HaltcaseStyleCreator}
20
28
  */
21
29
  export const getEslintBaseConfig: HaltcaseStyleCreator;
30
+ export type TypeScriptProjectServiceOptions = {
31
+ /**
32
+ * Use the TypeScript ESLint [project service](https://typescript-eslint.io/packages/parser#projectservice).
33
+ */
34
+ projectService: true;
35
+ /**
36
+ * Paths to tsconfig.json files for resolving and linting imports.
37
+ * This defaults to `<root>/tsconfig.json` or `<root>/jsconfig.json` and
38
+ * [project references](https://www.typescriptlang.org/docs/handbook/project-references.html) are supported.
39
+ */
40
+ tsconfigPaths?: string | string[] | undefined;
41
+ };
42
+ export type TypeScriptProjectOptions = ParserOptions["project"] | TypeScriptProjectServiceOptions;
22
43
  export type HaltcaseStyleOptions = {
23
44
  /**
24
45
  * Whether to include browser rules and globals.
@@ -41,12 +62,10 @@ export type HaltcaseStyleOptions = {
41
62
  */
42
63
  react?: boolean | undefined;
43
64
  /**
44
- * Custom TypeScript project options for the `typescript-eslint` parser.
45
- * // use when VS Code supports `projectService`
46
- * // https://github.com/microsoft/vscode-eslint/issues/1911
47
- * property {ProjectServiceOptions} [typescriptProjectServiceOptions = true] Custom TypeScript project service options for the `typescript-eslint` parser.
65
+ * Custom TypeScript project options for
66
+ * the `typescript-eslint` parser and `eslint-import-resolver-typescript`.
48
67
  */
49
- typescriptProject?: ParserOptions["project"];
68
+ typescriptProject?: TypeScriptProjectOptions;
50
69
  };
51
70
  export type HaltcaseStyleCreator = (options?: HaltcaseStyleOptions) => Awaited<import("typescript-eslint").Config>;
52
71
  import type { ParserOptions } from "@typescript-eslint/types";
@@ -0,0 +1,6 @@
1
+ export function prepareTypeScriptProjectConfig(projectInput: import("../base").TypeScriptProjectOptions): TypeScriptProjectConfig;
2
+ export type TypeScriptProjectConfig = {
3
+ parserOptions: import("@typescript-eslint/types").ParserOptions;
4
+ resolverOptions: TypeScriptResolverOptions;
5
+ };
6
+ import type { TypeScriptResolverOptions } from "eslint-import-resolver-typescript";
@@ -1,11 +1,12 @@
1
1
  /**
2
- * @import { ParserOptions } from "@typescript-eslint/types"
2
+ * @import { type ParserOptions } from "@typescript-eslint/types"
3
3
  */
4
4
 
5
5
  import babelParser from "@babel/eslint-parser";
6
6
  import eslint from "@eslint/js";
7
7
  import eslintPluginEslintComments from "@eslint-community/eslint-plugin-eslint-comments";
8
8
  import eslintConfigPrettier from "eslint-config-prettier";
9
+ import { createTypeScriptImportResolver } from "eslint-import-resolver-typescript";
9
10
  import * as eslintPluginImportX from "eslint-plugin-import-x";
10
11
  import eslintRegexp from "eslint-plugin-regexp";
11
12
  import { config } from "typescript-eslint";
@@ -27,6 +28,19 @@ import { getEslintCommonJsConfigInternal } from "./commonjs.js";
27
28
  import { eslintEs2015Config } from "./es2015.js";
28
29
  import { eslintSimpleImportSortConfig } from "./simple-import-sort.js";
29
30
  import { eslintUnicornConfig } from "./unicorn.js";
31
+ import { prepareTypeScriptProjectConfig } from "./utils/typescript.js";
32
+
33
+ /**
34
+ * @typedef {Object} TypeScriptProjectServiceOptions
35
+ * @property {true} projectService Use the TypeScript ESLint [project service](https://typescript-eslint.io/packages/parser#projectservice).
36
+ * @property {string | string[] | undefined} [tsconfigPaths] Paths to tsconfig.json files for resolving and linting imports.
37
+ * This defaults to `<root>/tsconfig.json` or `<root>/jsconfig.json` and
38
+ * [project references](https://www.typescriptlang.org/docs/handbook/project-references.html) are supported.
39
+ */
40
+
41
+ /**
42
+ * @typedef {ParserOptions["project"] | TypeScriptProjectServiceOptions} TypeScriptProjectOptions
43
+ */
30
44
 
31
45
  /**
32
46
  * @typedef {Object} HaltcaseStyleOptions
@@ -35,7 +49,11 @@ import { eslintUnicornConfig } from "./unicorn.js";
35
49
  * @property {boolean} [nextjs] Whether to include Next.js rules (implies `react`).
36
50
  * @property {boolean} [node] Whether to include Node.js rules.
37
51
  * @property {boolean} [react] Whether to include React rules.
38
- * @property {ParserOptions["project"]} [typescriptProject = true] Custom TypeScript project options for the `typescript-eslint` parser.
52
+ * @property {TypeScriptProjectOptions} [typescriptProject] Custom TypeScript project options for
53
+ * the `typescript-eslint` parser and `eslint-import-resolver-typescript`.
54
+ */
55
+
56
+ /*
39
57
  * // use when VS Code supports `projectService`
40
58
  * // https://github.com/microsoft/vscode-eslint/issues/1911
41
59
  * property {ProjectServiceOptions} [typescriptProjectServiceOptions = true] Custom TypeScript project service options for the `typescript-eslint` parser.
@@ -50,8 +68,12 @@ import { eslintUnicornConfig } from "./unicorn.js";
50
68
  *
51
69
  * @type {HaltcaseStyleCreator}
52
70
  */
53
- export const getEslintBaseConfig = (options = {}) =>
54
- config(
71
+ export const getEslintBaseConfig = (options = {}) => {
72
+ const { resolverOptions } = prepareTypeScriptProjectConfig(
73
+ options.typescriptProject
74
+ );
75
+
76
+ return config(
55
77
  {
56
78
  name: "import-x/recommended",
57
79
  plugins: {
@@ -64,10 +86,13 @@ export const getEslintBaseConfig = (options = {}) =>
64
86
  "import-x/parsers": {
65
87
  "@typescript-eslint/parser": [".ts"]
66
88
  },
67
- "import-x/resolver": {
68
- typescript: true,
69
- node: true
70
- }
89
+ "import-x/resolver-next": [
90
+ createTypeScriptImportResolver({
91
+ ...resolverOptions
92
+ }),
93
+
94
+ eslintPluginImportX.createNodeResolver()
95
+ ]
71
96
  }
72
97
  },
73
98
 
@@ -176,3 +201,4 @@ export const getEslintBaseConfig = (options = {}) =>
176
201
 
177
202
  ...getEslintCommonJsConfigInternal(options)
178
203
  );
204
+ };
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @import { type TypeScriptResolverOptions } from "eslint-import-resolver-typescript"
3
+ */
4
+
5
+ /**
6
+ * @typedef {Object} TypeScriptProjectConfig
7
+ * @property {import("@typescript-eslint/types").ParserOptions} parserOptions
8
+ * @property {TypeScriptResolverOptions} resolverOptions
9
+ */
10
+
11
+ /**
12
+ * @param {import("../base").TypeScriptProjectOptions} projectInput
13
+ * @returns {TypeScriptProjectConfig}
14
+ */
15
+ export const prepareTypeScriptProjectConfig = (projectInput) => {
16
+ // eslint-disable-next-line unicorn/prefer-default-parameters -- default parameters don't handle `null`
17
+ const project = projectInput ?? true;
18
+
19
+ if (typeof project === "string" || Array.isArray(project)) {
20
+ return {
21
+ parserOptions: {
22
+ project
23
+ },
24
+ resolverOptions: {
25
+ project
26
+ }
27
+ };
28
+ }
29
+
30
+ if (typeof project === "object" && project !== null) {
31
+ return {
32
+ parserOptions: {
33
+ projectService: project.projectService
34
+ },
35
+ resolverOptions: {
36
+ project: project.tsconfigPaths
37
+ }
38
+ };
39
+ }
40
+
41
+ if (typeof project !== "boolean") {
42
+ throw new TypeError(
43
+ "Invariant violation: expected project to be a boolean"
44
+ );
45
+ }
46
+
47
+ return {
48
+ parserOptions: {
49
+ project
50
+ },
51
+ resolverOptions: {}
52
+ };
53
+ };
@@ -1,4 +1,5 @@
1
1
  import eslintConfigPrettier from "eslint-config-prettier";
2
+ import { createTypeScriptImportResolver } from "eslint-import-resolver-typescript";
2
3
  import * as eslintPluginImportX from "eslint-plugin-import-x";
3
4
  import { config, configs, parser, plugin } from "typescript-eslint";
4
5
 
@@ -8,6 +9,7 @@ import { typescriptImportRules } from "../rules/typescript/import.js";
8
9
  import { typescriptBaseRules } from "../rules/typescript/index.js";
9
10
  import { getTypescriptNamingConventionRule } from "../rules/typescript/naming-convention.js";
10
11
  import { eslintTsdocConfig } from "./internal/tsdoc.js";
12
+ import { prepareTypeScriptProjectConfig } from "./internal/utils/typescript.js";
11
13
 
12
14
  /**
13
15
  * @type {import("./internal/base.js").HaltcaseStyleCreator}
@@ -19,6 +21,10 @@ export const getEslintTypescriptConfig = (options = {}) =>
19
21
  * @type {(options?: import("./internal/base.js").HaltcaseStyleOptions & {internal?: boolean}) => Awaited<import("typescript-eslint").Config>}
20
22
  */
21
23
  export const getEslintTypescriptConfigInternal = (options = {}) => {
24
+ const { parserOptions, resolverOptions } = prepareTypeScriptProjectConfig(
25
+ options.typescriptProject
26
+ );
27
+
22
28
  /** @type {import("typescript-eslint").ConfigWithExtends["languageOptions"]} */
23
29
  const languageOptions = {
24
30
  parser,
@@ -29,10 +35,7 @@ export const getEslintTypescriptConfigInternal = (options = {}) => {
29
35
  },
30
36
  // https://github.com/typescript-eslint/typescript-eslint/issues/3788#issuecomment-905094436
31
37
  jsxPragma: null,
32
- project: options.typescriptProject ?? true
33
- // use `projectService` when VS Code supports it properly
34
- // https://github.com/microsoft/vscode-eslint/issues/1911
35
- // projectService: options.typescriptProjectServiceOptions ?? true
38
+ ...parserOptions
36
39
  }
37
40
  };
38
41
 
@@ -72,9 +75,11 @@ export const getEslintTypescriptConfigInternal = (options = {}) => {
72
75
  },
73
76
 
74
77
  settings: {
75
- "import-x/resolver": {
76
- typescript: true
77
- }
78
+ "import-x/resolver-next": [
79
+ createTypeScriptImportResolver({
80
+ ...resolverOptions
81
+ })
82
+ ]
78
83
  }
79
84
  },
80
85
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@haltcase/style",
3
- "version": "8.0.0-canary.1",
3
+ "version": "8.0.0-canary.3",
4
4
  "description": "haltcase's web ecosystem style guide & configurations",
5
5
  "keywords": [
6
6
  "eslint",
@@ -90,10 +90,10 @@
90
90
  "@eslint-community/eslint-plugin-eslint-comments": "^4.4.1",
91
91
  "@eslint-react/eslint-plugin": "^1.26.2",
92
92
  "@next/eslint-plugin-next": "^15.1.7",
93
- "@stylistic/eslint-plugin-jsx": "^3.1.0",
93
+ "@stylistic/eslint-plugin-jsx": "^4.2.0",
94
94
  "eslint-config-prettier": "^10.0.1",
95
95
  "eslint-import-resolver-alias": "^1.1.2",
96
- "eslint-import-resolver-typescript": "^3.8.0",
96
+ "eslint-import-resolver-typescript": "^4.3.4",
97
97
  "eslint-plugin-import-x": "^4.6.1",
98
98
  "eslint-plugin-jsx-a11y": "^6.10.2",
99
99
  "eslint-plugin-playwright": "^2.2.0",
@@ -129,7 +129,7 @@
129
129
  "@typescript-eslint/types": "^8.24.0",
130
130
  "eslint": "^9.20.1",
131
131
  "eslint-define-config": "^2.1.0",
132
- "globals": "^15.15.0",
132
+ "globals": "^16.0.0",
133
133
  "husky": "^9.1.7",
134
134
  "lint-staged": "^15.4.3",
135
135
  "prettier": "^3.5.1",
package/readme.md CHANGED
@@ -186,6 +186,47 @@ export default [
186
186
  ];
187
187
  ```
188
188
 
189
+ You can also enable TypeScript ESLint's
190
+ [`projectService`](https://typescript-eslint.io/packages/parser#projectservice):
191
+
192
+ ```js
193
+ import { getEslintConfig } from "@haltcase/style/eslint";
194
+
195
+ export default [
196
+ ...getEslintConfig({
197
+ typescriptProject: {
198
+ projectService: true
199
+ }
200
+ })
201
+ ];
202
+ ```
203
+
204
+ Because `eslint-import-resolver-typescript` [does not support
205
+ `projectService`](https://github.com/import-js/eslint-import-resolver-typescript/issues/282),
206
+ you should either:
207
+
208
+ 1. Have a single `tsconfig.json` file in your root directory, including [project
209
+ references](https://www.typescriptlang.org/docs/handbook/project-references.html)
210
+ if necessary.
211
+
212
+ 2. Explicitly pass your `tsconfig.json` paths:
213
+
214
+ ```js
215
+ import { getEslintConfig } from "@haltcase/style/eslint";
216
+
217
+ export default [
218
+ ...getEslintConfig({
219
+ typescriptProject: {
220
+ projectService: true,
221
+ tsconfigPaths: [
222
+ "./packages/**/tsconfig.json",
223
+ "./separate-package/tsconfig.json"
224
+ ]
225
+ }
226
+ })
227
+ ];
228
+ ```
229
+
189
230
  If you need to further customize the TypeScript behavior, use a separate config
190
231
  with your own options, for example:
191
232