@open-xchange/linter-presets 0.3.0 → 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,14 @@
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
+
7
+ ## [0.3.1] - 2024-08-01
8
+
9
+ - added: [ESLint] default ignore globs (`dist`, `gitlab-ci`, and others)
10
+ - changed: [ESLint] default values of `stylistic` option (indent 4 spaces, always semicolons, double quotes)
11
+
3
12
  ## [0.3.0] - 2024-08-01
4
13
 
5
14
  - chore: [ESLint] [major bump of `typescript-eslint` to v8](https://typescript-eslint.io/blog/announcing-typescript-eslint-v8/)
@@ -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
  /**
@@ -43,6 +45,14 @@ export const env = {
43
45
  * An array of configuration objects to be added to the flat configuration.
44
46
  */
45
47
  export function configure(options) {
48
+ const ignores = [
49
+ "*/.yarn/*",
50
+ "dist/*",
51
+ "vite.config.ts.*.mjs",
52
+ "gitlab-ci/*",
53
+ ".gitlab-ci.yml",
54
+ ...(options?.ignores ?? []),
55
+ ];
46
56
  // resolve language configuration options
47
57
  const languageOptions = {
48
58
  ecmaVersion: 2022,
@@ -52,15 +62,15 @@ export function configure(options) {
52
62
  };
53
63
  // resolve stylistic configuration options
54
64
  const stylisticOptions = {
55
- indent: 2,
56
- semi: "never",
57
- quotes: "single",
65
+ indent: 4,
66
+ semi: "always",
67
+ quotes: "double",
58
68
  dangle: "always",
59
69
  ...options?.stylistic,
60
70
  };
61
71
  return [
62
72
  // ignore certain files and folders
63
- ...(options?.ignores?.length ? [{ ignores: options.ignores }] : []),
73
+ { ignores },
64
74
  // module types and standard rules for all JS/TS source files
65
75
  ...base(languageOptions),
66
76
  // default configuration for JavaScript files
@@ -32,19 +32,29 @@ function configure(options?: ConfigureOptions): Linter.FlatConfig[]
32
32
 
33
33
  | Name | Type | Default | Description |
34
34
  | - | - | - | - |
35
- | `ignores` | `string[]` | `[]` | Glob patterns with all files and folders to be ignored by ESLint. |
35
+ | `ignores` | `string[]` | `[]` | Glob patterns with all files and folders to be ignored by ESLint. This package already defines a few standard ignore globs (see below). |
36
36
  | `license` | `string` | `""` | Full path to the template file containing the license header to be used in all source files. |
37
37
  | `language` | `LanguageOptions` | | Configuration options for language and project setup. |
38
38
  | `language.ecmaVersion` | `number` | `2022` | The ECMAScript version to be used in the project (version or year). |
39
39
  | `language.sourceType` | `"module"\|"commonjs"` | `"module"` | Specifies how to treat `.js`, `.jsx`, `.ts`, and `.tsx` files. |
40
40
  | `language.nativeDecorators` | `boolean` | `false` | Whether to support native ES decorators in JavaScript code (via Babel plugin). Does not affect TypeScript code which uses an own parser aware of the decorator syntax. |
41
41
  | `stylistic` | `StylisticOptions` | | Configuration options for code style. |
42
- | `stylistic.indent` | `number` | `2` | Default indentation size (number of space characters). Will be applied to JavaScript, TypeScript, JSON, and YAML files, as well as JSX markup. |
43
- | `stylistic.semi` | `boolean` | `false` | Specifies whether to require semicolons following all statements (`true`), or to force to omit semicolons if possible according to ASI rules (`false`). |
44
- | `stylistic.quotes` | `"single"\|"double"\|"off"` | `"single"` | The type of the string delimiter character. |
42
+ | `stylistic.indent` | `number` | `4` | Default indentation size (number of space characters). Will be applied to JavaScript, TypeScript, JSON, and YAML files, as well as JSX markup. |
43
+ | `stylistic.semi` | `"always"\|"never"\|"off"` | `"always"` | Specifies whether to require semicolons following all statements (`"always"`), or to force to omit semicolons if possible according to ASI rules (`"never"`). |
44
+ | `stylistic.quotes` | `"single"\|"double"\|"off"` | `"double"` | The type of the string delimiter character. |
45
45
  | `stylistic.dangle` | `"always"\|"never"\|"off"` | `"always"` | Specifies how to treat dangling commas in multiline lists. |
46
46
  | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the global configuration. |
47
47
 
48
+ #### Built-in Ignore Globs
49
+
50
+ This package defines ignore globs for the following files and directories:
51
+
52
+ - `*/.yarn/*` (internal setup files of Yarn v2+)
53
+ - `dist/*` (standard build output directory)
54
+ - `vite.config.ts.*.mjs` (intermediate files of Vite dev server)
55
+ - `gitlab-ci/*` (GitLab CI configuration files)
56
+ - `.gitlab-ci.yml` (GitLab CI configuration files)
57
+
48
58
  #### `configure` Example
49
59
 
50
60
  ```js
@@ -55,10 +65,10 @@ const resolve = utils.resolver(import.meta.url)
55
65
 
56
66
  export default [
57
67
  ...eslint.configure({
58
- ignores: ["dist/*", "external/**/*.yaml"],
68
+ ignores: ["external/**/*.yaml"],
59
69
  language: { ecmaVersion: 2024, sourceType: "commonjs" },
60
70
  license: resolve("./license.txt"),
61
- stylistic: { quotes: "double", semi: "always" },
71
+ stylistic: { quotes: "single", semi: "never" },
62
72
  }),
63
73
  ]
64
74
  ```
@@ -81,3 +91,4 @@ The names of the environment presets are linked to detailed descriptions.
81
91
  | [`env.codecept`](./env/codecept.md) | E2E tests with [CodeceptJS](https://codecept.io/). |
82
92
  | [`env.eslint`](./env/eslint.md) | Implementation of custom ESLint rules. |
83
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.0",
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"
@@ -55,7 +55,7 @@
55
55
  "eslint-plugin-vitest": "0.5.4",
56
56
  "eslint-plugin-yml": "1.14.0",
57
57
  "find-up": "7.0.0",
58
- "globals": "15.8.0",
58
+ "globals": "15.9.0",
59
59
  "picomatch": "4.0.2",
60
60
  "stylelint-config-standard": "36.0.1",
61
61
  "stylelint-config-standard-less": "3.0.1",