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'
67import type { ConfigOptions } from '../types.d.ts'
78
89import 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
2222export 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 ]
0 commit comments