diff --git a/lib/configs/codeStyle.ts b/lib/configs/codeStyle.ts index bd12cbf6..e22895a2 100644 --- a/lib/configs/codeStyle.ts +++ b/lib/configs/codeStyle.ts @@ -2,6 +2,7 @@ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ + import type { Linter } from 'eslint' import type { ConfigOptions } from '../types.d.ts' @@ -20,7 +21,11 @@ import l10nPlugin from '../plugins/l10n/index.ts' * * @param options options defining the config preset flavor */ -export function codeStyle(options: ConfigOptions): (Linter.Config | Linter.BaseConfig)[] { +export function codeStyle(options: ConfigOptions): Linter.Config[] { + if (options.formatting === false) { + return [] + } + return [ // Nextcloud code style { diff --git a/lib/configs/documentation.ts b/lib/configs/documentation.ts index 38036972..10b0cffa 100644 --- a/lib/configs/documentation.ts +++ b/lib/configs/documentation.ts @@ -2,6 +2,7 @@ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ + import type { Linter } from 'eslint' import type { Settings } from 'eslint-plugin-jsdoc/iterateJsdoc.js' import type { ConfigOptions } from '../types.d.ts' @@ -41,6 +42,10 @@ const SHARED_JSDOC_SETTINGS: Partial = { * @param options options defining the config preset flavor */ export function documentation(options: ConfigOptions): Linter.Config[] { + if (options.linting === false) { + return [] + } + return [ { ...jsdoc({ diff --git a/lib/configs/filesystem.ts b/lib/configs/filesystem.ts index b1d1184a..f345ec37 100644 --- a/lib/configs/filesystem.ts +++ b/lib/configs/filesystem.ts @@ -4,26 +4,31 @@ */ import type { Linter } from 'eslint' +import type { ConfigOptions } from '../types.d.ts' import gitignore from 'eslint-config-flat-gitignore' /** * General config to exclude known non-source directories from linting + * + * @param options - Configuration options */ -export const filesystem: Linter.Config[] = [ - { - ...gitignore(), - name: 'nextcloud/filesystem/gitignore', - }, - { - name: 'nextcloud/filesystem/ignores', - ignores: [ - 'dist/', - 'js/', - 'l10n/', - 'vendor/', - 'vendor-bin/', - '**/package-lock.json', - ], - }, -] +export function filesystem(options: ConfigOptions): Linter.Config[] { // eslint-disable-line @typescript-eslint/no-unused-vars + return [ + { + ...gitignore(), + name: 'nextcloud/filesystem/gitignore', + }, + { + name: 'nextcloud/filesystem/ignores', + ignores: [ + 'dist/', + 'js/', + 'l10n/', + 'vendor/', + 'vendor-bin/', + '**/package-lock.json', + ], + }, + ] +} diff --git a/lib/configs/imports.ts b/lib/configs/imports.ts index 99f522c2..d842e3db 100644 --- a/lib/configs/imports.ts +++ b/lib/configs/imports.ts @@ -1,8 +1,9 @@ -import type { Linter } from 'eslint' /*! * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ + +import type { Linter } from 'eslint' import type { ConfigOptions } from '../types.d.ts' import perfectionist from 'eslint-plugin-perfectionist' @@ -18,14 +19,76 @@ import importExtensions from '../plugins/import-extensions/index.ts' * * @param options - Configuration options */ -// eslint-disable-next-line @typescript-eslint/no-unused-vars export function imports(options: ConfigOptions): Linter.Config[] { + const lintingRules: Partial = { + // Require file extensions + 'import-extensions/extensions': 'error', + } + + const formattingRules: Partial = { + // Sorting of imports + 'sort-imports': 'off' as const, + 'perfectionist/sort-imports': [ + 'error', + { + type: 'natural', + newlinesBetween: 'never', + groups: [ + // type first + 'external-type', + 'type', + { newlinesBetween: 'always' }, + // external things + [ + 'builtin', + 'external', + 'object', + ], + // Vue components + 'vue', // external modules (e.g. nextcloud-vue) + 'internalVue', // internal local vue components + // everything else which is everything internal + 'unknown', + { newlinesBetween: 'always' }, + // side effect only: import 'sideeffect.js' + 'side-effect', + // import style from 'my.module.css' + 'style', + ], + customGroups: [ + { + groupName: 'vue', + selector: 'external', + modifiers: ['value'], + elementNamePattern: [ + '\\.vue$', + '@nextcloud/vue/components/', + ], + }, + { + groupName: 'internalVue', + modifiers: ['value'], + elementNamePattern: ['\\.vue$'], + }, + ], + }, + ], + 'perfectionist/sort-named-exports': [ + 'error', + createSortingConfig('export'), + ], + 'perfectionist/sort-named-imports': [ + 'error', + createSortingConfig('import'), + ], + } + return [ { name: 'nextcloud/imports/setup', plugins: { - perfectionist, - 'import-extensions': importExtensions, + ...(options.formatting ? { perfectionist } : {}), + ...(options.linting ? { 'import-extensions': importExtensions } : {}), }, }, { @@ -36,63 +99,8 @@ export function imports(options: ConfigOptions): Linter.Config[] { ...GLOB_FILES_VUE, ], rules: { - // Require file extensions - 'import-extensions/extensions': 'error', - // Sorting of imports - 'sort-imports': 'off', - 'perfectionist/sort-imports': [ - 'error', - { - type: 'natural', - newlinesBetween: 'never', - groups: [ - // type first - 'external-type', - 'type', - { newlinesBetween: 'always' }, - // external things - [ - 'builtin', - 'external', - 'object', - ], - // Vue components - 'vue', // external modules (e.g. nextcloud-vue) - 'internalVue', // internal local vue components - // everything else which is everything internal - 'unknown', - { newlinesBetween: 'always' }, - // side effect only: import 'sideeffect.js' - 'side-effect', - // import style from 'my.module.css' - 'style', - ], - customGroups: [ - { - groupName: 'vue', - selector: 'external', - modifiers: ['value'], - elementNamePattern: [ - '\\.vue$', - '@nextcloud/vue/components/', - ], - }, - { - groupName: 'internalVue', - modifiers: ['value'], - elementNamePattern: ['\\.vue$'], - }, - ], - }, - ], - 'perfectionist/sort-named-exports': [ - 'error', - createSortingConfig('export'), - ], - 'perfectionist/sort-named-imports': [ - 'error', - createSortingConfig('import'), - ], + ...(options.linting ? lintingRules : {}), + ...(options.formatting ? formattingRules : {}), }, }, ] diff --git a/lib/configs/index.ts b/lib/configs/index.ts new file mode 100644 index 00000000..8995af31 --- /dev/null +++ b/lib/configs/index.ts @@ -0,0 +1,92 @@ +/*! + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import type { ConfigOptions } from '../types.d.ts' + +import { codeStyle } from './codeStyle.ts' +import { documentation } from './documentation.ts' +import { filesystem } from './filesystem.ts' +import { imports } from './imports.ts' +import { javascript } from './javascript.ts' +import { json } from './json.ts' +import { node } from './node.ts' +import { typescript } from './typescript.ts' +import { vue2 } from './vue2.ts' +import { vue3 } from './vue3.ts' + +/** + * Nextcloud shared configuration for projects using Vue 2 with Javascript