Skip to content

Commit ff65a38

Browse files
committed
feat: add options to separate formatting and linting and export createConfig
Added new configuration options for disabling linting or formatting and made all configurations aware of it. To make use of it the `createConfig` method is exposed now for advanced use cases. Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent ec0e7e3 commit ff65a38

File tree

14 files changed

+447
-360
lines changed

14 files changed

+447
-360
lines changed

lib/configs/codeStyle.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5+
56
import type { Linter } from 'eslint'
67
import type { ConfigOptions } from '../types.d.ts'
78

@@ -20,7 +21,11 @@ import l10nPlugin from '../plugins/l10n/index.ts'
2021
*
2122
* @param options options defining the config preset flavor
2223
*/
23-
export function codeStyle(options: ConfigOptions): (Linter.Config | Linter.BaseConfig)[] {
24+
export function codeStyle(options: ConfigOptions): Linter.Config[] {
25+
if (options.formatting === false) {
26+
return []
27+
}
28+
2429
return [
2530
// Nextcloud code style
2631
{

lib/configs/documentation.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5+
56
import type { Linter } from 'eslint'
67
import type { Settings } from 'eslint-plugin-jsdoc/iterateJsdoc.js'
78
import type { ConfigOptions } from '../types.d.ts'
@@ -41,6 +42,10 @@ const SHARED_JSDOC_SETTINGS: Partial<Settings> = {
4142
* @param options options defining the config preset flavor
4243
*/
4344
export function documentation(options: ConfigOptions): Linter.Config[] {
45+
if (options.linting === false) {
46+
return []
47+
}
48+
4449
return [
4550
{
4651
...jsdoc({

lib/configs/filesystem.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,31 @@
44
*/
55

66
import type { Linter } from 'eslint'
7+
import type { ConfigOptions } from '../types.d.ts'
78

89
import gitignore from 'eslint-config-flat-gitignore'
910

1011
/**
1112
* General config to exclude known non-source directories from linting
13+
*
14+
* @param options - Configuration options
1215
*/
13-
export const filesystem: Linter.Config[] = [
14-
{
15-
...gitignore(),
16-
name: 'nextcloud/filesystem/gitignore',
17-
},
18-
{
19-
name: 'nextcloud/filesystem/ignores',
20-
ignores: [
21-
'dist/',
22-
'js/',
23-
'l10n/',
24-
'vendor/',
25-
'vendor-bin/',
26-
'**/package-lock.json',
27-
],
28-
},
29-
]
16+
export function filesystem(options: ConfigOptions): Linter.Config[] { // eslint-disable-line @typescript-eslint/no-unused-vars
17+
return [
18+
{
19+
...gitignore(),
20+
name: 'nextcloud/filesystem/gitignore',
21+
},
22+
{
23+
name: 'nextcloud/filesystem/ignores',
24+
ignores: [
25+
'dist/',
26+
'js/',
27+
'l10n/',
28+
'vendor/',
29+
'vendor-bin/',
30+
'**/package-lock.json',
31+
],
32+
},
33+
]
34+
}

lib/configs/imports.ts

Lines changed: 69 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import type { Linter } from 'eslint'
21
/*!
32
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
43
* SPDX-License-Identifier: AGPL-3.0-or-later
54
*/
5+
6+
import type { Linter } from 'eslint'
67
import type { ConfigOptions } from '../types.d.ts'
78

89
import perfectionist from 'eslint-plugin-perfectionist'
@@ -18,14 +19,76 @@ import importExtensions from '../plugins/import-extensions/index.ts'
1819
*
1920
* @param options - Configuration options
2021
*/
21-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2222
export function imports(options: ConfigOptions): Linter.Config[] {
23+
const lintingRules: Partial<Linter.RulesRecord> = {
24+
// Require file extensions
25+
'import-extensions/extensions': 'error',
26+
}
27+
28+
const formattingRules: Partial<Linter.RulesRecord> = {
29+
// Sorting of imports
30+
'sort-imports': 'off' as const,
31+
'perfectionist/sort-imports': [
32+
'error',
33+
{
34+
type: 'natural',
35+
newlinesBetween: 'never',
36+
groups: [
37+
// type first
38+
'external-type',
39+
'type',
40+
{ newlinesBetween: 'always' },
41+
// external things
42+
[
43+
'builtin',
44+
'external',
45+
'object',
46+
],
47+
// Vue components
48+
'vue', // external modules (e.g. nextcloud-vue)
49+
'internalVue', // internal local vue components
50+
// everything else which is everything internal
51+
'unknown',
52+
{ newlinesBetween: 'always' },
53+
// side effect only: import 'sideeffect.js'
54+
'side-effect',
55+
// import style from 'my.module.css'
56+
'style',
57+
],
58+
customGroups: [
59+
{
60+
groupName: 'vue',
61+
selector: 'external',
62+
modifiers: ['value'],
63+
elementNamePattern: [
64+
'\\.vue$',
65+
'@nextcloud/vue/components/',
66+
],
67+
},
68+
{
69+
groupName: 'internalVue',
70+
modifiers: ['value'],
71+
elementNamePattern: ['\\.vue$'],
72+
},
73+
],
74+
},
75+
],
76+
'perfectionist/sort-named-exports': [
77+
'error',
78+
createSortingConfig('export'),
79+
],
80+
'perfectionist/sort-named-imports': [
81+
'error',
82+
createSortingConfig('import'),
83+
],
84+
}
85+
2386
return [
2487
{
2588
name: 'nextcloud/imports/setup',
2689
plugins: {
27-
perfectionist,
28-
'import-extensions': importExtensions,
90+
...(options.formatting ? { perfectionist } : {}),
91+
...(options.linting ? { 'import-extensions': importExtensions } : {}),
2992
},
3093
},
3194
{
@@ -36,63 +99,8 @@ export function imports(options: ConfigOptions): Linter.Config[] {
3699
...GLOB_FILES_VUE,
37100
],
38101
rules: {
39-
// Require file extensions
40-
'import-extensions/extensions': 'error',
41-
// Sorting of imports
42-
'sort-imports': 'off',
43-
'perfectionist/sort-imports': [
44-
'error',
45-
{
46-
type: 'natural',
47-
newlinesBetween: 'never',
48-
groups: [
49-
// type first
50-
'external-type',
51-
'type',
52-
{ newlinesBetween: 'always' },
53-
// external things
54-
[
55-
'builtin',
56-
'external',
57-
'object',
58-
],
59-
// Vue components
60-
'vue', // external modules (e.g. nextcloud-vue)
61-
'internalVue', // internal local vue components
62-
// everything else which is everything internal
63-
'unknown',
64-
{ newlinesBetween: 'always' },
65-
// side effect only: import 'sideeffect.js'
66-
'side-effect',
67-
// import style from 'my.module.css'
68-
'style',
69-
],
70-
customGroups: [
71-
{
72-
groupName: 'vue',
73-
selector: 'external',
74-
modifiers: ['value'],
75-
elementNamePattern: [
76-
'\\.vue$',
77-
'@nextcloud/vue/components/',
78-
],
79-
},
80-
{
81-
groupName: 'internalVue',
82-
modifiers: ['value'],
83-
elementNamePattern: ['\\.vue$'],
84-
},
85-
],
86-
},
87-
],
88-
'perfectionist/sort-named-exports': [
89-
'error',
90-
createSortingConfig('export'),
91-
],
92-
'perfectionist/sort-named-imports': [
93-
'error',
94-
createSortingConfig('import'),
95-
],
102+
...(options.linting ? lintingRules : {}),
103+
...(options.formatting ? formattingRules : {}),
96104
},
97105
},
98106
]

lib/configs/index.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*!
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
import type { ConfigOptions } from '../types.d.ts'
6+
7+
import { codeStyle } from './codeStyle.ts'
8+
import { documentation } from './documentation.ts'
9+
import { filesystem } from './filesystem.ts'
10+
import { imports } from './imports.ts'
11+
import { javascript } from './javascript.ts'
12+
import { json } from './json.ts'
13+
import { node } from './node.ts'
14+
import { typescript } from './typescript.ts'
15+
import { vue2 } from './vue2.ts'
16+
import { vue3 } from './vue3.ts'
17+
18+
/**
19+
* Nextcloud shared configuration for projects using Vue 2 with Javascript <script> blocks
20+
*/
21+
export const recommendedVue2Javascript = createConfig({
22+
isLibrary: false,
23+
vue2: true,
24+
vueIsTypescript: false,
25+
})
26+
27+
/**
28+
* Nextcloud shared configuration for projects using Vue 2 with Typescript <script> blocks
29+
*/
30+
export const recommendedVue2 = createConfig({
31+
isLibrary: false,
32+
vue2: true,
33+
vueIsTypescript: true,
34+
})
35+
36+
/**
37+
* Nextcloud shared configuration for projects using Vue 3 with Javascript <script> blocks
38+
*/
39+
export const recommendedJavascript = createConfig({
40+
isLibrary: false,
41+
vueIsTypescript: false,
42+
})
43+
44+
/**
45+
* Nextcloud shared configuration for projects using Vue 3 with Typescript <script> blocks
46+
*/
47+
export const recommended = createConfig({
48+
isLibrary: false,
49+
vueIsTypescript: true,
50+
})
51+
52+
/**
53+
* Nextcloud shared configuration for projects using Vue 3 with Typescript <script> blocks
54+
*/
55+
export const recommendedLibrary = createConfig({
56+
isLibrary: true,
57+
vueIsTypescript: true,
58+
})
59+
60+
/**
61+
* Nextcloud shared configuration for projects using Vue 3 with Typescript <script> blocks
62+
*/
63+
export const recommendedVue2Library = createConfig({
64+
isLibrary: true,
65+
vue2: true,
66+
vueIsTypescript: true,
67+
})
68+
69+
/**
70+
* Generate a configuration based on given options
71+
*
72+
* @param options - Configuration options
73+
*/
74+
export function createConfig(options: ConfigOptions & { vue2?: boolean }) {
75+
options = { formatting: true, linting: true, vue2: false, ...options }
76+
77+
return [
78+
...filesystem(options),
79+
...javascript(options),
80+
...json(options),
81+
...node(options),
82+
...typescript(options),
83+
...(
84+
options.vue2
85+
? vue2(options)
86+
: vue3(options)
87+
),
88+
...documentation(options),
89+
...imports(options),
90+
...codeStyle(options),
91+
]
92+
}

lib/configs/javascript.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ import nextcloudPlugin from '../plugins/nextcloud/index.ts'
2323
* @param options - Configuration options
2424
*/
2525
export function javascript(options: ConfigOptions): Linter.Config[] {
26+
if (options.linting === false) {
27+
return []
28+
}
29+
2630
return [
2731
{
2832
name: 'nextcloud/javascript/setup',

0 commit comments

Comments
 (0)