@open-xchange/linter-presets 1.2.34 → 1.2.35

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
+ ## `1.2.35` – 2025-May-29
4
+
5
+ - chore: bump dependencies
6
+
3
7
  ## `1.2.34` – 2025-May-26
4
8
 
5
9
  - added: (ESLint) disable rule "no-unused-private-class-members" in declaration files
@@ -0,0 +1,103 @@
1
+ # ESLint Presets
2
+
3
+ The module `eslint` provides a `configure` function for project-wide ESLint configuration (e.g. TypeScript files, JSON files, license headers, etc.), and a set of environment presets that apply more ESLint plugins and rules to a specific subset of the project (e.g. browser code, unit test code, etc.).
4
+
5
+ ## Functions
6
+
7
+ ### Function `configure`
8
+
9
+ Generates standard configuration targeting the source files in the entire project. Internally, various ESLint plugins will be included and configured to use their recommended rule sets.
10
+
11
+ | Target | ESLint Plugin |
12
+ | - | - |
13
+ | JavaScript and TypeScript files (including `.jsx` and `.tsx`) | ESLint core rules |
14
+ | JavaScript files only (including `.jsx`) | ESLint core rules |
15
+ | TypeScript files with type-aware rules (including `.tsx`) | [typescript-eslint](https://typescript-eslint.io/) |
16
+ | [Vue.js](https://vuejs.org) files (`.vue`) | [eslint-plugin-vue](https://eslint.vuejs.org) |
17
+ | JSON files (`.json`) | [eslint-plugin-jsonc](https://ota-meshi.github.io/eslint-plugin-jsonc/) |
18
+ | YAML files (`.yaml`, `.yml`) | [eslint-plugin-yml](https://ota-meshi.github.io/eslint-plugin-yml/) |
19
+ | Markdown files (`.md`) | [@eslint/markdown](https://github.com/eslint/markdown) |
20
+ | License headers | [eslint-plugin-license-header](https://github.com/nikku/eslint-plugin-license-header) |
21
+ | ESLint inline directives | [@eslint-community/eslint-plugin-eslint-comments](https://github.com/eslint-community/eslint-plugin-eslint-comments) |
22
+ | Outdated dependencies | [eslint-plugin-depend](https://github.com/es-tooling/eslint-plugin-depend) |
23
+ | Native ES6 promises | [eslint-plugin-promise](https://github.com/eslint-community/eslint-plugin-promise) |
24
+ | JSDoc source documentation | [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) |
25
+ | Source code formatting | [@stylistic/eslint-plugin](https://eslint.style/packages/default) |
26
+
27
+ #### `configure` Signature
28
+
29
+ ```ts
30
+ function configure(options?: ConfigureOptions): Linter.Config[]
31
+ ```
32
+
33
+ #### `configure` Options
34
+
35
+ | Name | Type | Default | Description |
36
+ | - | - | - | - |
37
+ | `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). |
38
+ | `license` | `string` | `""` | Full path to the template file containing the license header to be used in all source files. |
39
+ | `language` | `LanguageOptions` | | Configuration options for language and project setup. |
40
+ | `language.ecmaVersion` | `number\|"latest"` | `latest` | The ECMAScript version to be used in the project (version or year). |
41
+ | `language.sourceType` | `"module"\|"commonjs"` | `"module"` | Specifies how to treat `.js`, `.jsx`, `.ts`, and `.tsx` files. |
42
+ | `packages` | `PackagesOptions` | | Configuration options for external package dependencies. |
43
+ | `packages.allowed` | `string[]` | `[]` | Banned packages to be allowed in the project. |
44
+ | `packages.banned` | `string[]` | `[]` | Additional packages to be banned in the project. |
45
+ | `stylistic` | `StylisticOptions` | | Configuration options for code style. |
46
+ | `stylistic.indent` | `IndentOptions` | `{}` | Indentation size (number of space characters) per file type. |
47
+ | `stylistic.indent.js` | `number` | `4` | JavaScript and TypeScript files (including `.jsx`, `.tsx`). |
48
+ | `stylistic.indent.json` | `number` | `4` | JSON files (`.json`). |
49
+ | `stylistic.indent.yaml` | `number` | `2` | YAML files (`.yaml`, `.yml`). |
50
+ | `stylistic.indent.vue` | `number` | `4` | Vue.js files (`.vue`). |
51
+ | `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"`). |
52
+ | `stylistic.quotes` | `"single"\|"double"\|"off"` | `"double"` | The type of the string delimiter character. |
53
+ | `stylistic.dangle` | `"always"\|"never"\|"off"` | `"always"` | Specifies how to treat dangling commas in multiline lists. |
54
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the global configuration. |
55
+
56
+ #### Built-in Ignore Globs
57
+
58
+ This package defines ignore globs for the following files and directories:
59
+
60
+ - `*/.yarn/*` (internal setup files of Yarn v2+)
61
+ - `dist/*` (standard build output directory)
62
+ - `vite.config.ts.*.mjs` (intermediate files of Vite dev server)
63
+ - `gitlab-ci/*` (GitLab CI configuration files)
64
+ - `.gitlab-ci.yml` (GitLab CI configuration files)
65
+
66
+ #### `configure` Example
67
+
68
+ ```js
69
+ // eslint.config.js
70
+ import { utils, eslint } from "@open-xchange/linter-presets"
71
+
72
+ const resolve = utils.resolver(import.meta.url)
73
+
74
+ export default [
75
+ ...eslint.configure({
76
+ ignores: ["external/**/*.yaml"],
77
+ language: { ecmaVersion: 2024, sourceType: "commonjs" },
78
+ license: resolve("./license.txt"),
79
+ stylistic: { quotes: "single", semi: "never" },
80
+ }),
81
+ ]
82
+ ```
83
+
84
+ ## Environment Presets
85
+
86
+ Environment presets will be applied to specific subsets of the project. Usually, they import one or more external ESLint plugins, apply their recommended rule set, and add or modify a few of their rules to establish the default setup for the project. All environment presets allow to pass rule records to override the recommended rules.
87
+
88
+ ### Overview
89
+
90
+ The names of the environment presets are linked to detailed descriptions.
91
+
92
+ | Name | Description |
93
+ | - | - |
94
+ | [`env.node`](./env/node.md) | Modules running in NodeJS. |
95
+ | [`env.browser`](./env/browser.md) | Modules running in browsers. |
96
+ | [`env.react`](./env/react.md) | Modules using [React](https://react.dev/). |
97
+ | [`env.jest`](./env/jest.md) | Unit tests with [Jest](https://jestjs.io/). |
98
+ | [`env.vitest`](./env/vitest.md) | Unit tests with [Vitest](https://vitest.dev/). |
99
+ | [`env.codecept`](./env/codecept.md) | E2E tests with [CodeceptJS](https://codecept.io/). |
100
+ | [`env.eslint`](./env/eslint.md) | Implementation of custom ESLint rules. |
101
+ | [`env.project`](./env/project.md) | Project setup and module imports. |
102
+ | [`env.tsconfig`](./env/tsconfig.md) | TypeScript project setup (per `tsconfig.json` file). Provided in case VSCode fails to use the new project service correctly. |
103
+ | [`env.decorators`](./env/decorators.md) | Support for native decorators in JavaScript source files. |
@@ -0,0 +1,84 @@
1
+ # Environment `env.browser`
2
+
3
+ Creates configuration objects with global symbols and linter rules for modules running in the browser. Adds well-known [browser globals](https://github.com/sindresorhus/globals), and forbids [confusing browser globals](https://github.com/facebook/create-react-app/tree/main/packages/confusing-browser-globals).
4
+
5
+ ## Signature
6
+
7
+ ```ts
8
+ function browser(options: EnvBrowserOptions): Linter.Config[]
9
+ ```
10
+
11
+ ## Options
12
+
13
+ | Name | Type | Default | Description |
14
+ | - | - | - | - |
15
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
16
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
17
+ | `restricted` | `EnvRestrictedOptions` | `{}` | Settings for banned globals, imports, object properties, and syntax constructs (see below). |
18
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
19
+
20
+ ### Option `restricted`
21
+
22
+ - Type: `EnvRestrictedOptions`
23
+ - Default: `{}`
24
+
25
+ This option allows to specify banned globals, imports, object properties, and syntax constructs. These restricted items will be set on top of the built-in restricted items of the environment preset, and will be passed to the ESLint core rules [`no-restricted-globals`](https://eslint.org/docs/latest/rules/no-restricted-globals), [`no-restricted-imports`](https://eslint.org/docs/latest/rules/no-restricted-imports), [`no-restricted-properties`](https://eslint.org/docs/latest/rules/no-restricted-properties), and [`no-restricted-syntax`](https://eslint.org/docs/latest/rules/no-restricted-syntax), respectively.
26
+
27
+ The option `restricted` is an object with the following properties:
28
+
29
+ | Name | Type | Default | Description |
30
+ | - | - | - | - |
31
+ | `globals` | `EnvRestrictedName[]` | `[]` | Banned global symbols. Each entry is an object with string properties `name` and `message`. |
32
+ | `imports` | `EnvRestrictedName[]` | `[]` | Banned modules that must not be imported. Each entry is an object with string properties `name` and `message`. |
33
+ | `properties` | `EnvRestrictedProperty[]` | `[]` | Banned object properties. Each entry is an object with string properties `object`, `property`, and `message`). |
34
+ | `syntax` | `EnvRestrictedSyntax[]` | `[]` | Banned syntax constructs by [AST selectors](https://eslint.org/docs/latest/extend/selectors). Each entry is an object with string properties `selector` and `message`. |
35
+ | `overrides` | `EnvRestrictedOverride[]` | `[]` | Overrides for specific subsets of files in the environment. Each entry is an object with the common properties `files` (required) and `ignores`, and the properties `globals`, `imports`, `properties`, and `syntax` to specify restricted items (see above). All restricted items of overrides will be merged with the common restricted items defined for the entire environment. |
36
+
37
+ The environment `env.browser` already defines the following built-in restrictions:
38
+
39
+ | Type | Name | Description |
40
+ | - | - | - |
41
+ | Globals | [`isFinite`](https://devdocs.io/javascript/global_objects/isfinite) | Use [`Number.isFinite`](https://devdocs.io/javascript/global_objects/number/isfinite) instead. |
42
+ | | [`isNaN`](https://devdocs.io/javascript/global_objects/isnan) | Use [`Number.isNaN`](https://devdocs.io/javascript/global_objects/number/isnan) instead. |
43
+ | | [Confusing browser globals](https://github.com/facebook/create-react-app/tree/main/packages/confusing-browser-globals) | Globals such as `name` and `event` should not be used to catch typos in function parameters etc. |
44
+ | Syntax | TypeScript `public` class field modifier | Can be omitted (except for constructors of classes deriving from a class with protected constructor). |
45
+ | | TypeScript `private` class field modifier | Use native `#private` class fields. |
46
+ | | [TypeScript parameter properties](https://www.typescriptlang.org/docs/handbook/2/classes.html#parameter-properties) | Use explicit class properties. |
47
+ | | Module exports of [TypeScript const enumerations](https://devdocs.io/typescript~5.1/enums#enums-at-compile-time) | Not compatible with bundlers running in isolated modules mode (ESBuild). |
48
+
49
+ ## Example
50
+
51
+ ```js
52
+ // eslint.config.js
53
+ import { eslint } from "@open-xchange/linter-presets"
54
+
55
+ export default [
56
+ ...eslint.configure({ /* ... */ }),
57
+ ...eslint.env.browser({
58
+ files: ["src/**/*.{js,ts}"],
59
+ restricted: {
60
+ globals: [
61
+ { name: "$", message: "Explicitly import the 'jquery' package." },
62
+ ],
63
+ imports: [
64
+ { name: "underscore", message: "Use the 'lodash' package." },
65
+ ],
66
+ properties: [
67
+ { object: "_", property: "flatten", message: "Use native 'Array::flat' instead." },
68
+ ],
69
+ syntax: [
70
+ { selector: "ClassBody > StaticBlock", message: "Static blocks not supported in all browsers." },
71
+ ],
72
+ overrides: [
73
+ {
74
+ files: "src/**/*.ts",
75
+ properties: [
76
+ { object: "$", property: "Deferred", message: "Use native promises in TypeScript code." },
77
+ ],
78
+ },
79
+ ],
80
+ },
81
+ rules: { /* ... */ },
82
+ }),
83
+ ]
84
+ ```
@@ -0,0 +1,35 @@
1
+ # Environment `env.codecept`
2
+
3
+ Creates configuration objects with global symbols and linter rules for E2E tests using CodeceptJS. Adds the following plugins and their recommended rules:
4
+
5
+ - [eslint-plugin-codeceptjs](https://github.com/poenneby/eslint-plugin-codeceptjs)
6
+ - [eslint-plugin-chai-expect](https://github.com/turbo87/eslint-plugin-chai-expect)
7
+
8
+ ## Signature
9
+
10
+ ```ts
11
+ function codecept(options: EnvCodeceptOptions): Linter.Config[]
12
+ ```
13
+
14
+ ## Options
15
+
16
+ | Name | Type | Default | Description |
17
+ | - | - | - | - |
18
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
19
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
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 { eslint } from "@open-xchange/linter-presets"
27
+
28
+ export default [
29
+ ...eslint.configure({ /* ... */ }),
30
+ ...eslint.env.codecept({
31
+ files: ["e2e/**/*.{js,ts}"],
32
+ rules: { /* ... */ },
33
+ }),
34
+ ]
35
+ ```
@@ -0,0 +1,37 @@
1
+ # Environment `env.decorators`
2
+
3
+ Creates configuration objects to add support for native decorators to JavaScript source files.
4
+ Does not affect TypeScript source files which use an own parser aware of the decorator syntax.
5
+
6
+ Adds the following plugins:
7
+
8
+ - [@babel/eslint-parser](https://www.npmjs.com/package/@babel/eslint-parser)
9
+ - [@babel/plugin-proposal-decorators](https://babeljs.io/docs/babel-plugin-proposal-decorators)
10
+
11
+ ## Signature
12
+
13
+ ```ts
14
+ function decorators(options: EnvDecoratorsOptions): Linter.Config[]
15
+ ```
16
+
17
+ ## Options
18
+
19
+ | Name | Type | Default | Description |
20
+ | - | - | - | - |
21
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
22
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
23
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
24
+
25
+ ## Example
26
+
27
+ ```js
28
+ // eslint.config.js
29
+ import { eslint } from "@open-xchange/linter-presets"
30
+
31
+ export default [
32
+ ...eslint.configure({ /* ... */ }),
33
+ ...eslint.env.decorators({
34
+ files: ["src/**/*.js"],
35
+ }),
36
+ ]
37
+ ```
@@ -0,0 +1,32 @@
1
+ # Environment `env.eslint`
2
+
3
+ Creates configuration objects with linter rules for implementing custom ESlint plugins. Adds the plugin [eslint-plugin-eslint-plugin](https://github.com/eslint-community/eslint-plugin-eslint-plugin) and its recommended rules.
4
+
5
+ ## Signature
6
+
7
+ ```ts
8
+ function plugin(options: EnvEslintOptions): Linter.Config[]
9
+ ```
10
+
11
+ ## Options
12
+
13
+ | Name | Type | Default | Description |
14
+ | - | - | - | - |
15
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
16
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
17
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
18
+
19
+ ## Example
20
+
21
+ ```js
22
+ // eslint.config.js
23
+ import { eslint } from "@open-xchange/linter-presets"
24
+
25
+ export default [
26
+ ...eslint.configure({ /* ... */ }),
27
+ ...eslint.env.eslint({
28
+ files: ["eslint/rules/*.{js,ts}"],
29
+ rules: { /* ... */ },
30
+ }),
31
+ ]
32
+ ```
@@ -0,0 +1,41 @@
1
+ # Environment `env.jest`
2
+
3
+ Creates configuration objects with global symbols and linter rules for unit tests using Jest. Adds the following plugins and their recommended rules:
4
+
5
+ - [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest)
6
+ - [eslint-plugin-jest-extended](https://github.com/jest-community/eslint-plugin-jest-extended) (optional)
7
+ - [eslint-plugin-jest-dom](https://github.com/testing-library/eslint-plugin-jest-dom) (optional)
8
+ - [eslint-plugin-testing-library](https://github.com/testing-library/eslint-plugin-testing-library) (optional)
9
+
10
+ ## Signature
11
+
12
+ ```ts
13
+ function jest(options: EnvJestOptions): Linter.Config[]
14
+ ```
15
+
16
+ ## Options
17
+
18
+ | Name | Type | Default | Description |
19
+ | - | - | - | - |
20
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
21
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
22
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
23
+ | `jestExtended` | `boolean` | `false` | Activate plugin `eslint-plugin-jest-extended`. |
24
+ | `jestDom` | `boolean` | `false` | Activate plugin `eslint-plugin-jest-dom`. |
25
+ | `testingLib` | `"angular"\|"dom"\|"marko"\|"react"\|"vue"` | _none_ | Activate plugin `eslint-plugin-testing-library` for the specified environment. |
26
+
27
+ ## Example
28
+
29
+ ```js
30
+ // eslint.config.js
31
+ import { eslint } from "@open-xchange/linter-presets"
32
+
33
+ export default [
34
+ ...eslint.configure({ /* ... */ }),
35
+ ...eslint.env.jest({
36
+ files: ["test/**/*.{js,ts}"],
37
+ testingLib: "react",
38
+ rules: { /* ... */ },
39
+ }),
40
+ ]
41
+ ```
@@ -0,0 +1,51 @@
1
+ # Environment `env.node`
2
+
3
+ Creates configuration objects with global symbols and linter rules for NodeJS modules. Adds the plugin [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) and its recommended rules.
4
+
5
+ ## Signature
6
+
7
+ ```ts
8
+ function node(options: EnvNodeOptions): Linter.Config[]
9
+ ```
10
+
11
+ ## Options
12
+
13
+ | Name | Type | Default | Description |
14
+ | - | - | - | - |
15
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
16
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
17
+ | `sourceType` | `"module"\|"commonjs"` | `"module"` | Specifies how to treat `.js`, `.jsx`, `.ts`, and `.tsx`. |
18
+ | `restricted` | `EnvRestrictedOptions` | `{}` | Settings for banned globals, imports, object properties, and syntax constructs (see below). |
19
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
20
+
21
+ ### Option `restricted`
22
+
23
+ - Type: `EnvRestrictedOptions`
24
+ - Default: `{}`
25
+
26
+ This option allows to specify banned globals, imports, object properties, and syntax constructs. See [documentation in `env.browser`](./browser.md#option-restricted) for a detailed description.
27
+
28
+ The environment `env.node` already defines the following built-in restrictions:
29
+
30
+ | Type | Name | Description |
31
+ | - | - | - |
32
+ | Globals | [`isFinite`](https://devdocs.io/javascript/global_objects/isfinite) | Use [`Number.isFinite`](https://devdocs.io/javascript/global_objects/number/isfinite) instead. |
33
+ | | [`isNaN`](https://devdocs.io/javascript/global_objects/isnan) | Use [`Number.isNaN`](https://devdocs.io/javascript/global_objects/number/isnan) instead. |
34
+ | Syntax | TypeScript `public` class field modifier | Can be omitted (except for constructors of classes deriving from a class with protected constructor). |
35
+ | | TypeScript `private` class field modifier | Use native `#private` class fields. |
36
+ | | [TypeScript parameter properties](https://www.typescriptlang.org/docs/handbook/2/classes.html#parameter-properties) | Use explicit class properties. |
37
+
38
+ ## Example
39
+
40
+ ```js
41
+ // eslint.config.js
42
+ import { utils, eslint } from "@open-xchange/linter-presets"
43
+
44
+ export default [
45
+ ...eslint.configure({ /* ... */ }),
46
+ ...eslint.env.node({
47
+ files: ["*.config.{js,ts}", "scripts/**/*.js"],
48
+ rules: { /* ... */ },
49
+ }),
50
+ ]
51
+ ```
@@ -0,0 +1,129 @@
1
+ # Environment `env.project`
2
+
3
+ Creates configuration objects for custom project setup and module imports.
4
+
5
+ - Source files will be checked for the correct usage of ES modules with static `import` and `export` statements, as well as dynamic `import` expressions. For the latter, only literal strings will be checked, other expressions that build the imported module names dynamically cannot be checked.
6
+
7
+ - Enforces an hierarchy of internal packages. If a project distributes its source files into multiple installation packages, the dependencies between these packages can be checked to prevent that files from a base package import files from a dependent package (which may not get installed on the target machine).
8
+
9
+ - Bans the TypeScript compiler directive `<amd-module>`. This directive was used in the past to declare module names when transpiling TypeScript module code to AMD modules.
10
+
11
+ ## Signature
12
+
13
+ ```ts
14
+ function project(options: EnvProjectOptions): Linter.Config[]
15
+ ```
16
+
17
+ ## Options
18
+
19
+ | Name | Type | Default | Description |
20
+ | - | - | - | - |
21
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
22
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
23
+ | `alias` | `Record<string, string>` | `{}` | Maps all alias prefixes to actual paths in the project (see below). |
24
+ | `external` | `string \| string[]` | `[]` | Specifies glob patterns for external modules (see below). |
25
+ | `hierarchy` | `Record<string, RuleNoInvalidHierarchyPackage>` | `{}` | Allows to separate the source files into virtual packages (see below). |
26
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
27
+
28
+ ### Option `alias`
29
+
30
+ - Type: `Record<string, string>`
31
+ - Default: `{}`
32
+
33
+ Maps all alias prefixes to actual paths in the project. All paths must be relative to the project's root directory.
34
+
35
+ #### `alias` Example
36
+
37
+ ```js
38
+ // eslint.config.js
39
+ import { eslint } from "@open-xchange/linter-presets"
40
+
41
+ export default [
42
+ ...eslint.configure({ /* ... */ }),
43
+ ...eslint.env.project({
44
+ files: ["src/**/*.{js,ts}"],
45
+ alias: {
46
+ "@": "src",
47
+ },
48
+ }),
49
+ ]
50
+ ```
51
+
52
+ - The alias prefix `"@/"` of a module name will be replaced with the path `src/` to check the existence of source files.
53
+ - The module `"@/my/module"` will correspond to the file `src/my/module.js` (relative to the project's root directory).
54
+
55
+ ### Option `external`
56
+
57
+ - Type: `string[]`
58
+ - Default: `[]`
59
+
60
+ Specifies glob patterns for modules that can be imported although there is no module file available, e.g. due to build tool configuration.
61
+
62
+ #### `external` Example
63
+
64
+ ```js
65
+ // eslint.config.js
66
+ import { eslint } from "@open-xchange/linter-presets"
67
+
68
+ export default [
69
+ ...eslint.configure({ /* ... */ }),
70
+ ...eslint.env.project({
71
+ files: ["src/**/*.{js,ts}"],
72
+ alias: { "@": "src" },
73
+ external: ["virtual:*", "@/special/lib/**/*.js"],
74
+ }),
75
+ ]
76
+ ```
77
+
78
+ - All imports starting with `"virtual:"` will not be checked.
79
+ - All imports of `.js` files deeply inside `src/special/lib/` will not be checked.
80
+
81
+ ### Option `hierarchy`
82
+
83
+ - Type: `Record<string, RuleNoInvalidHierarchyPackage>`
84
+ - Default: `{}`
85
+
86
+ Allows to separate the source files into several virtual packages. This option is completely independent from any actual packaging performed in later steps of the build process. Its solely purpose is to impose dependencies between the source files to prevent importing files between specific packages.
87
+
88
+ Each key in the `hierarchy` record is the arbitrary unique name of a package. The record values must be objects satisfying the interface `RuleNoInvalidHierarchyPackage`:
89
+
90
+ | Name | Type | Default | Description |
91
+ | - | - | - | - |
92
+ | `files` | `string[]` | _required_ | Glob patterns selecting all source files that are part of the package. |
93
+ | `extends` | `string\|string[]` | `[]` | Specifies the names of all packages (dictionary keys of the option `hierarchy`) this package depends on. |
94
+ | `optional` | `boolean` | `false` | Set to `true` to mark an optional package that may be missing in an installation. Such a package cannot be imported statically (with `import` statement) from a non-optional package, but can only be loaded dynamically at runtime (by calling `import()`). The rule will mark all static imports of optional code as an error. |
95
+
96
+ Modules that are part of such a package may import any modules from the same package, or from packages it depends on (also recursively from their dependent packages).
97
+
98
+ Example configuration:
99
+
100
+ ```js
101
+ // eslint.config.js
102
+ import { eslint } from "@open-xchange/linter-presets"
103
+
104
+ export default [
105
+ ...eslint.configure({ /* ... */ }),
106
+ ...eslint.env.project({
107
+ files: ["src/**/*.{js,ts}"],
108
+ alias: { "@": "src" },
109
+ hierarchy: {
110
+ base: {
111
+ files: ["@/base/**/*", "@/tools/**/*"],
112
+ },
113
+ debug: {
114
+ files: ["@/debug/**/*"],
115
+ extends: "base",
116
+ optional: true,
117
+ },
118
+ special: {
119
+ files: ["@/my/special/**/*"],
120
+ extends: ["base", "debug"],
121
+ },
122
+ },
123
+ }),
124
+ ]
125
+ ```
126
+
127
+ - The package `base` contains all modules starting with `@/base/` or `@/tools/`. All modules in the package `base` can import themselves, but they cannot import any other modules from the project.
128
+ - The _optional_ package `debug` contains all modules starting with `@/debug/`. Modules in this package can import other modules from this package, and from the package `base`. Modules in this package can only be imported dynamically from other packages.
129
+ - The package `special` contains all modules starting with `@/my/special/`. Modules in this package can import other modules from this package, and all modules from the packages `base` and `debug`. The latter package can only be imported dynamically.
@@ -0,0 +1,38 @@
1
+ # Environment `env.react`
2
+
3
+ Creates configuration objects with linter rules for ReactJS. Adds the following plugins and their recommended rules:
4
+
5
+ - [@eslint-react/eslint-plugin](https://eslint-react.xyz/)
6
+ - [eslint-plugin-react-hooks](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks)
7
+ - [eslint-plugin-react-hooks-static-deps](https://github.com/stoikio/eslint-plugin-react-hooks-static-deps)
8
+ - [eslint-plugin-react-refresh](https://github.com/ArnaudBarre/eslint-plugin-react-refresh)
9
+ - [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y)
10
+
11
+ ## Signature
12
+
13
+ ```ts
14
+ function react(options: EnvReactOptions): Linter.Config[]
15
+ ```
16
+
17
+ ## Options
18
+
19
+ | Name | Type | Default | Description |
20
+ | - | - | - | - |
21
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
22
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
23
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
24
+
25
+ ## Example
26
+
27
+ ```js
28
+ // eslint.config.js
29
+ import { eslint } from "@open-xchange/linter-presets"
30
+
31
+ export default [
32
+ ...eslint.configure({ /* ... */ }),
33
+ ...eslint.env.react({
34
+ files: ["src/**/*.{js,ts}"],
35
+ rules: { /* ... */ },
36
+ }),
37
+ ]
38
+ ```
@@ -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.Config[]
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
+ ]
@@ -0,0 +1,41 @@
1
+ # Environment `env.vitest`
2
+
3
+ Creates configuration objects with global symbols and linter rules for unit tests using Vitest. Adds the following plugins and their recommended rules:
4
+
5
+ - [eslint-plugin-vitest](https://github.com/veritem/eslint-plugin-vitest)
6
+ - [eslint-plugin-jest-extended](https://github.com/jest-community/eslint-plugin-jest-extended) (optional)
7
+ - [eslint-plugin-jest-dom](https://github.com/testing-library/eslint-plugin-jest-dom) (optional)
8
+ - [eslint-plugin-testing-library](https://github.com/testing-library/eslint-plugin-testing-library) (optional)
9
+
10
+ ## Signature
11
+
12
+ ```ts
13
+ function vitest(options: EnvVitestOptions): Linter.Config[]
14
+ ```
15
+
16
+ ## Options
17
+
18
+ | Name | Type | Default | Description |
19
+ | - | - | - | - |
20
+ | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
21
+ | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
22
+ | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
23
+ | `jestExtended` | `boolean` | `false` | Activate plugin `eslint-plugin-jest-extended`. |
24
+ | `jestDom` | `boolean` | `false` | Activate plugin `eslint-plugin-jest-dom`. |
25
+ | `testingLib` | `"angular"\|"dom"\|"marko"\|"react"\|"vue"` | _none_ | Add plugin `eslint-plugin-testing-library` for the specified environment. |
26
+
27
+ ## Example
28
+
29
+ ```js
30
+ // eslint.config.js
31
+ import { eslint } from "@open-xchange/linter-presets"
32
+
33
+ export default [
34
+ ...eslint.configure({ /* ... */ }),
35
+ ...eslint.env.vitest({
36
+ files: ["test/**/*.{js,ts}"],
37
+ testingLib: "react",
38
+ rules: { /* ... */ },
39
+ }),
40
+ ]
41
+ ```
@@ -0,0 +1,52 @@
1
+ # StyleLint Presets
2
+
3
+ The module `stylelint` provides a `configure` function for project-wide StyleLint configuration.
4
+
5
+ ## Functions
6
+
7
+ ### Function `configure`
8
+
9
+ Generates standard configuration targeting the source files in the entire project. Internally, various StyleLint plugins will be included and configured to use their recommended rule sets.
10
+
11
+ | Target | StyleLint Plugin |
12
+ | - | - |
13
+ | Stylesheet files (`.css`, `.less`, `.scss`) | StyleLint core rules |
14
+ | Less files only | [stylelint-config-standard-less](https://github.com/stylelint-less/stylelint-config-standard-less) |
15
+ | Sass files only | [stylelint-config-standard-scss](https://github.com/stylelint-scss/stylelint-config-standard-scss) |
16
+ | Source code formatting | [@stylistic/stylelint-plugin](https://github.com/stylelint-stylistic/stylelint-stylistic) |
17
+
18
+ #### `configure` Signature
19
+
20
+ `function configure(options?: ConfigureOptions): Linter.Config[]`
21
+
22
+ #### `configure` Options
23
+
24
+ | Name | Type | Default | Description |
25
+ | - | - | - | - |
26
+ | `ignores` | `string[]` | `[]` | Glob patterns with all files and folders to be ignored by StyleLint. |
27
+ | `license` | `string` | `""` | Full path to the template file containing the license header to be used in all source files. |
28
+ | `stylistic` | `StylisticOptions` | | Configuration options for code style. |
29
+ | `stylistic.indent` | `number` | `4` | Default indentation size (number of space characters). |
30
+ | `stylistic.quotes` | `"single"\|"double"\|"off"` | `"double"` | The type of the string delimiter character. |
31
+ | `rules` | `StyleLint.Config["rules"]` | `{}` | Additional linter rules to be added to the global configuration. |
32
+
33
+ #### Built-in Ignore Globs
34
+
35
+ This package defines ignore globs for the following files and directories:
36
+
37
+ - `dist/*` (standard build output directory)
38
+
39
+ #### `configure` Example
40
+
41
+ ```js
42
+ // stylelint.config.js
43
+ import { utils, stylelint } from "@open-xchange/linter-presets"
44
+
45
+ const resolve = utils.resolver(import.meta.url)
46
+
47
+ export default stylelint.configure({
48
+ ignores: ["external/**/*.scss"],
49
+ license: resolve("./license.txt"),
50
+ stylistic: { indent: 2, quotes: "single" },
51
+ })
52
+ ```
@@ -0,0 +1,30 @@
1
+ # Utility Functions
2
+
3
+ The `utils` module provides utility functions for usage in either ESLint or StyleLint configuration files.
4
+
5
+ ## Functions
6
+
7
+ ### Function `resolver`
8
+
9
+ Creates and returns a function that will convert relative file paths to absolute file paths. Intended to be used with the base URL of the calling script, usually `import.meta.url`.
10
+
11
+ #### `resolver` Signature
12
+
13
+ `function resolver(url: string): (file: string) => string`
14
+
15
+ #### `resolver` Example
16
+
17
+ ```js
18
+ // eslint.config.js
19
+ import { utils, eslint } from "@open-xchange/linter-presets"
20
+
21
+ const resolve = utils.resolver(import.meta.url)
22
+
23
+ export default [
24
+ ...eslint.configure({
25
+ // ...
26
+ license: resolve("./license.txt"),
27
+ // ...
28
+ }),
29
+ ]
30
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/linter-presets",
3
- "version": "1.2.34",
3
+ "version": "1.2.35",
4
4
  "description": "Configuration presets for ESLint and StyleLint",
5
5
  "repository": {
6
6
  "type": "git",
@@ -27,26 +27,26 @@
27
27
  "test": "cd test && eslint . && stylelint \"**/*.{css,scss}\""
28
28
  },
29
29
  "dependencies": {
30
- "@babel/core": "^7.27.1",
30
+ "@babel/core": "^7.27.3",
31
31
  "@babel/eslint-parser": "^7.27.1",
32
32
  "@babel/plugin-proposal-decorators": "^7.27.1",
33
33
  "@eslint-community/eslint-plugin-eslint-comments": "^4.5.0",
34
- "@eslint-react/eslint-plugin": "^1.49.0",
34
+ "@eslint-react/eslint-plugin": "^1.50.0",
35
35
  "@eslint/compat": "^1.2.9",
36
36
  "@eslint/js": "^9.27.0",
37
37
  "@eslint/markdown": "^6.4.0",
38
- "@stylistic/eslint-plugin": "^4.2.0",
39
- "@stylistic/eslint-plugin-migrate": "^4.2.0",
38
+ "@stylistic/eslint-plugin": "^4.4.0",
39
+ "@stylistic/eslint-plugin-migrate": "^4.4.0",
40
40
  "@stylistic/stylelint-config": "^2.0.0",
41
41
  "@stylistic/stylelint-plugin": "^3.1.2",
42
42
  "@types/picomatch": "^4.0.0",
43
- "@vitest/eslint-plugin": "^1.2.0",
43
+ "@vitest/eslint-plugin": "^1.2.1",
44
44
  "confusing-browser-globals": "^1.0.11",
45
45
  "eslint-plugin-chai-expect": "^3.1.0",
46
46
  "eslint-plugin-codeceptjs": "^1.3.0",
47
47
  "eslint-plugin-depend": "^1.2.0",
48
48
  "eslint-plugin-eslint-plugin": "^6.4.0",
49
- "eslint-plugin-jest": "^28.11.0",
49
+ "eslint-plugin-jest": "^28.11.1",
50
50
  "eslint-plugin-jest-dom": "^5.5.0",
51
51
  "eslint-plugin-jest-extended": "^3.0.0",
52
52
  "eslint-plugin-jsdoc": "^50.6.17",
@@ -58,11 +58,11 @@
58
58
  "eslint-plugin-react-hooks": "^5.2.0",
59
59
  "eslint-plugin-react-hooks-static-deps": "^1.0.7",
60
60
  "eslint-plugin-react-refresh": "^0.4.20",
61
- "eslint-plugin-testing-library": "^7.2.1",
61
+ "eslint-plugin-testing-library": "^7.2.2",
62
62
  "eslint-plugin-vue": "^10.1.0",
63
63
  "eslint-plugin-yml": "^1.18.0",
64
64
  "find-up": "^7.0.0",
65
- "globals": "^16.1.0",
65
+ "globals": "^16.2.0",
66
66
  "picomatch": "^4.0.2",
67
67
  "postcss-html": "^1.8.0",
68
68
  "stylelint-config-standard": "^38.0.0",
@@ -70,14 +70,14 @@
70
70
  "stylelint-config-standard-scss": "^15.0.1",
71
71
  "stylelint-config-standard-vue": "^1.0.0",
72
72
  "stylelint-plugin-license-header": "^1.0.3",
73
- "typescript-eslint": "^8.32.1",
73
+ "typescript-eslint": "^8.33.0",
74
74
  "vue-eslint-parser": "^10.1.3"
75
75
  },
76
76
  "devDependencies": {
77
77
  "@types/confusing-browser-globals": "^1.0.3",
78
78
  "@types/eslint-scope": "^8.3.0",
79
- "@types/react": "^19.1.5",
80
- "@typescript-eslint/utils": "^8.32.1",
79
+ "@types/react": "^19.1.6",
80
+ "@typescript-eslint/utils": "^8.33.0",
81
81
  "eslint": "^9.27.0",
82
82
  "jest": "^29.7.0",
83
83
  "jiti": "^2.4.2",