@open-xchange/linter-presets 0.0.1 → 0.0.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 +10 -0
- package/doc/eslint.md +2 -2
- package/doc/stylelint.md +36 -0
- package/lib/eslint/index.d.ts +4 -53
- package/lib/eslint/index.js +8 -8
- package/lib/eslint/shared/types.d.ts +41 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/stylelint/index.d.ts +18 -0
- package/lib/stylelint/index.js +76 -0
- package/lib/stylelint/types.d.ts +44 -0
- package/package.json +11 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.1] - 2024-07-05
|
|
4
|
+
|
|
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
|
+
|
|
8
|
+
## [0.0.2] - 2024-07-08
|
|
9
|
+
|
|
10
|
+
- Added: StyleLint project configuration (core, less, sass, license, stylistic)
|
package/doc/eslint.md
CHANGED
|
@@ -23,13 +23,13 @@ Generates standard configuration targeting the source files in the entire projec
|
|
|
23
23
|
|
|
24
24
|
#### `configure` Signature
|
|
25
25
|
|
|
26
|
-
`function configure(options?:
|
|
26
|
+
`function configure(options?: ESLintConfigureOptions): Linter.FlatConfig[]`
|
|
27
27
|
|
|
28
28
|
#### `configure` Options
|
|
29
29
|
|
|
30
30
|
| Name | Type | Default | Description |
|
|
31
31
|
| - | - | - | - |
|
|
32
|
-
| `ignores` | `string[]` | `[]` | Glob patterns with all files and folders to be ignored by
|
|
32
|
+
| `ignores` | `string[]` | `[]` | Glob patterns with all files and folders to be ignored by ESLint. |
|
|
33
33
|
| `license` | `string` | `""` | Full path to the template file containing the license header to be used in all source files. |
|
|
34
34
|
| `language` | `LanguageOptions` | | Configuration options for language and project setup. |
|
|
35
35
|
| `language.ecmaVersion` | `number` | `2022` | The ECMAScript version to be used in the project (version or year). |
|
package/doc/stylelint.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
1
|
# StyleLint Presets
|
|
2
2
|
|
|
3
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
|
+
#### `configure` Signature
|
|
12
|
+
|
|
13
|
+
`function configure(options?: StyleLintConfigureOptions): Linter.FlatConfig[]`
|
|
14
|
+
|
|
15
|
+
#### `configure` Options
|
|
16
|
+
|
|
17
|
+
| Name | Type | Default | Description |
|
|
18
|
+
| - | - | - | - |
|
|
19
|
+
| `ignores` | `string[]` | `[]` | Glob patterns with all files and folders to be ignored by StyleLint. |
|
|
20
|
+
| `license` | `string` | `""` | Full path to the template file containing the license header to be used in all source files. |
|
|
21
|
+
| `stylistic` | `StylisticOptions` | | Configuration options for code style. |
|
|
22
|
+
| `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. |
|
|
23
|
+
| `stylistic.quotes` | `"single"\|"double"\|"off"` | `"single"` | The type of the string delimiter character. |
|
|
24
|
+
| `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the global configuration. |
|
|
25
|
+
|
|
26
|
+
#### `configure` Example
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
// stylelint.config.js
|
|
30
|
+
import { utils, stylelint } from "@open-xchange/linter-presets"
|
|
31
|
+
|
|
32
|
+
const resolve = utils.resolver(import.meta.url)
|
|
33
|
+
|
|
34
|
+
export default stylelint.configure({
|
|
35
|
+
ignores: ["dist/*", "external/**/*.scss"],
|
|
36
|
+
license: resolve("./license.txt"),
|
|
37
|
+
stylistic: { indent: 4, quotes: "double" },
|
|
38
|
+
})
|
|
39
|
+
```
|
package/lib/eslint/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { FlatConfigArray, LanguageOptions, StylisticOptions } from "./shared/types";
|
|
2
|
+
import { FlatConfigArray, ESLintConfigureOptions } from "./shared/types";
|
|
5
3
|
|
|
6
4
|
import tsconfig from "./env/tsconfig";
|
|
7
5
|
import node from "./env/node";
|
|
@@ -12,41 +10,6 @@ import codecept from "./env/codecept";
|
|
|
12
10
|
import react from "./env/react";
|
|
13
11
|
import plugin from "./env/plugin";
|
|
14
12
|
|
|
15
|
-
// types ======================================================================
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Configuration options for linting the entire project.
|
|
19
|
-
*/
|
|
20
|
-
export interface ESLintPresetsOptions {
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Glob patterns with all files and folders to be ignored by ESlint.
|
|
24
|
-
*/
|
|
25
|
-
ignores?: readonly string[];
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Full path to the template file containing the license header to be used
|
|
29
|
-
* in all source files. The function `resolver` helps to to convert a local
|
|
30
|
-
* path to an absolute path.
|
|
31
|
-
*/
|
|
32
|
-
license?: string;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Configuration options for language and project setup.
|
|
36
|
-
*/
|
|
37
|
-
language?: LanguageOptions;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Configuration options for code style.
|
|
41
|
-
*/
|
|
42
|
-
stylistic?: StylisticOptions;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Additional linter rules to be added to the global configuration.
|
|
46
|
-
*/
|
|
47
|
-
rules?: Linter.RulesRecord;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
13
|
// environments ===============================================================
|
|
51
14
|
|
|
52
15
|
/**
|
|
@@ -65,26 +28,14 @@ export const env: {
|
|
|
65
28
|
|
|
66
29
|
// functions ==================================================================
|
|
67
30
|
|
|
68
|
-
/**
|
|
69
|
-
* Creates and returns a resolver function for file paths relative to the given
|
|
70
|
-
* base URL of a script file.
|
|
71
|
-
*
|
|
72
|
-
* @param url
|
|
73
|
-
* The base URL of the calling script, usually `import.meta.url`.
|
|
74
|
-
*
|
|
75
|
-
* @returns
|
|
76
|
-
* A function that converts relative file paths to absolute file paths.
|
|
77
|
-
*/
|
|
78
|
-
export function resolver(url: string): (file: string) => string;
|
|
79
|
-
|
|
80
31
|
/**
|
|
81
32
|
* Defines standard configuration objects targeting the source files in the
|
|
82
33
|
* entire project.
|
|
83
34
|
*
|
|
84
|
-
* @param
|
|
85
|
-
* Plugin configuration.
|
|
35
|
+
* @param options
|
|
36
|
+
* Plugin configuration options.
|
|
86
37
|
*
|
|
87
38
|
* @returns
|
|
88
39
|
* An array of configuration objects to be added to the flat configuration.
|
|
89
40
|
*/
|
|
90
|
-
export function configure(
|
|
41
|
+
export function configure(options?: ESLintConfigureOptions): FlatConfigArray;
|
package/lib/eslint/index.js
CHANGED
|
@@ -41,23 +41,23 @@ export const env = {
|
|
|
41
41
|
* Generates standard configuration objects targeting the source files in the
|
|
42
42
|
* entire project.
|
|
43
43
|
*
|
|
44
|
-
* @param {import("./shared/types
|
|
44
|
+
* @param {import("./shared/types").ESLintConfigureOptions} [options]
|
|
45
45
|
* Plugin configuration options.
|
|
46
46
|
*
|
|
47
|
-
* @returns {import("./shared/types
|
|
47
|
+
* @returns {import("./shared/types").FlatConfigArray}
|
|
48
48
|
* An array of configuration objects to be added to the flat configuration.
|
|
49
49
|
*/
|
|
50
50
|
export function configure(options) {
|
|
51
51
|
|
|
52
52
|
// resolve language configuration options
|
|
53
|
-
const
|
|
53
|
+
const languageOptions = {
|
|
54
54
|
ecmaVersion: 2022,
|
|
55
55
|
sourceType: "module",
|
|
56
56
|
...options?.language,
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
// resolve stylistic configuration options
|
|
60
|
-
const
|
|
60
|
+
const stylisticOptions = {
|
|
61
61
|
indent: 2,
|
|
62
62
|
semi: false,
|
|
63
63
|
quotes: "single",
|
|
@@ -71,7 +71,7 @@ export function configure(options) {
|
|
|
71
71
|
...(options?.ignores?.length ? [{ ignores: options.ignores }] : []),
|
|
72
72
|
|
|
73
73
|
// module types and standard rules for all JS/TS source files
|
|
74
|
-
...base(
|
|
74
|
+
...base(languageOptions),
|
|
75
75
|
|
|
76
76
|
// default configuration for JavaScript files
|
|
77
77
|
...js(),
|
|
@@ -80,10 +80,10 @@ export function configure(options) {
|
|
|
80
80
|
...ts(),
|
|
81
81
|
|
|
82
82
|
// default configuration for JSON files
|
|
83
|
-
...json(
|
|
83
|
+
...json(stylisticOptions),
|
|
84
84
|
|
|
85
85
|
// default configuration for YAML files
|
|
86
|
-
...yaml(
|
|
86
|
+
...yaml(stylisticOptions),
|
|
87
87
|
|
|
88
88
|
// check for correct license headers
|
|
89
89
|
...(options?.license ? license(options.license) : []),
|
|
@@ -98,7 +98,7 @@ export function configure(options) {
|
|
|
98
98
|
...jsdoc(),
|
|
99
99
|
|
|
100
100
|
// default configuration for code style checks
|
|
101
|
-
...stylistic(
|
|
101
|
+
...stylistic(stylisticOptions),
|
|
102
102
|
|
|
103
103
|
// custom rules
|
|
104
104
|
...(options?.rules ? [{ rules: options.rules }] : []),
|
|
@@ -8,6 +8,8 @@ import { Linter } from "eslint";
|
|
|
8
8
|
*/
|
|
9
9
|
export type FlatConfigArray = Linter.FlatConfig[];
|
|
10
10
|
|
|
11
|
+
// ----------------------------------------------------------------------------
|
|
12
|
+
|
|
11
13
|
/**
|
|
12
14
|
* Configuration options for language and project setup.
|
|
13
15
|
*/
|
|
@@ -30,6 +32,8 @@ export interface LanguageOptions {
|
|
|
30
32
|
sourceType?: "module" | "commonjs";
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
// ----------------------------------------------------------------------------
|
|
36
|
+
|
|
33
37
|
/**
|
|
34
38
|
* Configuration options for code style.
|
|
35
39
|
*/
|
|
@@ -67,6 +71,43 @@ export interface StylisticOptions {
|
|
|
67
71
|
dangle?: "always" | "never" | "off";
|
|
68
72
|
}
|
|
69
73
|
|
|
74
|
+
// ----------------------------------------------------------------------------
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Configuration options for linting the entire project with ESLint.
|
|
78
|
+
*/
|
|
79
|
+
export interface ESLintConfigureOptions {
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Glob patterns with all files and folders to be ignored by ESLint.
|
|
83
|
+
*/
|
|
84
|
+
ignores?: readonly string[];
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Full path to the template file containing the license header to be used
|
|
88
|
+
* in all source files. The function `resolver` helps to to convert a local
|
|
89
|
+
* path to an absolute path.
|
|
90
|
+
*/
|
|
91
|
+
license?: string;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Configuration options for language and project setup.
|
|
95
|
+
*/
|
|
96
|
+
language?: LanguageOptions;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Configuration options for code style.
|
|
100
|
+
*/
|
|
101
|
+
stylistic?: StylisticOptions;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Additional linter rules to be added to the global configuration.
|
|
105
|
+
*/
|
|
106
|
+
rules?: Linter.RulesRecord;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ----------------------------------------------------------------------------
|
|
110
|
+
|
|
70
111
|
/**
|
|
71
112
|
* Shared options for an environment preset: include and exclude files, and add
|
|
72
113
|
* more linter rules.
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
import { Config } from "stylelint";
|
|
3
|
+
|
|
4
|
+
import { StyleLintConfigureOptions } from "./types";
|
|
5
|
+
|
|
6
|
+
// functions ==================================================================
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Defines standard configuration objects targeting the source files in the
|
|
10
|
+
* entire project.
|
|
11
|
+
*
|
|
12
|
+
* @param config
|
|
13
|
+
* Plugin configuration.
|
|
14
|
+
*
|
|
15
|
+
* @returns
|
|
16
|
+
* An array of configuration objects to be added to the flat configuration.
|
|
17
|
+
*/
|
|
18
|
+
export function configure(config?: StyleLintConfigureOptions): Config;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
|
|
2
|
+
// functions ==================================================================
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generates standard configuration objects targeting the source files in the
|
|
6
|
+
* entire project.
|
|
7
|
+
*
|
|
8
|
+
* @param {import("./types").StyleLintConfigureOptions} [options]
|
|
9
|
+
* Plugin configuration options.
|
|
10
|
+
*
|
|
11
|
+
* @returns {import("stylelint").Config}
|
|
12
|
+
* The configuration object to be exported from `stylelint.config.js`.
|
|
13
|
+
*/
|
|
14
|
+
export function configure(options) {
|
|
15
|
+
|
|
16
|
+
// resolve stylistic configuration options
|
|
17
|
+
const stylistic = {
|
|
18
|
+
indent: 2,
|
|
19
|
+
quotes: "single",
|
|
20
|
+
...options?.stylistic,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
|
|
25
|
+
// ignore certain files and folders
|
|
26
|
+
ignoreFiles: options?.ignores ?? [],
|
|
27
|
+
|
|
28
|
+
// add the stylistic plugin
|
|
29
|
+
plugins: [
|
|
30
|
+
"stylelint-plugin-license-header",
|
|
31
|
+
"@stylistic/stylelint-plugin",
|
|
32
|
+
],
|
|
33
|
+
|
|
34
|
+
// add recommended configurations
|
|
35
|
+
extends: [
|
|
36
|
+
"stylelint-config-standard-less",
|
|
37
|
+
"stylelint-config-standard-scss",
|
|
38
|
+
"@stylistic/stylelint-config",
|
|
39
|
+
],
|
|
40
|
+
|
|
41
|
+
// reconfigure linter rules
|
|
42
|
+
rules: {
|
|
43
|
+
|
|
44
|
+
"at-rule-empty-line-before": null,
|
|
45
|
+
"color-function-notation": ["modern", { ignore: ["with-var-inside"] }],
|
|
46
|
+
"color-hex-length": null,
|
|
47
|
+
"custom-property-empty-line-before": null,
|
|
48
|
+
"declaration-block-no-redundant-longhand-properties": [true, { ignoreShorthands: ["inset"] }], // Safari does not support "inset"
|
|
49
|
+
"declaration-block-single-line-max-declarations": null,
|
|
50
|
+
"declaration-empty-line-before": null,
|
|
51
|
+
"function-url-no-scheme-relative": true,
|
|
52
|
+
"function-url-scheme-allowed-list": ["data"],
|
|
53
|
+
"media-feature-range-notation": null, // Safari 16.3 does not work with this notation
|
|
54
|
+
"no-descending-specificity": null,
|
|
55
|
+
"property-no-vendor-prefix": null,
|
|
56
|
+
"rule-empty-line-before": null,
|
|
57
|
+
|
|
58
|
+
...(options?.license ? { "plugin/license-header": [true, { license: options.license }] } : null),
|
|
59
|
+
|
|
60
|
+
"scss/double-slash-comment-empty-line-before": null,
|
|
61
|
+
|
|
62
|
+
"@stylistic/declaration-colon-newline-after": null,
|
|
63
|
+
"@stylistic/indentation": [stylistic.indent, { ignore: ["inside-parens"] }],
|
|
64
|
+
"@stylistic/max-line-length": null,
|
|
65
|
+
"@stylistic/selector-list-comma-newline-after": null,
|
|
66
|
+
"@stylistic/string-quotes": (stylistic.quotes === "off") ? null : [stylistic.quotes, { avoidEscape: true }],
|
|
67
|
+
|
|
68
|
+
...options?.rules,
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
// check inline directives
|
|
72
|
+
reportDescriptionlessDisables: null,
|
|
73
|
+
reportInvalidScopeDisables: true,
|
|
74
|
+
reportNeedlessDisables: true,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
import { Config } from "stylelint";
|
|
3
|
+
|
|
4
|
+
// types ======================================================================
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for code style.
|
|
8
|
+
*/
|
|
9
|
+
export interface StylisticOptions {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Default indentation size (number of space characters). Default value is
|
|
13
|
+
* `2`.
|
|
14
|
+
*/
|
|
15
|
+
indent?: number;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The type of the string delimiter character. Default value is "single".
|
|
19
|
+
*/
|
|
20
|
+
quotes?: "single" | "double" | "off";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// ----------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Configuration options for linting the entire project.
|
|
27
|
+
*/
|
|
28
|
+
export interface StyleLintConfigureOptions {
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Glob patterns with all files and folders to be ignored by StyleLint.
|
|
32
|
+
*/
|
|
33
|
+
ignores?: readonly string[];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Configuration options for code style.
|
|
37
|
+
*/
|
|
38
|
+
stylistic?: StylisticOptions;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Additional linter rules to be added to the global configuration.
|
|
42
|
+
*/
|
|
43
|
+
rules?: Config["rules"];
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-xchange/linter-presets",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Configuration presets for ESLint and StyleLint",
|
|
5
5
|
"repository": "https://gitlab.open-xchange.com/fspd/npm-packages/linter-presets",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,13 +23,15 @@
|
|
|
23
23
|
"@eslint/js": "9.6.0",
|
|
24
24
|
"@stylistic/eslint-plugin": "2.3.0",
|
|
25
25
|
"@stylistic/eslint-plugin-migrate": "2.3.0",
|
|
26
|
+
"@stylistic/stylelint-config": "1.0.1",
|
|
27
|
+
"@stylistic/stylelint-plugin": "2.1.2",
|
|
26
28
|
"confusing-browser-globals": "1.0.11",
|
|
27
29
|
"eslint-plugin-chai-expect": "3.1.0",
|
|
28
30
|
"eslint-plugin-codeceptjs": "1.3.0",
|
|
29
31
|
"eslint-plugin-eslint-plugin": "6.2.0",
|
|
30
32
|
"eslint-plugin-jest": "28.6.0",
|
|
31
33
|
"eslint-plugin-jest-dom": "5.4.0",
|
|
32
|
-
"eslint-plugin-jsdoc": "48.5.
|
|
34
|
+
"eslint-plugin-jsdoc": "48.5.2",
|
|
33
35
|
"eslint-plugin-jsonc": "2.16.0",
|
|
34
36
|
"eslint-plugin-jsx-a11y": "6.9.0",
|
|
35
37
|
"eslint-plugin-jsx-expressions": "1.3.2",
|
|
@@ -44,15 +46,22 @@
|
|
|
44
46
|
"eslint-plugin-vitest": "0.5.4",
|
|
45
47
|
"eslint-plugin-yml": "1.14.0",
|
|
46
48
|
"globals": "15.8.0",
|
|
49
|
+
"stylelint-config-standard": "36.0.1",
|
|
50
|
+
"stylelint-config-standard-less": "3.0.1",
|
|
51
|
+
"stylelint-config-standard-scss": "13.1.0",
|
|
52
|
+
"stylelint-plugin-license-header": "1.0.3",
|
|
47
53
|
"typescript-eslint": "7.15.0"
|
|
48
54
|
},
|
|
49
55
|
"devDependencies": {
|
|
50
56
|
"eslint": "9.6.0",
|
|
51
57
|
"husky": "9.0.11",
|
|
58
|
+
"lint-staged": "15.2.7",
|
|
59
|
+
"stylelint": "16.6.1",
|
|
52
60
|
"typescript": "5.5.3"
|
|
53
61
|
},
|
|
54
62
|
"peerDependencies": {
|
|
55
63
|
"eslint": "^9.6.0",
|
|
64
|
+
"stylelint": "^16.6.1",
|
|
56
65
|
"typescript": "^5.5.3"
|
|
57
66
|
},
|
|
58
67
|
"resolutions": {
|