@nextcloud/eslint-config 9.0.0-rc.0 → 9.0.0-rc.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 +80 -40
- package/README.md +142 -29
- package/dist/configs/codeStyle.d.ts +13 -0
- package/dist/configs/codeStyle.js +184 -0
- package/dist/configs/documentation.d.ts +12 -0
- package/dist/configs/documentation.js +123 -0
- package/dist/configs/filesystem.d.ts +9 -0
- package/dist/configs/filesystem.js +20 -0
- package/dist/configs/imports.d.ts +12 -0
- package/dist/configs/imports.js +114 -0
- package/dist/configs/javascript.d.ts +14 -0
- package/dist/configs/javascript.js +118 -0
- package/dist/configs/json.d.ts +9 -0
- package/dist/configs/json.js +45 -0
- package/dist/configs/node.d.ts +10 -0
- package/dist/configs/node.js +24 -0
- package/dist/configs/typescript.d.ts +12 -0
- package/dist/configs/typescript.js +60 -0
- package/dist/configs/vue.d.ts +12 -0
- package/dist/configs/vue.js +152 -0
- package/dist/configs/vue2.d.ts +12 -0
- package/dist/configs/vue2.js +30 -0
- package/dist/configs/vue3.d.ts +12 -0
- package/dist/configs/vue3.js +26 -0
- package/dist/globs.d.ts +20 -0
- package/dist/globs.js +39 -0
- package/dist/index.d.ts +27 -31
- package/dist/index.js +78 -0
- package/dist/plugins/l10n/index.d.ts +10 -0
- package/dist/plugins/l10n/index.js +17 -0
- package/dist/plugins/l10n/rules/enforce-ellipsis.d.ts +7 -0
- package/dist/plugins/l10n/rules/enforce-ellipsis.js +32 -0
- package/dist/plugins/l10n/rules/non-breaking-space.d.ts +7 -0
- package/dist/plugins/l10n/rules/non-breaking-space.js +30 -0
- package/dist/plugins/nextcloud/index.d.ts +7 -0
- package/dist/plugins/nextcloud/index.js +9 -0
- package/dist/plugins/nextcloud/rules/index.d.ts +6 -0
- package/dist/plugins/nextcloud/rules/index.js +6 -0
- package/dist/plugins/nextcloud/rules/no-deprecations.d.ts +7 -0
- package/dist/plugins/nextcloud/rules/no-deprecations.js +196 -0
- package/dist/plugins/nextcloud/rules/no-removed-apis.d.ts +7 -0
- package/dist/plugins/nextcloud/rules/no-removed-apis.js +152 -0
- package/dist/plugins/nextcloud/utils/version-parser.d.ts +41 -0
- package/dist/plugins/nextcloud/utils/version-parser.js +106 -0
- package/dist/plugins/nextcloud-vue/index.d.ts +28 -0
- package/dist/plugins/nextcloud-vue/index.js +13 -0
- package/dist/plugins/nextcloud-vue/rules/index.d.ts +17 -0
- package/dist/plugins/nextcloud-vue/rules/index.js +10 -0
- package/dist/plugins/nextcloud-vue/rules/no-deprecated-exports.d.ts +7 -0
- package/dist/plugins/nextcloud-vue/rules/no-deprecated-exports.js +44 -0
- package/dist/plugins/nextcloud-vue/rules/no-deprecated-props.d.ts +20 -0
- package/dist/plugins/nextcloud-vue/rules/no-deprecated-props.js +61 -0
- package/dist/plugins/nextcloud-vue/utils/lib-version-parser.d.ts +33 -0
- package/dist/plugins/nextcloud-vue/utils/lib-version-parser.js +94 -0
- package/dist/plugins/packageJson.d.ts +10 -0
- package/dist/plugins/packageJson.js +66 -0
- package/dist/utils.d.ts +23 -0
- package/dist/utils.js +19 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +6 -0
- package/package.json +26 -22
- package/dist/index.mjs +0 -1464
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
|
3
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
*/
|
|
5
|
+
import type { Linter } from 'eslint';
|
|
6
|
+
import type { ConfigOptions } from '../types.d.ts';
|
|
7
|
+
/**
|
|
8
|
+
* Config factory for code documentation related rules (JSDoc)
|
|
9
|
+
*
|
|
10
|
+
* @param options options defining the config preset flavor
|
|
11
|
+
*/
|
|
12
|
+
export declare function documentation(options: ConfigOptions): Linter.Config[];
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import jsdocPlugin from 'eslint-plugin-jsdoc';
|
|
2
|
+
import { GLOB_FILES_JAVASCRIPT, GLOB_FILES_TESTING, GLOB_FILES_TYPESCRIPT, GLOB_FILES_VUE, } from "../globs.js";
|
|
3
|
+
const TS_FUNCTION_CONTEXTS = [
|
|
4
|
+
'FunctionDeclaration:has(TSTypeAnnotation)',
|
|
5
|
+
'FunctionExpression:has(TSTypeAnnotation)',
|
|
6
|
+
'ArrowFunctionExpression:has(TSTypeAnnotation)',
|
|
7
|
+
'MethodDefinition:has(TSTypeAnnotation)',
|
|
8
|
+
];
|
|
9
|
+
const JS_FUNCTION_CONTEXTS = [
|
|
10
|
+
'FunctionDeclaration:not(:has(TSTypeAnnotation))',
|
|
11
|
+
'FunctionExpression:not(:has(TSTypeAnnotation))',
|
|
12
|
+
'ArrowFunctionExpression:not(:has(TSTypeAnnotation))',
|
|
13
|
+
'MethodDefinition:not(:has(TSTypeAnnotation))',
|
|
14
|
+
];
|
|
15
|
+
/**
|
|
16
|
+
* Config factory for code documentation related rules (JSDoc)
|
|
17
|
+
*
|
|
18
|
+
* @param options options defining the config preset flavor
|
|
19
|
+
*/
|
|
20
|
+
export function documentation(options) {
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
files: [
|
|
24
|
+
...GLOB_FILES_JAVASCRIPT,
|
|
25
|
+
...GLOB_FILES_TYPESCRIPT,
|
|
26
|
+
...GLOB_FILES_VUE,
|
|
27
|
+
],
|
|
28
|
+
plugins: {
|
|
29
|
+
jsdoc: jsdocPlugin,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
...jsdocPlugin.configs['flat/recommended-typescript-flavor'],
|
|
34
|
+
files: [
|
|
35
|
+
...GLOB_FILES_JAVASCRIPT,
|
|
36
|
+
...(options.vueIsTypescript ? [] : GLOB_FILES_VUE),
|
|
37
|
+
],
|
|
38
|
+
settings: {
|
|
39
|
+
jsdoc: {
|
|
40
|
+
mode: 'permissive',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
ignores: GLOB_FILES_TESTING,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
...jsdocPlugin.configs['flat/recommended-typescript'],
|
|
47
|
+
files: [
|
|
48
|
+
...GLOB_FILES_TYPESCRIPT,
|
|
49
|
+
...(options.vueIsTypescript ? GLOB_FILES_VUE : []),
|
|
50
|
+
],
|
|
51
|
+
ignores: GLOB_FILES_TESTING,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'nextcloud/documentation/rules',
|
|
55
|
+
files: [
|
|
56
|
+
...GLOB_FILES_JAVASCRIPT,
|
|
57
|
+
...GLOB_FILES_TYPESCRIPT,
|
|
58
|
+
...GLOB_FILES_VUE,
|
|
59
|
+
],
|
|
60
|
+
ignores: GLOB_FILES_TESTING,
|
|
61
|
+
rules: {
|
|
62
|
+
// Force proper documentation
|
|
63
|
+
'jsdoc/check-tag-names': 'error',
|
|
64
|
+
// But ignore return values
|
|
65
|
+
'jsdoc/require-returns': 'off',
|
|
66
|
+
'jsdoc/require-returns-description': 'off',
|
|
67
|
+
// Allow one empty line in jsdoc blocks
|
|
68
|
+
'jsdoc/tag-lines': [
|
|
69
|
+
'warn',
|
|
70
|
+
'any',
|
|
71
|
+
{ startLines: 1 },
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
settings: {
|
|
75
|
+
jsdoc: {
|
|
76
|
+
// We use the alias for legacy reasons to prevent unnecessary noise
|
|
77
|
+
tagNamePreference: {
|
|
78
|
+
returns: 'return',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: 'nextcloud/documentation/rules-typescript',
|
|
85
|
+
files: [...GLOB_FILES_TYPESCRIPT],
|
|
86
|
+
ignores: GLOB_FILES_TESTING,
|
|
87
|
+
rules: {
|
|
88
|
+
// Overwrites for documentation as types are already provided by Typescript
|
|
89
|
+
'jsdoc/no-types': 'error',
|
|
90
|
+
'jsdoc/require-param-type': 'off',
|
|
91
|
+
'jsdoc/require-returns-type': 'off',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
...(options.vueIsTypescript
|
|
95
|
+
? [
|
|
96
|
+
{
|
|
97
|
+
name: 'nextcloud/documentation/rules-vue',
|
|
98
|
+
files: [...(options.vueIsTypescript ? GLOB_FILES_VUE : [])],
|
|
99
|
+
ignores: GLOB_FILES_TESTING,
|
|
100
|
+
rules: {
|
|
101
|
+
// Vue files can be both Javascript and Typescript
|
|
102
|
+
// Try to apply TS files only for functions with TS definitions
|
|
103
|
+
'jsdoc/no-types': [
|
|
104
|
+
'error',
|
|
105
|
+
{ contexts: TS_FUNCTION_CONTEXTS },
|
|
106
|
+
],
|
|
107
|
+
'jsdoc/require-param-type': [
|
|
108
|
+
'error',
|
|
109
|
+
{ contexts: JS_FUNCTION_CONTEXTS },
|
|
110
|
+
],
|
|
111
|
+
// Unlike params, return values are often inferred and not explicitly typed
|
|
112
|
+
'jsdoc/require-returns-type': 'off',
|
|
113
|
+
// Unfortunately, we cannot check when it is used in TS context and when not
|
|
114
|
+
'jsdoc/check-tag-names': [
|
|
115
|
+
'error',
|
|
116
|
+
{ typed: false },
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
]
|
|
121
|
+
: []),
|
|
122
|
+
];
|
|
123
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
|
3
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
*/
|
|
5
|
+
import type { Linter } from 'eslint';
|
|
6
|
+
/**
|
|
7
|
+
* General config to exclude known non-source directories from linting
|
|
8
|
+
*/
|
|
9
|
+
export declare const filesystem: Linter.Config[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
|
3
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* General config to exclude known non-source directories from linting
|
|
7
|
+
*/
|
|
8
|
+
export const filesystem = [
|
|
9
|
+
{
|
|
10
|
+
name: 'nextcloud/filesystem/ignores',
|
|
11
|
+
ignores: [
|
|
12
|
+
'**/dist',
|
|
13
|
+
'**/js',
|
|
14
|
+
'**/l10n',
|
|
15
|
+
'**/vendor',
|
|
16
|
+
'**/vendor-bin',
|
|
17
|
+
'**/package-lock.json',
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Linter } from 'eslint';
|
|
2
|
+
/*!
|
|
3
|
+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
|
4
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
5
|
+
*/
|
|
6
|
+
import type { ConfigOptions } from '../types.d.ts';
|
|
7
|
+
/**
|
|
8
|
+
* Generate imports and exports related ESLint rules.
|
|
9
|
+
*
|
|
10
|
+
* @param options - Configuration options
|
|
11
|
+
*/
|
|
12
|
+
export declare function imports(options: ConfigOptions): Linter.Config[];
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import perfectionist from 'eslint-plugin-perfectionist';
|
|
2
|
+
import { GLOB_FILES_JAVASCRIPT, GLOB_FILES_TYPESCRIPT, GLOB_FILES_VUE, } from "../globs.js";
|
|
3
|
+
/**
|
|
4
|
+
* Generate imports and exports related ESLint rules.
|
|
5
|
+
*
|
|
6
|
+
* @param options - Configuration options
|
|
7
|
+
*/
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
+
export function imports(options) {
|
|
10
|
+
return [
|
|
11
|
+
{
|
|
12
|
+
name: 'nextcloud/imports/setup',
|
|
13
|
+
plugins: {
|
|
14
|
+
perfectionist,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: 'nextcloud/imports/rules',
|
|
19
|
+
files: [
|
|
20
|
+
...GLOB_FILES_JAVASCRIPT,
|
|
21
|
+
...GLOB_FILES_TYPESCRIPT,
|
|
22
|
+
...GLOB_FILES_VUE,
|
|
23
|
+
],
|
|
24
|
+
rules: {
|
|
25
|
+
// Require file extensions
|
|
26
|
+
'no-restricted-imports': [
|
|
27
|
+
'error',
|
|
28
|
+
{
|
|
29
|
+
patterns: [
|
|
30
|
+
{
|
|
31
|
+
regex: '^(\\.*)/(.+/)*[^/.]+$',
|
|
32
|
+
message: 'Import is missing the file extension.',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
// Sorting of imports
|
|
38
|
+
'sort-imports': 'off',
|
|
39
|
+
'perfectionist/sort-imports': [
|
|
40
|
+
'error',
|
|
41
|
+
{
|
|
42
|
+
type: 'natural',
|
|
43
|
+
newlinesBetween: 'never',
|
|
44
|
+
groups: [
|
|
45
|
+
// type first
|
|
46
|
+
'external-type',
|
|
47
|
+
'type',
|
|
48
|
+
{ newlinesBetween: 'always' },
|
|
49
|
+
// external things
|
|
50
|
+
[
|
|
51
|
+
'builtin',
|
|
52
|
+
'external',
|
|
53
|
+
'object',
|
|
54
|
+
],
|
|
55
|
+
// Vue components
|
|
56
|
+
'vue', // external modules (e.g. nextcloud-vue)
|
|
57
|
+
'internalVue', // internal local vue components
|
|
58
|
+
// everything else which is everything internal
|
|
59
|
+
'unknown',
|
|
60
|
+
{ newlinesBetween: 'always' },
|
|
61
|
+
// side effect only: import 'sideeffect.js'
|
|
62
|
+
'side-effect',
|
|
63
|
+
// import style from 'my.module.css'
|
|
64
|
+
'style',
|
|
65
|
+
],
|
|
66
|
+
customGroups: [
|
|
67
|
+
{
|
|
68
|
+
groupName: 'vue',
|
|
69
|
+
selector: 'external',
|
|
70
|
+
modifiers: ['value'],
|
|
71
|
+
elementNamePattern: [
|
|
72
|
+
'\\.vue$',
|
|
73
|
+
'@nextcloud/vue/components/',
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
groupName: 'internalVue',
|
|
78
|
+
modifiers: ['value'],
|
|
79
|
+
elementNamePattern: ['\\.vue$'],
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
'perfectionist/sort-named-exports': [
|
|
85
|
+
'error',
|
|
86
|
+
createSortingConfig('export'),
|
|
87
|
+
],
|
|
88
|
+
'perfectionist/sort-named-imports': [
|
|
89
|
+
'error',
|
|
90
|
+
createSortingConfig('import'),
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Create the same rule config for exports and import.
|
|
98
|
+
*
|
|
99
|
+
* @param type The type for which to create the config
|
|
100
|
+
*/
|
|
101
|
+
function createSortingConfig(type) {
|
|
102
|
+
return {
|
|
103
|
+
type: 'natural',
|
|
104
|
+
newlinesBetween: 'always',
|
|
105
|
+
partitionByNewLine: false,
|
|
106
|
+
groups: [
|
|
107
|
+
`type-${type}`,
|
|
108
|
+
[
|
|
109
|
+
`value-${type}`,
|
|
110
|
+
'unknown',
|
|
111
|
+
],
|
|
112
|
+
],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
|
3
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
*/
|
|
5
|
+
import type { Linter } from 'eslint';
|
|
6
|
+
import type { ConfigOptions } from '../types.d.ts';
|
|
7
|
+
/**
|
|
8
|
+
* This config provides the base rules for code quality,
|
|
9
|
+
* the target is a good code quality -> prevent bugs,
|
|
10
|
+
* code style is handled by another config.
|
|
11
|
+
*
|
|
12
|
+
* @param options - Configuration options
|
|
13
|
+
*/
|
|
14
|
+
export declare function javascript(options: ConfigOptions): Linter.Config[];
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import eslintRules from '@eslint/js';
|
|
2
|
+
import globals from 'globals';
|
|
3
|
+
import { GLOB_FILES_JAVASCRIPT, GLOB_FILES_TESTING, GLOB_FILES_TYPESCRIPT, GLOB_FILES_VUE, } from "../globs.js";
|
|
4
|
+
import nextcloudPlugin from "../plugins/nextcloud/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* This config provides the base rules for code quality,
|
|
7
|
+
* the target is a good code quality -> prevent bugs,
|
|
8
|
+
* code style is handled by another config.
|
|
9
|
+
*
|
|
10
|
+
* @param options - Configuration options
|
|
11
|
+
*/
|
|
12
|
+
export function javascript(options) {
|
|
13
|
+
return [
|
|
14
|
+
{
|
|
15
|
+
name: 'nextcloud/javascript/setup',
|
|
16
|
+
languageOptions: {
|
|
17
|
+
ecmaVersion: 'latest',
|
|
18
|
+
globals: {
|
|
19
|
+
...globals.browser,
|
|
20
|
+
...globals.es2025,
|
|
21
|
+
OC: 'readonly',
|
|
22
|
+
OCA: 'writable',
|
|
23
|
+
OCP: 'readonly',
|
|
24
|
+
// injected by shared Vite and Webpack config
|
|
25
|
+
appName: 'readonly',
|
|
26
|
+
appVersion: 'readonly',
|
|
27
|
+
// legacy global Nextcloud translation function
|
|
28
|
+
t: 'readonly',
|
|
29
|
+
n: 'readonly',
|
|
30
|
+
// webpack support
|
|
31
|
+
__webpack_nonce__: 'writable',
|
|
32
|
+
},
|
|
33
|
+
parserOptions: {
|
|
34
|
+
ecmaFeatures: {
|
|
35
|
+
jsx: true,
|
|
36
|
+
},
|
|
37
|
+
ecmaVersion: 'latest',
|
|
38
|
+
sourceType: 'module',
|
|
39
|
+
},
|
|
40
|
+
sourceType: 'module',
|
|
41
|
+
},
|
|
42
|
+
linterOptions: {
|
|
43
|
+
reportUnusedDisableDirectives: true,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
// General rules we built upon
|
|
47
|
+
{
|
|
48
|
+
name: 'eslint/configs/recommended',
|
|
49
|
+
files: [
|
|
50
|
+
...GLOB_FILES_JAVASCRIPT,
|
|
51
|
+
...GLOB_FILES_TYPESCRIPT,
|
|
52
|
+
...GLOB_FILES_VUE,
|
|
53
|
+
],
|
|
54
|
+
...eslintRules.configs.recommended,
|
|
55
|
+
},
|
|
56
|
+
// The Nextcloud plugin for detecting deprecated and removed global API
|
|
57
|
+
(options.isLibrary
|
|
58
|
+
? {}
|
|
59
|
+
: {
|
|
60
|
+
name: 'nextcloud/javascript/plugin',
|
|
61
|
+
plugins: {
|
|
62
|
+
'@nextcloud': nextcloudPlugin,
|
|
63
|
+
},
|
|
64
|
+
rules: {
|
|
65
|
+
'@nextcloud/no-deprecations': ['warn'],
|
|
66
|
+
'@nextcloud/no-removed-apis': ['error'],
|
|
67
|
+
},
|
|
68
|
+
files: [
|
|
69
|
+
...GLOB_FILES_JAVASCRIPT,
|
|
70
|
+
...GLOB_FILES_TYPESCRIPT,
|
|
71
|
+
...GLOB_FILES_VUE,
|
|
72
|
+
],
|
|
73
|
+
}),
|
|
74
|
+
// Nextcloud specific overwrite
|
|
75
|
+
{
|
|
76
|
+
name: 'nextcloud/javascript/rules',
|
|
77
|
+
files: [
|
|
78
|
+
...GLOB_FILES_JAVASCRIPT,
|
|
79
|
+
...GLOB_FILES_TYPESCRIPT,
|
|
80
|
+
...GLOB_FILES_VUE,
|
|
81
|
+
],
|
|
82
|
+
rules: {
|
|
83
|
+
'no-eval': 'error',
|
|
84
|
+
// Require strict checks
|
|
85
|
+
eqeqeq: 'error',
|
|
86
|
+
// Use dot notation where possible as we also only use quote where needed
|
|
87
|
+
'dot-notation': 'error',
|
|
88
|
+
// prevent bugs and increasing code clarity by ensuring that block statements are wrapped in curly braces
|
|
89
|
+
curly: [
|
|
90
|
+
'error',
|
|
91
|
+
'all',
|
|
92
|
+
],
|
|
93
|
+
// disallow use of "var", use let and const - see rule description for reasons.
|
|
94
|
+
'no-var': 'error',
|
|
95
|
+
// Prevent bugs by enforce const if variable is not changed.
|
|
96
|
+
'prefer-const': 'error',
|
|
97
|
+
// `@nextcloud/logger` should be used
|
|
98
|
+
'no-console': 'error',
|
|
99
|
+
// We support ES2022 so we should use `hasOwn` instead
|
|
100
|
+
'prefer-object-has-own': 'error',
|
|
101
|
+
// Allow to write code in reading order for functions
|
|
102
|
+
'no-use-before-define': [
|
|
103
|
+
'error',
|
|
104
|
+
{ functions: false },
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
// Testing related overwrites
|
|
109
|
+
{
|
|
110
|
+
name: 'nextcloud/javascript/testing-overwrites',
|
|
111
|
+
files: GLOB_FILES_TESTING,
|
|
112
|
+
rules: {
|
|
113
|
+
// Allow to test console output
|
|
114
|
+
'no-console': 'off',
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
];
|
|
118
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
|
3
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
*/
|
|
5
|
+
import type { Linter } from 'eslint';
|
|
6
|
+
/**
|
|
7
|
+
* JSON related ESLint rules for Nextcloud
|
|
8
|
+
*/
|
|
9
|
+
export declare const json: Linter.Config[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import jsonPlugin from '@eslint/json';
|
|
2
|
+
import { GLOB_FILES_JSON, GLOB_FILES_JSONC, GLOB_FILES_MS_JSON, } from "../globs.js";
|
|
3
|
+
import packageJsonPlugin from "../plugins/packageJson.js";
|
|
4
|
+
/**
|
|
5
|
+
* JSON related ESLint rules for Nextcloud
|
|
6
|
+
*/
|
|
7
|
+
export const json = [
|
|
8
|
+
{
|
|
9
|
+
language: 'json/json',
|
|
10
|
+
plugins: {
|
|
11
|
+
json: jsonPlugin,
|
|
12
|
+
'package-json': packageJsonPlugin,
|
|
13
|
+
},
|
|
14
|
+
rules: {
|
|
15
|
+
...jsonPlugin.configs.recommended.rules,
|
|
16
|
+
},
|
|
17
|
+
files: GLOB_FILES_JSON,
|
|
18
|
+
name: 'nextcloud/json',
|
|
19
|
+
},
|
|
20
|
+
// lint package.json files
|
|
21
|
+
{
|
|
22
|
+
files: ['**/package.json'],
|
|
23
|
+
language: 'json/json',
|
|
24
|
+
rules: {
|
|
25
|
+
'package-json/sort-package-json': 'error',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
// Special handing of JSONC
|
|
29
|
+
{
|
|
30
|
+
files: GLOB_FILES_JSONC,
|
|
31
|
+
language: 'json/jsonc',
|
|
32
|
+
...jsonPlugin.configs.recommended,
|
|
33
|
+
name: 'nextcloud/jsonc',
|
|
34
|
+
},
|
|
35
|
+
// Microsoft specific JSONC (e.g. Typescript config)
|
|
36
|
+
{
|
|
37
|
+
files: GLOB_FILES_MS_JSON,
|
|
38
|
+
language: 'json/jsonc',
|
|
39
|
+
languageOptions: {
|
|
40
|
+
allowTrailingCommas: true,
|
|
41
|
+
},
|
|
42
|
+
...jsonPlugin.configs.recommended,
|
|
43
|
+
name: 'nextcloud/ms-json',
|
|
44
|
+
},
|
|
45
|
+
];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
|
3
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
*/
|
|
5
|
+
import type { Linter } from 'eslint';
|
|
6
|
+
/**
|
|
7
|
+
* Config setup for the node environment.
|
|
8
|
+
* Config files should be parsed as Node.JS scripts with Node globals etc.
|
|
9
|
+
*/
|
|
10
|
+
export declare const node: Linter.Config[];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import globals from 'globals';
|
|
2
|
+
import { GLOB_FILES_TESTING } from "../globs.js";
|
|
3
|
+
/**
|
|
4
|
+
* Config setup for the node environment.
|
|
5
|
+
* Config files should be parsed as Node.JS scripts with Node globals etc.
|
|
6
|
+
*/
|
|
7
|
+
export const node = [
|
|
8
|
+
{
|
|
9
|
+
name: 'nextcloud/node/setup',
|
|
10
|
+
files: [
|
|
11
|
+
'**/*.config.*',
|
|
12
|
+
'**/*.cjs',
|
|
13
|
+
'**/*.cts',
|
|
14
|
+
...GLOB_FILES_TESTING,
|
|
15
|
+
],
|
|
16
|
+
languageOptions: {
|
|
17
|
+
globals: {
|
|
18
|
+
...globals.es2023,
|
|
19
|
+
...globals.node,
|
|
20
|
+
...globals.nodeBuiltin,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
|
3
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
*/
|
|
5
|
+
import type { Linter } from 'eslint';
|
|
6
|
+
import type { ConfigOptions } from '../types.d.ts';
|
|
7
|
+
/**
|
|
8
|
+
* Typescript related ESLint rules for Nextcloud
|
|
9
|
+
*
|
|
10
|
+
* @param options options defining the config preset flavor
|
|
11
|
+
*/
|
|
12
|
+
export declare function typescript(options: ConfigOptions): Linter.Config[];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import typescriptPlugin from 'typescript-eslint';
|
|
2
|
+
import { GLOB_FILES_TESTING, GLOB_FILES_TYPESCRIPT, GLOB_FILES_TYPESCRIPT_DECLARATIONS, GLOB_FILES_VUE, } from "../globs.js";
|
|
3
|
+
import { restrictConfigFiles } from "../utils.js";
|
|
4
|
+
/**
|
|
5
|
+
* Typescript related ESLint rules for Nextcloud
|
|
6
|
+
*
|
|
7
|
+
* @param options options defining the config preset flavor
|
|
8
|
+
*/
|
|
9
|
+
export function typescript(options) {
|
|
10
|
+
return [
|
|
11
|
+
...restrictConfigFiles(typescriptPlugin.configs.recommended, [
|
|
12
|
+
...GLOB_FILES_TYPESCRIPT,
|
|
13
|
+
...(options.vueIsTypescript ? GLOB_FILES_VUE : []),
|
|
14
|
+
]),
|
|
15
|
+
{
|
|
16
|
+
name: 'nextcloud/typescript/rules',
|
|
17
|
+
files: [
|
|
18
|
+
...GLOB_FILES_TYPESCRIPT,
|
|
19
|
+
...(options.vueIsTypescript ? GLOB_FILES_VUE : []),
|
|
20
|
+
],
|
|
21
|
+
rules: {
|
|
22
|
+
// Do not allow to import types with `import` but require `import type`
|
|
23
|
+
'@typescript-eslint/consistent-type-imports': 'error',
|
|
24
|
+
// Allow expect-error as we can sometimes not prevent it...
|
|
25
|
+
'@typescript-eslint/ban-ts-comment': [
|
|
26
|
+
'error',
|
|
27
|
+
{
|
|
28
|
+
'ts-expect-error': 'allow-with-description',
|
|
29
|
+
minimumDescriptionLength: 9,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
// No nullish coalescing if left side can not be nullish
|
|
33
|
+
'@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error',
|
|
34
|
+
// Do not use types, variables etc before they are defined
|
|
35
|
+
'no-use-before-define': 'off',
|
|
36
|
+
'@typescript-eslint/no-use-before-define': [
|
|
37
|
+
'error',
|
|
38
|
+
{
|
|
39
|
+
functions: false,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'nextcloud/typescript/declaration-rules',
|
|
46
|
+
files: [...GLOB_FILES_TYPESCRIPT_DECLARATIONS],
|
|
47
|
+
rules: {
|
|
48
|
+
'@typescript-eslint/consistent-type-imports': ['error', { disallowTypeAnnotations: false }],
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
files: GLOB_FILES_TESTING,
|
|
53
|
+
rules: {
|
|
54
|
+
// Allow "any" in tests
|
|
55
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
56
|
+
},
|
|
57
|
+
name: 'nextcloud/typescript/test-rules',
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
|
3
|
+
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
4
|
+
*/
|
|
5
|
+
import type { Linter } from 'eslint';
|
|
6
|
+
import type { ConfigOptions } from '../types.d.ts';
|
|
7
|
+
/**
|
|
8
|
+
* General vue related rules for both versions
|
|
9
|
+
*
|
|
10
|
+
* @param options options defining the config preset flavor
|
|
11
|
+
*/
|
|
12
|
+
export declare function vue(options: ConfigOptions): Linter.Config[];
|