@open-xchange/linter-presets 0.0.2 → 0.0.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.
- package/CHANGELOG.md +14 -3
- package/README.md +21 -8
- package/lib/eslint/README.md +83 -0
- package/lib/eslint/config/base.js +0 -1
- package/lib/eslint/config/imports.js +68 -0
- package/lib/eslint/config/js.js +1 -1
- package/lib/eslint/config/ts.js +1 -1
- package/lib/eslint/env/browser.d.ts +10 -2
- package/lib/eslint/env/browser.js +44 -30
- package/lib/eslint/env/browser.md +33 -0
- package/lib/eslint/env/codecept.d.ts +2 -1
- package/lib/eslint/env/codecept.md +35 -0
- package/lib/eslint/env/eslint.d.ts +14 -0
- package/lib/eslint/env/eslint.js +41 -0
- package/lib/eslint/env/eslint.md +32 -0
- package/lib/eslint/env/jest.d.ts +2 -1
- package/lib/eslint/env/jest.md +32 -0
- package/lib/eslint/env/node.d.ts +8 -1
- package/lib/eslint/env/node.js +10 -6
- package/lib/eslint/env/node.md +34 -0
- package/lib/eslint/env/project.d.ts +21 -0
- package/lib/eslint/env/{plugin.js → project.js} +23 -22
- package/lib/eslint/env/project.md +129 -0
- package/lib/eslint/env/react.d.ts +2 -1
- package/lib/eslint/env/react.md +39 -0
- package/lib/eslint/env/tsconfig.d.ts +2 -1
- package/lib/eslint/env/tsconfig.js +0 -2
- package/lib/eslint/env/tsconfig.md +35 -0
- package/lib/eslint/env/vitest.d.ts +2 -1
- package/lib/eslint/env/vitest.md +36 -0
- package/lib/eslint/index.d.ts +6 -4
- package/lib/eslint/index.js +9 -3
- package/lib/eslint/rules/no-amd-module-directive.js +57 -0
- package/lib/eslint/rules/no-invalid-modules.js +206 -0
- package/lib/eslint/shared/env-utils.d.ts +97 -0
- package/lib/eslint/shared/env-utils.js +105 -0
- package/lib/eslint/shared/rule-utils.js +143 -0
- package/lib/eslint/shared/types.d.ts +1 -25
- package/lib/index.d.ts +1 -1
- package/{doc/stylelint.md → lib/stylelint/README.md} +10 -3
- package/lib/stylelint/index.d.ts +2 -2
- package/lib/stylelint/index.js +42 -12
- package/lib/stylelint/types.d.ts +1 -1
- package/package.json +89 -69
- package/doc/eslint.md +0 -343
- package/lib/eslint/env/plugin.d.ts +0 -13
- package/lib/eslint/shared/constants.js +0 -33
- /package/{doc/utils.md → lib/utils/README.md} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,9 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
## [0.0.1] - 2024-07-05
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
-
|
|
5
|
+
- added: [ESLint] project configuration (core, js, ts, json, yaml, license, directives, promises, jsdoc, stylistic)
|
|
6
|
+
- added: [ESLint] environment presets (tsconfig, node, browser, jest, vitest, codecept, react, plugin)
|
|
7
7
|
|
|
8
8
|
## [0.0.2] - 2024-07-08
|
|
9
9
|
|
|
10
|
-
-
|
|
10
|
+
- added: [StyleLint] project configuration (core, less, sass, license, stylistic)
|
|
11
|
+
|
|
12
|
+
## [0.0.3] - 2024-07-09
|
|
13
|
+
|
|
14
|
+
- added: [ESLint] `eslint-plugin-import`
|
|
15
|
+
- added: [ESLint] option "restricted" for `env.node` and `env.browser`
|
|
16
|
+
- added: [ESLint] custom rule `env-project/no-amd-module-directive`
|
|
17
|
+
- added: [ESLint] custom rule `env-project/no-invalid-modules`
|
|
18
|
+
- added: [ESLint] environment `env.project` (wraps all `env-project/*` rules)
|
|
19
|
+
- changed: [ESLint] environment `env.plugin` renamed to `env.eslint`
|
|
20
|
+
- fixed: [StyleLint] support for LESS files
|
|
21
|
+
- chore: update dependencies
|
package/README.md
CHANGED
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
This package provides configuration presets for [ESLint](https://eslint.org/) and [StyleLint](https://stylelint.io/), including wrappers for various linter plugins.
|
|
4
4
|
|
|
5
|
-
## Utils
|
|
6
|
-
|
|
7
|
-
The module `utils` exports utility functions for usage in either ESLint or StyleLint configuration files.
|
|
8
|
-
|
|
9
|
-
See the [documentation](./doc/utils.md) for more details.
|
|
10
|
-
|
|
11
5
|
## ESLint
|
|
12
6
|
|
|
13
7
|
The module `eslint` exports a `configure` function for setting up the entire project (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.).
|
|
@@ -32,8 +26,27 @@ export default [
|
|
|
32
26
|
]
|
|
33
27
|
```
|
|
34
28
|
|
|
35
|
-
See the [documentation](./
|
|
29
|
+
See the [`eslint` module documentation](./lib/eslint/README.md) for more details.
|
|
36
30
|
|
|
37
31
|
## StyleLint
|
|
38
32
|
|
|
39
|
-
|
|
33
|
+
The module `stylelint` exports a `configure` function for setting up the entire project (e.g. CSS files, SCSS files, license headers, etc.).
|
|
34
|
+
|
|
35
|
+
Usage example:
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
// stylelint.config.js
|
|
39
|
+
import { stylelint } from "@open-xchange/linter-presets"
|
|
40
|
+
|
|
41
|
+
export default eslint.configure({
|
|
42
|
+
/* config options */
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
See the [`stylelint` module documentation](./lib/stylelint/README.md) for more details.
|
|
47
|
+
|
|
48
|
+
## Utils
|
|
49
|
+
|
|
50
|
+
The module `utils` exports utility functions to be used in ESLint and StyleLint configuration files.
|
|
51
|
+
|
|
52
|
+
See the [`utils` module documentation](./lib/utils/README.md) for more details.
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
| JSON files | [eslint-plugin-jsonc](https://ota-meshi.github.io/eslint-plugin-jsonc/) |
|
|
17
|
+
| YAML files | [eslint-plugin-yml](https://ota-meshi.github.io/eslint-plugin-yml/) |
|
|
18
|
+
| License headers | [eslint-plugin-license-header](https://github.com/nikku/eslint-plugin-license-header) |
|
|
19
|
+
| ESLint inline directives | [@eslint-community/eslint-plugin-eslint-comments](https://github.com/eslint-community/eslint-plugin-eslint-comments) |
|
|
20
|
+
| Module imports | [eslint-plugin-import](https://github.com/import-js/eslint-plugin-import) |
|
|
21
|
+
| Native ES6 promises | [eslint-plugin-promise](https://github.com/eslint-community/eslint-plugin-promise) |
|
|
22
|
+
| JSDoc source documentation | [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) |
|
|
23
|
+
| Source code formatting | [@stylistic/eslint-plugin](https://eslint.style/packages/default) |
|
|
24
|
+
|
|
25
|
+
#### `configure` Signature
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
function configure(options?: ConfigureOptions): Linter.FlatConfig[]
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
#### `configure` Options
|
|
32
|
+
|
|
33
|
+
| Name | Type | Default | Description |
|
|
34
|
+
| - | - | - | - |
|
|
35
|
+
| `ignores` | `string[]` | `[]` | Glob patterns with all files and folders to be ignored by ESLint. |
|
|
36
|
+
| `license` | `string` | `""` | Full path to the template file containing the license header to be used in all source files. |
|
|
37
|
+
| `language` | `LanguageOptions` | | Configuration options for language and project setup. |
|
|
38
|
+
| `language.ecmaVersion` | `number` | `2022` | The ECMAScript version to be used in the project (version or year). |
|
|
39
|
+
| `language.sourceType` | `"module"\|"commonjs"` | `"module"` | Specifies how to treat `.js`, `.jsx`, `.ts`, and `.tsx` files. |
|
|
40
|
+
| `stylistic` | `StylisticOptions` | | Configuration options for code style. |
|
|
41
|
+
| `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. |
|
|
42
|
+
| `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`). |
|
|
43
|
+
| `stylistic.quotes` | `"single"\|"double"\|"off"` | `"single"` | The type of the string delimiter character. |
|
|
44
|
+
| `stylistic.dangle` | `"always"\|"never"\|"off"` | `"always"` | Specifies how to treat dangling commas in multiline lists. |
|
|
45
|
+
| `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the global configuration. |
|
|
46
|
+
|
|
47
|
+
#### `configure` Example
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
// eslint.config.js
|
|
51
|
+
import { utils, eslint } from "@open-xchange/linter-presets"
|
|
52
|
+
|
|
53
|
+
const resolve = utils.resolver(import.meta.url)
|
|
54
|
+
|
|
55
|
+
export default [
|
|
56
|
+
...eslint.configure({
|
|
57
|
+
ignores: ["dist/*", "external/**/*.yaml"],
|
|
58
|
+
language: { ecmaVersion: 2024, sourceType: "commonjs" },
|
|
59
|
+
license: resolve("./license.txt"),
|
|
60
|
+
stylistic: { quotes: "double", semi: true },
|
|
61
|
+
}),
|
|
62
|
+
]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Environment Presets
|
|
66
|
+
|
|
67
|
+
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.
|
|
68
|
+
|
|
69
|
+
### Overview
|
|
70
|
+
|
|
71
|
+
The names of the environment presets are linked to detailed descriptions.
|
|
72
|
+
|
|
73
|
+
| Name | Description |
|
|
74
|
+
| - | - |
|
|
75
|
+
| [`env.tsconfig`](./env/tsconfig.md) | TypeScript project setup (per `tsconfig.json` file). |
|
|
76
|
+
| [`env.node`](./env/node.md) | Modules running in NodeJS. |
|
|
77
|
+
| [`env.browser`](./env/browser.md) | Modules running in browsers. |
|
|
78
|
+
| [`env.react`](./env/react.md) | Modules using [React](https://react.dev/) library. |
|
|
79
|
+
| [`env.jest`](./env/jest.md) | Unit tests with [Jest](https://jestjs.io/). |
|
|
80
|
+
| [`env.vitest`](./env/vitest.md) | Unit tests with [Vitest](https://vitest.dev/). |
|
|
81
|
+
| [`env.codecept`](./env/codecept.md) | E2E tests with [CodeceptJS](https://codecept.io/). |
|
|
82
|
+
| [`env.eslint`](./env/eslint.md) | Implementation of custom ESLint rules. |
|
|
83
|
+
| [`env.project`](./env/project.md) | Project setup and module imports. |
|
|
@@ -120,7 +120,6 @@ export default function base(options) {
|
|
|
120
120
|
"no-useless-return": "error",
|
|
121
121
|
"no-var": "error",
|
|
122
122
|
"object-shorthand": "error",
|
|
123
|
-
"one-var": ["error", "never"],
|
|
124
123
|
"operator-assignment": "error",
|
|
125
124
|
"prefer-arrow-callback": "error",
|
|
126
125
|
"prefer-const": ["error", { ignoreReadBeforeAssign: true }],
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
|
|
2
|
+
import { fixupPluginRules } from "@eslint/compat";
|
|
3
|
+
import importPlugin from "eslint-plugin-import";
|
|
4
|
+
|
|
5
|
+
// exports ====================================================================
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Adds linter rules for `import` and `export` statements.
|
|
9
|
+
*
|
|
10
|
+
* Wraps the following packages:
|
|
11
|
+
* - `eslint-plugin-import`
|
|
12
|
+
*
|
|
13
|
+
* @param {Required<import("../shared/types").LanguageOptions>} options
|
|
14
|
+
* Resolved configuration options.
|
|
15
|
+
*
|
|
16
|
+
* @returns {import("../shared/types.js").FlatConfigArray}
|
|
17
|
+
* An array of configuration objects to be added to the flat configuration.
|
|
18
|
+
*/
|
|
19
|
+
export default function importConfig(options) {
|
|
20
|
+
|
|
21
|
+
// configuration properties
|
|
22
|
+
const { ecmaVersion, sourceType } = options;
|
|
23
|
+
|
|
24
|
+
// extensions of ES module files
|
|
25
|
+
const jsExtensions = (sourceType === "module") ? [".js", ".mjs"] : [".mjs"];
|
|
26
|
+
const tsExtensions = (sourceType === "module") ? [".ts", ".mts"] : [".mts"];
|
|
27
|
+
|
|
28
|
+
return [{
|
|
29
|
+
files: [
|
|
30
|
+
...jsExtensions.map(ext => "**/*" + ext),
|
|
31
|
+
...tsExtensions.map(ext => "**/*" + ext),
|
|
32
|
+
],
|
|
33
|
+
|
|
34
|
+
// register rule implementations of the plugin
|
|
35
|
+
plugins: {
|
|
36
|
+
import: fixupPluginRules(importPlugin), // https://github.com/import-js/eslint-plugin-import/issues/2948
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
// language options need to be repeated for this plugin
|
|
40
|
+
languageOptions: {
|
|
41
|
+
parserOptions: {
|
|
42
|
+
ecmaVersion,
|
|
43
|
+
sourceType: "module",
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
// parser settings need to be repeated for this plugin
|
|
48
|
+
settings: {
|
|
49
|
+
"import/parsers": {
|
|
50
|
+
espree: jsExtensions,
|
|
51
|
+
"@typescript-eslint/parser": tsExtensions,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
// reconfigure plugin rules
|
|
56
|
+
rules: {
|
|
57
|
+
// recommended rules
|
|
58
|
+
...importPlugin.configs.recommended.rules,
|
|
59
|
+
...importPlugin.configs.typescript.rules,
|
|
60
|
+
// change or disable a few recommended rules
|
|
61
|
+
"import/default": "off",
|
|
62
|
+
"import/no-duplicates": "error",
|
|
63
|
+
"import/no-named-as-default": "off",
|
|
64
|
+
"import/no-named-as-default-member": "off",
|
|
65
|
+
"import/no-unresolved": "off",
|
|
66
|
+
},
|
|
67
|
+
}];
|
|
68
|
+
}
|
package/lib/eslint/config/js.js
CHANGED
package/lib/eslint/config/ts.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import typescriptEslint from "typescript-eslint";
|
|
9
9
|
|
|
10
|
-
import { NO_UNUSED_VARS_OPTIONS } from "../shared/
|
|
10
|
+
import { NO_UNUSED_VARS_OPTIONS } from "../shared/env-utils.js";
|
|
11
11
|
|
|
12
12
|
// functions ==================================================================
|
|
13
13
|
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
|
|
2
|
-
import { FlatConfigArray
|
|
2
|
+
import { FlatConfigArray } from "../shared/types";
|
|
3
|
+
import { EnvBaseOptions, EnvRestrictedOptions } from "../shared/env-utils";
|
|
3
4
|
|
|
4
5
|
// types ======================================================================
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Configuration options for the environment preset "env.browser".
|
|
8
9
|
*/
|
|
9
|
-
export interface EnvBrowserOptions extends EnvBaseOptions {
|
|
10
|
+
export interface EnvBrowserOptions extends EnvBaseOptions {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* All globals, imports, properties, and syntax constructs to be banned for
|
|
14
|
+
* the files included by the environment.
|
|
15
|
+
*/
|
|
16
|
+
restricted?: EnvRestrictedOptions;
|
|
17
|
+
}
|
|
10
18
|
|
|
11
19
|
// functions ==================================================================
|
|
12
20
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import JAVASCRIPT_GLOBALS from "globals";
|
|
3
3
|
import CONFUSING_BROWSER_GLOBALS from "confusing-browser-globals";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { generateRestrictedRules } from "../shared/env-utils.js";
|
|
6
6
|
|
|
7
7
|
// constants ==================================================================
|
|
8
8
|
|
|
@@ -36,6 +36,21 @@ const AMBIGUOUS_BROWSER_TYPES = [
|
|
|
36
36
|
"Transformer",
|
|
37
37
|
];
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Properties of global objects to be banned in all browser modules.
|
|
41
|
+
*/
|
|
42
|
+
const RESTRICTED_PROPERTIES = [
|
|
43
|
+
{ object: "Object", property: "hasOwn", message: "Missing browser support." },
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Syntax constructs to be banned in all browser modules.
|
|
48
|
+
*/
|
|
49
|
+
const RESTRICTED_SYNTAX = [
|
|
50
|
+
{ selector: "ClassBody > StaticBlock", message: "Static blocks not supported yet." },
|
|
51
|
+
{ selector: "ExportNamedDeclaration > TSEnumDeclaration[const=true]", message: "Do not export const enums." },
|
|
52
|
+
];
|
|
53
|
+
|
|
39
54
|
// initialization =============================================================
|
|
40
55
|
|
|
41
56
|
/**
|
|
@@ -68,7 +83,7 @@ for (const name of CONFUSING_BROWSER_GLOBALS) {
|
|
|
68
83
|
}
|
|
69
84
|
|
|
70
85
|
// Create the configuration list for rule "no-restricted-globals".
|
|
71
|
-
const
|
|
86
|
+
const RESTRICTED_GLOBALS = AMBIGUOUS_BROWSER_TYPES.map(name => {
|
|
72
87
|
const message = `Import custom type '${name}', or use 'window.${name}' for disambiguation.`;
|
|
73
88
|
return { name, message };
|
|
74
89
|
});
|
|
@@ -94,34 +109,33 @@ export default function browser(options) {
|
|
|
94
109
|
// configuration properties
|
|
95
110
|
const { files, ignores = [], rules } = options;
|
|
96
111
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
// generate the "no-restricted-?" rules according to passed configuration
|
|
113
|
+
const restricted = generateRestrictedRules({
|
|
114
|
+
globals: RESTRICTED_GLOBALS,
|
|
115
|
+
properties: RESTRICTED_PROPERTIES,
|
|
116
|
+
syntax: RESTRICTED_SYNTAX,
|
|
117
|
+
}, options?.restricted);
|
|
118
|
+
|
|
119
|
+
return [
|
|
120
|
+
|
|
121
|
+
// base configuration for the environment
|
|
122
|
+
{
|
|
123
|
+
files,
|
|
124
|
+
ignores,
|
|
125
|
+
|
|
126
|
+
// register global symbols used in browser scripts
|
|
127
|
+
languageOptions: {
|
|
128
|
+
globals: BROWSER_GLOBALS,
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
// configure rules
|
|
132
|
+
rules: {
|
|
133
|
+
...restricted.rules,
|
|
134
|
+
...rules,
|
|
135
|
+
},
|
|
104
136
|
},
|
|
105
137
|
|
|
106
|
-
//
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
"no-restricted-globals": ["error",
|
|
110
|
-
...RESTRICTED_GLOBALS,
|
|
111
|
-
...AMBIGUOUS_BROWSER_GLOBALS,
|
|
112
|
-
],
|
|
113
|
-
// ban static class functions
|
|
114
|
-
"no-restricted-properties": ["error",
|
|
115
|
-
{ object: "Object", property: "hasOwn", message: "Missing browser support." },
|
|
116
|
-
],
|
|
117
|
-
// ban specific syntax constructs
|
|
118
|
-
"no-restricted-syntax": ["error",
|
|
119
|
-
...RESTRICTED_SYNTAX,
|
|
120
|
-
{ selector: "ClassBody > StaticBlock", message: "Static blocks not supported yet." },
|
|
121
|
-
{ selector: "ExportNamedDeclaration > TSEnumDeclaration[const=true]", message: "Do not export const enums." },
|
|
122
|
-
],
|
|
123
|
-
// custom rules
|
|
124
|
-
...rules,
|
|
125
|
-
},
|
|
126
|
-
}];
|
|
138
|
+
// "no-restricted-?" rules overrides for specific files
|
|
139
|
+
...restricted.overrides,
|
|
140
|
+
];
|
|
127
141
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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.FlatConfig[]
|
|
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. |
|
|
18
|
+
| `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
|
|
19
|
+
|
|
20
|
+
## Example
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
// eslint.config.js
|
|
24
|
+
import { eslint } from "@open-xchange/linter-presets"
|
|
25
|
+
|
|
26
|
+
export default [
|
|
27
|
+
...eslint.configure({ /* ... */ }),
|
|
28
|
+
...eslint.env.browser({
|
|
29
|
+
files: ["src/**/*.{js,ts}"],
|
|
30
|
+
rules: { /* ... */ },
|
|
31
|
+
}),
|
|
32
|
+
]
|
|
33
|
+
```
|
|
@@ -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.FlatConfig[]
|
|
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,14 @@
|
|
|
1
|
+
|
|
2
|
+
import { FlatConfigArray } from "../shared/types";
|
|
3
|
+
import { EnvBaseOptions } from "../shared/env-utils";
|
|
4
|
+
|
|
5
|
+
// types ======================================================================
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for the environment preset "env.eslint".
|
|
9
|
+
*/
|
|
10
|
+
export interface EnvEslintOptions extends EnvBaseOptions { }
|
|
11
|
+
|
|
12
|
+
// functions ==================================================================
|
|
13
|
+
|
|
14
|
+
export default function eslint(options: EnvEslintOptions): FlatConfigArray;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
|
|
2
|
+
import eslintPlugin from "eslint-plugin-eslint-plugin";
|
|
3
|
+
|
|
4
|
+
// exports ====================================================================
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Adds linter rules for ESLint plugin implementations.
|
|
8
|
+
*
|
|
9
|
+
* Wraps the following packages:
|
|
10
|
+
* - `eslint-plugin-eslint-plugin`
|
|
11
|
+
*
|
|
12
|
+
* @param {import("./eslint").EnvEslintOptions} options
|
|
13
|
+
* Configuration options for the environment.
|
|
14
|
+
*
|
|
15
|
+
* @returns {import("../shared/types").FlatConfigArray}
|
|
16
|
+
* An array of configuration objects to be added to the flat configuration.
|
|
17
|
+
*/
|
|
18
|
+
export default function eslint(options) {
|
|
19
|
+
|
|
20
|
+
// configuration properties
|
|
21
|
+
const { files, ignores = [], rules = {} } = options;
|
|
22
|
+
// the plugin configuration
|
|
23
|
+
const pluginConfig = eslintPlugin.configs["flat/rules-recommended"];
|
|
24
|
+
|
|
25
|
+
return [
|
|
26
|
+
|
|
27
|
+
// register rule implementations and recommended rules
|
|
28
|
+
{
|
|
29
|
+
files,
|
|
30
|
+
ignores,
|
|
31
|
+
...pluginConfig,
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
// reconfigure plugin rules
|
|
35
|
+
{
|
|
36
|
+
files,
|
|
37
|
+
ignores,
|
|
38
|
+
rules,
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
}
|
|
@@ -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.FlatConfig[]
|
|
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
|
+
```
|
package/lib/eslint/env/jest.d.ts
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Environment `env.jest`
|
|
2
|
+
|
|
3
|
+
Creates configuration objects with global symbols and linter rules for unit tests using Jest. Adds the plugin [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) and its recommended rules.
|
|
4
|
+
|
|
5
|
+
## Signature
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
function jest(options: EnvJestOptions): Linter.FlatConfig[]
|
|
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.jest({
|
|
28
|
+
files: ["test/**/*.{js,ts}"],
|
|
29
|
+
rules: { /* ... */ },
|
|
30
|
+
}),
|
|
31
|
+
]
|
|
32
|
+
```
|
package/lib/eslint/env/node.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
import { FlatConfigArray, LanguageOptions
|
|
2
|
+
import { FlatConfigArray, LanguageOptions } from "../shared/types";
|
|
3
|
+
import { EnvBaseOptions, EnvRestrictedOptions } from "../shared/env-utils";
|
|
3
4
|
|
|
4
5
|
// types ======================================================================
|
|
5
6
|
|
|
@@ -14,6 +15,12 @@ export interface EnvNodeOptions extends EnvBaseOptions {
|
|
|
14
15
|
* Default value is "module".
|
|
15
16
|
*/
|
|
16
17
|
sourceType?: LanguageOptions["sourceType"];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* All globals, imports, properties, and syntax constructs to be banned for
|
|
21
|
+
* the files included by the environment.
|
|
22
|
+
*/
|
|
23
|
+
restricted?: EnvRestrictedOptions;
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
// functions ==================================================================
|
package/lib/eslint/env/node.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// - https://github.com/mysticatea/eslint-plugin-node/issues/341
|
|
4
4
|
import nodePlugin from "eslint-plugin-n";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { generateRestrictedRules } from "../shared/env-utils.js";
|
|
7
7
|
|
|
8
8
|
// functions ==================================================================
|
|
9
9
|
|
|
@@ -28,17 +28,19 @@ export default function node(options) {
|
|
|
28
28
|
const configKey = (sourceType === "commonjs") ? "flat/recommended-script" : "flat/recommended-module";
|
|
29
29
|
const nodeConfig = nodePlugin.configs[configKey];
|
|
30
30
|
|
|
31
|
+
// generate the "no-restricted-?" rules according to passed configuration
|
|
32
|
+
const restricted = generateRestrictedRules({}, options?.restricted);
|
|
33
|
+
|
|
31
34
|
return [
|
|
32
35
|
|
|
33
|
-
// register rule implementations
|
|
36
|
+
// register rule implementations
|
|
34
37
|
{
|
|
35
38
|
files,
|
|
36
39
|
ignores,
|
|
37
40
|
...nodeConfig,
|
|
38
|
-
// automatically add missing extensions in imports of CommonJS scripts
|
|
39
41
|
settings: {
|
|
40
42
|
node: {
|
|
41
|
-
tryExtensions: [".js", ".ts"],
|
|
43
|
+
tryExtensions: [".js", ".ts", ".d.ts"], // automatically add missing extensions in imports
|
|
42
44
|
},
|
|
43
45
|
},
|
|
44
46
|
},
|
|
@@ -48,12 +50,14 @@ export default function node(options) {
|
|
|
48
50
|
files,
|
|
49
51
|
ignores,
|
|
50
52
|
rules: {
|
|
51
|
-
"no-restricted-globals": ["error", ...RESTRICTED_GLOBALS],
|
|
52
|
-
"no-restricted-syntax": ["error", ...RESTRICTED_SYNTAX],
|
|
53
53
|
"n/no-unsupported-features/node-builtins": ["error", { allowExperimental: true }],
|
|
54
54
|
"n/prefer-node-protocol": "error",
|
|
55
|
+
...restricted.rules,
|
|
55
56
|
...rules,
|
|
56
57
|
},
|
|
57
58
|
},
|
|
59
|
+
|
|
60
|
+
// "no-restricted-?" rules overrides for specific files
|
|
61
|
+
...restricted.overrides,
|
|
58
62
|
];
|
|
59
63
|
}
|