@open-xchange/linter-presets 0.0.6 → 0.1.0
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 +19 -14
- package/README.md +3 -3
- package/dist/eslint/config/base.d.ts +16 -0
- package/{lib → dist}/eslint/config/base.js +5 -26
- package/dist/eslint/config/directives.d.ts +11 -0
- package/{lib → dist}/eslint/config/directives.js +1 -5
- package/dist/eslint/config/imports.d.ts +15 -0
- package/dist/eslint/config/imports.js +58 -0
- package/dist/eslint/config/js.d.ts +9 -0
- package/dist/eslint/config/js.js +32 -0
- package/dist/eslint/config/jsdoc.d.ts +11 -0
- package/{lib → dist}/eslint/config/jsdoc.js +1 -9
- package/dist/eslint/config/json.d.ts +15 -0
- package/{lib → dist}/eslint/config/json.js +2 -8
- package/dist/eslint/config/license.d.ts +14 -0
- package/{lib → dist}/eslint/config/license.js +12 -18
- package/dist/eslint/config/promises.d.ts +11 -0
- package/{lib → dist}/eslint/config/promises.js +3 -9
- package/dist/eslint/config/stylistic.d.ts +16 -0
- package/{lib → dist}/eslint/config/stylistic.js +12 -22
- package/dist/eslint/config/ts.d.ts +11 -0
- package/{lib → dist}/eslint/config/ts.js +9 -18
- package/dist/eslint/config/yaml.d.ts +15 -0
- package/{lib → dist}/eslint/config/yaml.js +2 -8
- package/dist/eslint/env/browser.d.ts +27 -0
- package/{lib → dist}/eslint/env/browser.js +5 -26
- package/dist/eslint/env/codecept.d.ts +22 -0
- package/{lib → dist}/eslint/env/codecept.js +4 -13
- package/dist/eslint/env/eslint.d.ts +20 -0
- package/{lib → dist}/eslint/env/eslint.js +2 -9
- package/dist/eslint/env/jest.d.ts +21 -0
- package/dist/eslint/env/jest.js +49 -0
- package/dist/eslint/env/node.d.ts +30 -0
- package/{lib → dist}/eslint/env/node.js +2 -14
- package/dist/eslint/env/project.d.ts +18 -0
- package/{lib → dist}/eslint/env/project.js +18 -25
- package/dist/eslint/env/react.d.ts +29 -0
- package/{lib → dist}/eslint/env/react.js +3 -15
- package/dist/eslint/env/tsconfig.d.ts +21 -0
- package/{lib → dist}/eslint/env/tsconfig.js +15 -21
- package/dist/eslint/env/vitest.d.ts +23 -0
- package/{lib → dist}/eslint/env/vitest.js +3 -16
- package/dist/eslint/index.d.ts +63 -0
- package/{lib → dist}/eslint/index.js +3 -25
- package/dist/eslint/rules/no-amd-module-directive.d.ts +3 -0
- package/{lib → dist}/eslint/rules/no-amd-module-directive.js +22 -26
- package/dist/eslint/rules/no-invalid-modules.d.ts +38 -0
- package/{lib → dist}/eslint/rules/no-invalid-modules.js +40 -63
- package/dist/eslint/shared/env-utils.d.ts +150 -0
- package/{lib → dist}/eslint/shared/env-utils.js +12 -23
- package/dist/eslint/shared/rule-utils.d.ts +76 -0
- package/{lib → dist}/eslint/shared/rule-utils.js +27 -60
- package/dist/index.d.ts +3 -0
- package/{lib → dist}/index.js +0 -1
- package/dist/stylelint/index.d.ts +49 -0
- package/{lib → dist}/stylelint/index.js +5 -22
- package/dist/utils/index.d.ts +12 -0
- package/{lib → dist}/utils/index.js +2 -5
- package/package.json +12 -4
- package/lib/eslint/config/imports.js +0 -68
- package/lib/eslint/config/js.js +0 -36
- package/lib/eslint/env/browser.d.ts +0 -21
- package/lib/eslint/env/codecept.d.ts +0 -14
- package/lib/eslint/env/eslint.d.ts +0 -14
- package/lib/eslint/env/jest.d.ts +0 -14
- package/lib/eslint/env/jest.js +0 -56
- package/lib/eslint/env/node.d.ts +0 -28
- package/lib/eslint/env/project.d.ts +0 -21
- package/lib/eslint/env/react.d.ts +0 -20
- package/lib/eslint/env/tsconfig.d.ts +0 -20
- package/lib/eslint/env/vitest.d.ts +0 -14
- package/lib/eslint/index.d.ts +0 -43
- package/lib/eslint/shared/env-utils.d.ts +0 -95
- package/lib/eslint/shared/types.d.ts +0 -107
- package/lib/index.d.ts +0 -4
- package/lib/stylelint/index.d.ts +0 -18
- package/lib/stylelint/types.d.ts +0 -44
- package/lib/utils/index.d.ts +0 -4
- /package/{lib → doc}/eslint/README.md +0 -0
- /package/{lib → doc}/eslint/env/browser.md +0 -0
- /package/{lib → doc}/eslint/env/codecept.md +0 -0
- /package/{lib → doc}/eslint/env/eslint.md +0 -0
- /package/{lib → doc}/eslint/env/jest.md +0 -0
- /package/{lib → doc}/eslint/env/node.md +0 -0
- /package/{lib → doc}/eslint/env/project.md +0 -0
- /package/{lib → doc}/eslint/env/react.md +0 -0
- /package/{lib → doc}/eslint/env/tsconfig.md +0 -0
- /package/{lib → doc}/eslint/env/vitest.md +0 -0
- /package/{lib → doc}/stylelint/README.md +0 -0
- /package/{lib → doc}/utils/README.md +0 -0
|
@@ -18,145 +18,112 @@
|
|
|
18
18
|
* Any use of the work other than as authorized under this license or copyright law is prohibited.
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
|
-
|
|
22
21
|
import { posix, sep } from "node:path";
|
|
23
22
|
import { lstatSync } from "node:fs";
|
|
24
|
-
|
|
25
23
|
import pm from "picomatch";
|
|
26
|
-
|
|
24
|
+
import { AST_NODE_TYPES as NodeType } from "@typescript-eslint/utils";
|
|
27
25
|
// Schema =====================================================================
|
|
28
|
-
|
|
29
26
|
/**
|
|
30
27
|
* Helper functions to build a JSON schema for custom ESLint rules.
|
|
31
28
|
*/
|
|
32
29
|
export const Schema = {
|
|
33
|
-
|
|
34
30
|
boolean() {
|
|
35
31
|
return { type: "boolean" };
|
|
36
32
|
},
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return { type: "string", ...options };
|
|
33
|
+
string() {
|
|
34
|
+
return { type: "string" };
|
|
40
35
|
},
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return Schema.string({ minLength: 1, ...options });
|
|
36
|
+
stringNE() {
|
|
37
|
+
return { type: "string", minLength: 1 };
|
|
44
38
|
},
|
|
45
|
-
|
|
46
39
|
array(items) {
|
|
47
40
|
return { type: "array", items, uniqueItems: true };
|
|
48
41
|
},
|
|
49
|
-
|
|
50
42
|
maybeArray(items) {
|
|
51
43
|
return { oneOf: [items, Schema.array(items)] };
|
|
52
44
|
},
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return { type: "object", additionalProperties: items };
|
|
45
|
+
dictionary(properties) {
|
|
46
|
+
return { type: "object", additionalProperties: properties };
|
|
56
47
|
},
|
|
57
|
-
|
|
58
48
|
options(properties, required) {
|
|
59
49
|
return { type: "object", properties, required, additionalProperties: false };
|
|
60
50
|
},
|
|
61
51
|
};
|
|
62
|
-
|
|
63
52
|
// functions ==================================================================
|
|
64
|
-
|
|
65
53
|
/**
|
|
66
|
-
* Returns
|
|
54
|
+
* Returns a passed array unmodified, converts the value `undefined` to an
|
|
55
|
+
* empty array, and converts all other values to an array with one element.
|
|
67
56
|
*
|
|
68
|
-
* @param
|
|
69
|
-
* The value to be checked.
|
|
70
|
-
*
|
|
71
|
-
* @returns {boolean}
|
|
72
|
-
* Whether the passed value is nullish (either `undefined` or `null`).
|
|
73
|
-
*/
|
|
74
|
-
export function isNullish(value) {
|
|
75
|
-
return (value === undefined) || (value === null);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Returns a passed array unmodified, converts nullish values to an empty
|
|
80
|
-
* array, and converts all other values to an array with one element.
|
|
81
|
-
*
|
|
82
|
-
* @param {unknown} value
|
|
57
|
+
* @param value
|
|
83
58
|
* Any value to be converted to an array.
|
|
84
59
|
*
|
|
85
|
-
* @returns
|
|
60
|
+
* @returns
|
|
86
61
|
* An array containing the value, unless the value is already an array.
|
|
87
62
|
*/
|
|
88
63
|
export function makeArray(value) {
|
|
89
|
-
return Array.isArray(value) ? value :
|
|
64
|
+
return Array.isArray(value) ? value : (value === undefined) ? [] : [value];
|
|
90
65
|
}
|
|
91
|
-
|
|
92
66
|
/**
|
|
93
67
|
* Converts a Windows file path to a Posix file path.
|
|
94
68
|
*
|
|
95
|
-
* @param
|
|
69
|
+
* @param path
|
|
96
70
|
* The file path to be normalized to Posix format.
|
|
97
71
|
*
|
|
98
|
-
* @returns
|
|
72
|
+
* @returns
|
|
99
73
|
* The normalized Posix file path.
|
|
100
74
|
*/
|
|
101
75
|
export function toPosixPath(path) {
|
|
102
76
|
return path.replaceAll(sep, posix.sep);
|
|
103
77
|
}
|
|
104
|
-
|
|
105
78
|
/**
|
|
106
79
|
* Returns whether the passed path refers to an existing file.
|
|
107
80
|
*
|
|
108
|
-
* @param
|
|
81
|
+
* @param path
|
|
109
82
|
* The path to be checked.
|
|
110
83
|
*
|
|
111
|
-
* @returns
|
|
84
|
+
* @returns
|
|
112
85
|
* Whether the passed path refers to an existing file (returns `false` for
|
|
113
86
|
* existing directories).
|
|
114
87
|
*/
|
|
115
88
|
export function isFile(path) {
|
|
116
89
|
try {
|
|
117
90
|
return lstatSync(path).isFile();
|
|
118
|
-
}
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
119
93
|
return false;
|
|
120
94
|
}
|
|
121
95
|
}
|
|
122
|
-
|
|
123
96
|
/**
|
|
124
97
|
* Returns whether a module name matches the specified glob patterns.
|
|
125
98
|
*
|
|
126
|
-
* @param
|
|
99
|
+
* @param moduleName
|
|
127
100
|
* The module name to be checked.
|
|
128
101
|
*
|
|
129
|
-
* @param
|
|
102
|
+
* @param patterns
|
|
130
103
|
* The glob patterns to be matched against the module name.
|
|
131
104
|
*
|
|
132
|
-
* @returns
|
|
105
|
+
* @returns
|
|
133
106
|
* Whether the module name matches at least one glob pattern.
|
|
134
107
|
*/
|
|
135
108
|
export const matchModuleName = pm.isMatch;
|
|
136
|
-
|
|
137
109
|
/**
|
|
138
110
|
* Extracts the source node and module name of an import/export statement node,
|
|
139
111
|
* or a dynamic import expression node.
|
|
140
112
|
*
|
|
141
|
-
* @
|
|
142
|
-
*
|
|
143
|
-
* @param {Node} node
|
|
113
|
+
* @param node
|
|
144
114
|
* The import/export statement node, or dynamic import expression node.
|
|
145
115
|
*
|
|
146
|
-
* @returns
|
|
116
|
+
* @returns
|
|
147
117
|
* The string literal node containing the module name, and the resulting
|
|
148
118
|
* extracted module name.
|
|
149
119
|
*/
|
|
150
120
|
export function getModuleName(node) {
|
|
151
|
-
|
|
152
121
|
// TSExternalModuleReference: module name in property "expression", otherwise "source"
|
|
153
|
-
const
|
|
154
|
-
|
|
122
|
+
const sourceNodeRaw = (node.type === NodeType.TSExternalModuleReference) ? node.expression : node.source;
|
|
155
123
|
// module name is expected to be a string literal
|
|
156
|
-
const isStringLiteral = (
|
|
157
|
-
|
|
124
|
+
const isStringLiteral = (sourceNodeRaw?.type === NodeType.Literal) && (typeof sourceNodeRaw.value === "string");
|
|
125
|
+
const sourceNode = isStringLiteral ? sourceNodeRaw : undefined;
|
|
158
126
|
// strip URL query strings from module name
|
|
159
|
-
const moduleName =
|
|
160
|
-
|
|
127
|
+
const moduleName = sourceNode ? sourceNode.value.replace(/\?.*$/, "") : "";
|
|
161
128
|
return { sourceNode, moduleName };
|
|
162
129
|
}
|
package/dist/index.d.ts
ADDED
package/{lib → dist}/index.js
RENAMED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Config } from "stylelint";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for StyleLint code style rules.
|
|
4
|
+
*/
|
|
5
|
+
export interface StylisticOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Default indentation size (number of space characters). Default value is
|
|
8
|
+
* `2`.
|
|
9
|
+
*/
|
|
10
|
+
indent?: number;
|
|
11
|
+
/**
|
|
12
|
+
* The type of the string delimiter character. Default value is "single".
|
|
13
|
+
*/
|
|
14
|
+
quotes?: "single" | "double" | "off";
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Configuration options for linting the entire project with StyleLint.
|
|
18
|
+
*/
|
|
19
|
+
export interface ConfigureOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Glob patterns with all files and folders to be ignored by StyleLint.
|
|
22
|
+
*/
|
|
23
|
+
ignores?: string[];
|
|
24
|
+
/**
|
|
25
|
+
* Full path to the template file containing the license header to be used
|
|
26
|
+
* in all source files. The function `resolver` helps to to convert a local
|
|
27
|
+
* path to an absolute path.
|
|
28
|
+
*/
|
|
29
|
+
license?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Configuration options for code style.
|
|
32
|
+
*/
|
|
33
|
+
stylistic?: StylisticOptions;
|
|
34
|
+
/**
|
|
35
|
+
* Additional linter rules to be added to the global configuration.
|
|
36
|
+
*/
|
|
37
|
+
rules?: Config["rules"];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Generates a StyleLint configuration object targeting the source files in the
|
|
41
|
+
* entire project.
|
|
42
|
+
*
|
|
43
|
+
* @param options
|
|
44
|
+
* Plugin configuration options.
|
|
45
|
+
*
|
|
46
|
+
* @returns
|
|
47
|
+
* The configuration object to be exported from `stylelint.config.js`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function configure(options?: ConfigureOptions): Config;
|
|
@@ -1,55 +1,44 @@
|
|
|
1
|
-
|
|
2
1
|
// functions ==================================================================
|
|
3
|
-
|
|
4
2
|
/**
|
|
5
|
-
* Generates
|
|
3
|
+
* Generates a StyleLint configuration object targeting the source files in the
|
|
6
4
|
* entire project.
|
|
7
5
|
*
|
|
8
|
-
* @param
|
|
6
|
+
* @param options
|
|
9
7
|
* Plugin configuration options.
|
|
10
8
|
*
|
|
11
|
-
* @returns
|
|
9
|
+
* @returns
|
|
12
10
|
* The configuration object to be exported from `stylelint.config.js`.
|
|
13
11
|
*/
|
|
14
12
|
export function configure(options) {
|
|
15
|
-
|
|
16
13
|
// resolve stylistic configuration options
|
|
17
14
|
const stylistic = {
|
|
18
15
|
indent: 2,
|
|
19
16
|
quotes: "single",
|
|
20
17
|
...options?.stylistic,
|
|
21
18
|
};
|
|
22
|
-
|
|
23
|
-
// group custom rules by language plugins
|
|
24
19
|
const rules = { base: {}, scss: {}, less: {} };
|
|
25
20
|
for (const [rule, value] of Object.entries(options?.rules ?? {})) {
|
|
26
|
-
|
|
21
|
+
const key = rule.split("/")[0];
|
|
22
|
+
(rules[key] ?? rules.base)[rule] = value;
|
|
27
23
|
}
|
|
28
|
-
|
|
29
24
|
return {
|
|
30
|
-
|
|
31
25
|
// ignore certain files and folders
|
|
32
26
|
ignoreFiles: options?.ignores ?? [],
|
|
33
|
-
|
|
34
27
|
// add the stylistic plugin
|
|
35
28
|
plugins: [
|
|
36
29
|
"stylelint-plugin-license-header",
|
|
37
30
|
"@stylistic/stylelint-plugin",
|
|
38
31
|
],
|
|
39
|
-
|
|
40
32
|
// add recommended configurations
|
|
41
33
|
extends: [
|
|
42
34
|
"@stylistic/stylelint-config",
|
|
43
35
|
],
|
|
44
|
-
|
|
45
36
|
// check inline directives
|
|
46
37
|
reportDescriptionlessDisables: null,
|
|
47
38
|
reportInvalidScopeDisables: true,
|
|
48
39
|
reportNeedlessDisables: true,
|
|
49
|
-
|
|
50
40
|
// reconfigure linter rules
|
|
51
41
|
rules: {
|
|
52
|
-
|
|
53
42
|
// core rules
|
|
54
43
|
"at-rule-empty-line-before": null,
|
|
55
44
|
"color-function-notation": ["modern", { ignore: ["with-var-inside"] }],
|
|
@@ -65,24 +54,19 @@ export function configure(options) {
|
|
|
65
54
|
"no-descending-specificity": null,
|
|
66
55
|
"no-unknown-animations": true,
|
|
67
56
|
"rule-empty-line-before": null,
|
|
68
|
-
|
|
69
57
|
// license-header plugin
|
|
70
58
|
...(options?.license ? { "plugin/license-header": [true, { license: options.license }] } : null),
|
|
71
|
-
|
|
72
59
|
// stylistic plugin
|
|
73
60
|
"@stylistic/declaration-colon-newline-after": null,
|
|
74
61
|
"@stylistic/indentation": [stylistic.indent, { ignore: ["inside-parens"] }],
|
|
75
62
|
"@stylistic/max-line-length": null,
|
|
76
63
|
"@stylistic/selector-list-comma-newline-after": null,
|
|
77
64
|
"@stylistic/string-quotes": (stylistic.quotes === "off") ? null : [stylistic.quotes, { avoidEscape: true }],
|
|
78
|
-
|
|
79
65
|
// custom rules
|
|
80
66
|
...rules.base,
|
|
81
67
|
},
|
|
82
|
-
|
|
83
68
|
// overrides for custom languages
|
|
84
69
|
overrides: [
|
|
85
|
-
|
|
86
70
|
// SCSS files
|
|
87
71
|
{
|
|
88
72
|
files: ["**/*.scss"],
|
|
@@ -92,7 +76,6 @@ export function configure(options) {
|
|
|
92
76
|
...rules.scss,
|
|
93
77
|
},
|
|
94
78
|
},
|
|
95
|
-
|
|
96
79
|
// LESS files
|
|
97
80
|
{
|
|
98
81
|
files: ["**/*.less"],
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type FileResolveFn = (file: string) => string;
|
|
2
|
+
/**
|
|
3
|
+
* Creates and returns a resolver function for file paths relative to the given
|
|
4
|
+
* base URL of a script file.
|
|
5
|
+
*
|
|
6
|
+
* @param url
|
|
7
|
+
* The base URL of the calling script, usually `import.meta.url`.
|
|
8
|
+
*
|
|
9
|
+
* @returns
|
|
10
|
+
* A function that converts relative file paths to absolute file paths.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolver(url: string): FileResolveFn;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
1
|
import { URL, fileURLToPath } from "node:url";
|
|
3
|
-
|
|
4
2
|
// functions ==================================================================
|
|
5
|
-
|
|
6
3
|
/**
|
|
7
4
|
* Creates and returns a resolver function for file paths relative to the given
|
|
8
5
|
* base URL of a script file.
|
|
9
6
|
*
|
|
10
|
-
* @param
|
|
7
|
+
* @param url
|
|
11
8
|
* The base URL of the calling script, usually `import.meta.url`.
|
|
12
9
|
*
|
|
13
|
-
* @returns
|
|
10
|
+
* @returns
|
|
14
11
|
* A function that converts relative file paths to absolute file paths.
|
|
15
12
|
*/
|
|
16
13
|
export function resolver(url) {
|
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-xchange/linter-presets",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Configuration presets for ESLint and StyleLint",
|
|
5
|
-
"repository":
|
|
5
|
+
"repository": {
|
|
6
|
+
"url": "https://gitlab.open-xchange.com/fspd/npm-packages/linter-presets"
|
|
7
|
+
},
|
|
6
8
|
"license": "MIT",
|
|
7
9
|
"engines": {
|
|
8
10
|
"node": ">=18"
|
|
9
11
|
},
|
|
10
12
|
"packageManager": "yarn@4.3.1",
|
|
11
13
|
"type": "module",
|
|
12
|
-
"exports": "./
|
|
14
|
+
"exports": "./dist/index.js",
|
|
13
15
|
"scripts": {
|
|
14
16
|
"prepare": "husky",
|
|
17
|
+
"prepack": "yarn lint && yarn build",
|
|
18
|
+
"build": "npx --yes rimraf dist && tsc",
|
|
15
19
|
"lint": "eslint ."
|
|
16
20
|
},
|
|
17
21
|
"lint-staged": {
|
|
@@ -56,7 +60,11 @@
|
|
|
56
60
|
"typescript-eslint": "7.16.0"
|
|
57
61
|
},
|
|
58
62
|
"devDependencies": {
|
|
59
|
-
"@types/
|
|
63
|
+
"@types/confusing-browser-globals": "1.0.3",
|
|
64
|
+
"@types/eslint__js": "8.42.3",
|
|
65
|
+
"@types/json-schema": "7.0.15",
|
|
66
|
+
"@types/picomatch": "3.0.0",
|
|
67
|
+
"@typescript-eslint/utils": "7.16.0",
|
|
60
68
|
"eslint": "9.6.0",
|
|
61
69
|
"husky": "9.0.11",
|
|
62
70
|
"jest": "29.7.0",
|
|
@@ -1,68 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { NO_UNUSED_VARS_OPTIONS } from "../shared/env-utils.js";
|
|
3
|
-
|
|
4
|
-
// functions ==================================================================
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Defines additional standard rules targeting JavaScript but _not_ TypeScript
|
|
8
|
-
* source files.
|
|
9
|
-
*
|
|
10
|
-
* @returns {import("../shared/types.js").FlatConfigArray}
|
|
11
|
-
* An array of configuration objects to be added to the flat configuration.
|
|
12
|
-
*/
|
|
13
|
-
export default function js() {
|
|
14
|
-
|
|
15
|
-
return [{
|
|
16
|
-
files: ["**/*.{js,jsx,cjs,mjs}"],
|
|
17
|
-
rules: {
|
|
18
|
-
// possible problems
|
|
19
|
-
"no-duplicate-imports": "error",
|
|
20
|
-
"no-loss-of-precision": "off",
|
|
21
|
-
"no-unused-vars": ["error", NO_UNUSED_VARS_OPTIONS],
|
|
22
|
-
// suggestions
|
|
23
|
-
"default-param-last": "error",
|
|
24
|
-
"dot-notation": "error",
|
|
25
|
-
"no-array-constructor": "error",
|
|
26
|
-
"no-invalid-this": "error",
|
|
27
|
-
"no-loop-func": "error",
|
|
28
|
-
"no-redeclare": "error",
|
|
29
|
-
"no-shadow": ["error", { ignoreOnInitialization: true }],
|
|
30
|
-
"no-throw-literal": "error",
|
|
31
|
-
"no-useless-constructor": "error",
|
|
32
|
-
"prefer-promise-reject-errors": "error",
|
|
33
|
-
"require-await": "error",
|
|
34
|
-
},
|
|
35
|
-
}];
|
|
36
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { FlatConfigArray } from "../shared/types";
|
|
3
|
-
import { EnvBaseOptions, EnvRestrictedOptions } from "../shared/env-utils";
|
|
4
|
-
|
|
5
|
-
// types ======================================================================
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Configuration options for the environment preset "env.browser".
|
|
9
|
-
*/
|
|
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
|
-
}
|
|
18
|
-
|
|
19
|
-
// functions ==================================================================
|
|
20
|
-
|
|
21
|
-
export default function browser(options: EnvBrowserOptions): FlatConfigArray;
|
|
@@ -1,14 +0,0 @@
|
|
|
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.codecept".
|
|
9
|
-
*/
|
|
10
|
-
export interface EnvCodeceptOptions extends EnvBaseOptions { }
|
|
11
|
-
|
|
12
|
-
// functions ==================================================================
|
|
13
|
-
|
|
14
|
-
export default function codecept(options: EnvCodeceptOptions): FlatConfigArray;
|
|
@@ -1,14 +0,0 @@
|
|
|
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;
|
package/lib/eslint/env/jest.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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.jest".
|
|
9
|
-
*/
|
|
10
|
-
export interface EnvJestOptions extends EnvBaseOptions { }
|
|
11
|
-
|
|
12
|
-
// functions ==================================================================
|
|
13
|
-
|
|
14
|
-
export default function jest(options: EnvJestOptions): FlatConfigArray;
|
package/lib/eslint/env/jest.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import jestPlugin from "eslint-plugin-jest";
|
|
3
|
-
|
|
4
|
-
// functions ==================================================================
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Creates configuration objects with global symbols and linter rules for unit
|
|
8
|
-
* tests using Jest.
|
|
9
|
-
*
|
|
10
|
-
* Wraps the following packages:
|
|
11
|
-
* - `eslint-plugin-jest`
|
|
12
|
-
*
|
|
13
|
-
* @param {import("./jest").EnvJestOptions} options
|
|
14
|
-
* Configuration options for the environment.
|
|
15
|
-
*
|
|
16
|
-
* @returns {import("../shared/types").FlatConfigArray}
|
|
17
|
-
* An array of configuration objects to be added to the flat configuration.
|
|
18
|
-
*/
|
|
19
|
-
export default function jest(options) {
|
|
20
|
-
|
|
21
|
-
// config properties
|
|
22
|
-
const { files, ignores = [], rules } = options;
|
|
23
|
-
|
|
24
|
-
return [{
|
|
25
|
-
files,
|
|
26
|
-
ignores,
|
|
27
|
-
|
|
28
|
-
// register rule implementations, globals
|
|
29
|
-
...jestPlugin.configs["flat/recommended"],
|
|
30
|
-
|
|
31
|
-
// configure plugin rules
|
|
32
|
-
rules: {
|
|
33
|
-
// recommended rules
|
|
34
|
-
...jestPlugin.configs["flat/recommended"].rules,
|
|
35
|
-
...jestPlugin.configs["flat/style"].rules,
|
|
36
|
-
// extra rules
|
|
37
|
-
"jest/consistent-test-it": ["error", { fn: "it" }],
|
|
38
|
-
"jest/no-commented-out-tests": "error",
|
|
39
|
-
"jest/no-conditional-expect": "off",
|
|
40
|
-
"jest/no-confusing-set-timeout": "error",
|
|
41
|
-
"jest/no-duplicate-hooks": "error",
|
|
42
|
-
"jest/no-test-return-statement": "error",
|
|
43
|
-
"jest/prefer-comparison-matcher": "error",
|
|
44
|
-
"jest/prefer-equality-matcher": "error",
|
|
45
|
-
"jest/prefer-expect-resolves": "error",
|
|
46
|
-
"jest/prefer-hooks-on-top": "error",
|
|
47
|
-
"jest/prefer-lowercase-title": "error",
|
|
48
|
-
"jest/prefer-mock-promise-shorthand": "error",
|
|
49
|
-
"jest/prefer-spy-on": "error",
|
|
50
|
-
"jest/prefer-todo": "error",
|
|
51
|
-
"jest/require-top-level-describe": "error",
|
|
52
|
-
// custom rules
|
|
53
|
-
...rules,
|
|
54
|
-
},
|
|
55
|
-
}];
|
|
56
|
-
}
|
package/lib/eslint/env/node.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { FlatConfigArray, LanguageOptions } from "../shared/types";
|
|
3
|
-
import { EnvBaseOptions, EnvRestrictedOptions } from "../shared/env-utils";
|
|
4
|
-
|
|
5
|
-
// types ======================================================================
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Configuration options for the environment preset "env.node".
|
|
9
|
-
*/
|
|
10
|
-
export interface EnvNodeOptions extends EnvBaseOptions {
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The module mode used by the linted files.
|
|
14
|
-
*
|
|
15
|
-
* Default value is "module".
|
|
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;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// functions ==================================================================
|
|
27
|
-
|
|
28
|
-
export default function node(options: EnvNodeOptions): FlatConfigArray;
|