@open-xchange/linter-presets 0.3.1 → 0.3.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.2] - 2024-08-01
4
+
5
+ - added: [ESLint] restore environment `env.tsconfig` to workaround VSCode issues
6
+
3
7
  ## [0.3.1] - 2024-08-01
4
8
 
5
9
  - added: [ESLint] default ignore globs (`dist`, `gitlab-ci`, and others)
@@ -0,0 +1,21 @@
1
+ import type { TSESLint } from "@typescript-eslint/utils";
2
+ import type { EnvBaseOptions } from "../shared/env-utils.js";
3
+ /**
4
+ * Configuration options for the environment preset "env.tsconfig".
5
+ */
6
+ export interface EnvTSConfigOptions extends EnvBaseOptions {
7
+ /**
8
+ * The path to the TypeScript project configuration file (`tsconfig.json`).
9
+ */
10
+ project: string;
11
+ }
12
+ /**
13
+ * Creates configuration objects for TypeScript projects.
14
+ *
15
+ * @param envOptions
16
+ * Configuration options for the environment.
17
+ *
18
+ * @returns
19
+ * An array of configuration objects to be added to the flat configuration.
20
+ */
21
+ export default function tsconfig(envOptions: EnvTSConfigOptions): TSESLint.FlatConfig.ConfigArray;
@@ -0,0 +1,24 @@
1
+ import { concatConfigs, createConfig, customRules } from "../shared/env-utils.js";
2
+ // functions ==================================================================
3
+ /**
4
+ * Creates configuration objects for TypeScript projects.
5
+ *
6
+ * @param envOptions
7
+ * Configuration options for the environment.
8
+ *
9
+ * @returns
10
+ * An array of configuration objects to be added to the flat configuration.
11
+ */
12
+ export default function tsconfig(envOptions) {
13
+ return concatConfigs(
14
+ // path to project configuration file
15
+ createConfig(envOptions, {
16
+ languageOptions: {
17
+ parserOptions: {
18
+ project: envOptions.project,
19
+ },
20
+ },
21
+ }),
22
+ // custom rules
23
+ customRules(envOptions));
24
+ }
@@ -8,6 +8,7 @@ import codecept from "./env/codecept.js";
8
8
  import react from "./env/react.js";
9
9
  import project from "./env/project.js";
10
10
  import eslint from "./env/eslint.js";
11
+ import tsconfig from "./env/tsconfig.js";
11
12
  /**
12
13
  * Configuration options for linting the entire project with ESLint.
13
14
  */
@@ -47,6 +48,7 @@ export declare const env: {
47
48
  react: typeof react;
48
49
  project: typeof project;
49
50
  eslint: typeof eslint;
51
+ tsconfig: typeof tsconfig;
50
52
  };
51
53
  /**
52
54
  * Generates ESLint configuration objects targeting the source files in the
@@ -17,6 +17,7 @@ import codecept from "./env/codecept.js";
17
17
  import react from "./env/react.js";
18
18
  import project from "./env/project.js";
19
19
  import eslint from "./env/eslint.js";
20
+ import tsconfig from "./env/tsconfig.js";
20
21
  // environment presets ========================================================
21
22
  /**
22
23
  * A collection with all available environment presets.
@@ -30,6 +31,7 @@ export const env = {
30
31
  react,
31
32
  project,
32
33
  eslint,
34
+ tsconfig,
33
35
  };
34
36
  // functions ==================================================================
35
37
  /**
@@ -65,10 +65,10 @@ const resolve = utils.resolver(import.meta.url)
65
65
 
66
66
  export default [
67
67
  ...eslint.configure({
68
- ignores: ["dist/*", "external/**/*.yaml"],
68
+ ignores: ["external/**/*.yaml"],
69
69
  language: { ecmaVersion: 2024, sourceType: "commonjs" },
70
70
  license: resolve("./license.txt"),
71
- stylistic: { quotes: "double", semi: "always" },
71
+ stylistic: { quotes: "single", semi: "never" },
72
72
  }),
73
73
  ]
74
74
  ```
@@ -91,3 +91,4 @@ The names of the environment presets are linked to detailed descriptions.
91
91
  | [`env.codecept`](./env/codecept.md) | E2E tests with [CodeceptJS](https://codecept.io/). |
92
92
  | [`env.eslint`](./env/eslint.md) | Implementation of custom ESLint rules. |
93
93
  | [`env.project`](./env/project.md) | Project setup and module imports. |
94
+ | [`env.tsconfig`](./env/tsconfig.md) | TypeScript project setup (per `tsconfig.json` file). Provided in case VSCode fails to use the new project service correctly. |
@@ -0,0 +1,36 @@
1
+ # Environment `env.tsconfig`
2
+
3
+ Creates configuration objects for TypeScript projects (registers a `tsconfig.json` file in the project).
4
+
5
+ Usually, this environment preset should not be necessary, as the new [project service](https://typescript-eslint.io/blog/announcing-typescript-eslint-v8#project-service) of `typescript-eslint` is enabled by default. However, the ESLint plugin of VSCode sometimes fails to lint files in certain subdirectories and complains about the project service not covering the file to be linted. In these cases, manually setting up this environment preset will help.
6
+
7
+ ## Signature
8
+
9
+ ```ts
10
+ function tsconfig(options: EnvTSConfigOptions): Linter.FlatConfig[]
11
+ ```
12
+
13
+ ## Options
14
+
15
+ | Name | Type | Default | Description |
16
+ | - | - | - | - |
17
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
18
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
19
+ | `project` | `string` | _required_ | The absolute path to the TypeScript project configuration file (`tsconfig.json`). |
20
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
21
+
22
+ ## Example
23
+
24
+ ```js
25
+ // eslint.config.js
26
+ import { utils, eslint } from "@open-xchange/linter-presets"
27
+
28
+ const resolve = utils.resolver(import.meta.url)
29
+
30
+ export default [
31
+ ...eslint.configure({ /* ... */ }),
32
+ ...eslint.env.tsconfig({
33
+ files: ["src/**/*.ts"],
34
+ project: resolve("src/tsconfig.json"),
35
+ }),
36
+ ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/linter-presets",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Configuration presets for ESLint and StyleLint",
5
5
  "repository": {
6
6
  "url": "https://gitlab.open-xchange.com/fspd/npm-packages/linter-presets"