From 0ae2dcef1f01819c2198a716641ff39403b0a228 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 6 Nov 2025 01:55:16 +0100 Subject: [PATCH 1/2] fix: switch to `@stylistic/exp-list-style` to resolve array edge-cases Signed-off-by: Ferdinand Thiessen --- lib/configs/codeStyle.ts | 28 ++++------ lib/configs/vue.ts | 3 +- tests/fixtures/codestyle/input/array.js | 58 +++++++++++++++++---- tests/fixtures/codestyle/output/array.js | 52 +++++++++++++----- tests/fixtures/codestyle/output/function.ts | 5 +- 5 files changed, 102 insertions(+), 44 deletions(-) diff --git a/lib/configs/codeStyle.ts b/lib/configs/codeStyle.ts index 3e354d66..45a4ec6f 100644 --- a/lib/configs/codeStyle.ts +++ b/lib/configs/codeStyle.ts @@ -93,25 +93,15 @@ export function codeStyle(options: ConfigOptions): Linter.Config[] { { avoidQuotes: true }, ], - // Enforce consistent new lines after [ and before ] - '@stylistic/array-bracket-newline': [ - 'error', - 'consistent', - ], - // Enforce new lines between array elements (better git diff) but allow to have single line arrays - '@stylistic/array-element-newline': ['error', 'consistent'], - // Same for objects as for arrays - '@stylistic/object-curly-newline': [ - 'error', - { - consistent: true, - multiline: true, - }, - ], - '@stylistic/object-property-newline': [ - 'error', - { allowAllPropertiesOnSameLine: true }, - ], + // Enforce consistent new lines after brackets + '@stylistic/array-bracket-newline': 'off', + '@stylistic/array-bracket-spacing': 'off', + '@stylistic/array-element-newline': 'off', + '@stylistic/jsx-function-call-newline': 'off', + '@stylistic/object-curly-newline': 'off', + '@stylistic/object-curly-spacing': 'off', + '@stylistic/object-property-newline': 'off', + '@stylistic/exp-list-style': 'error', // No space between function name and parenthesis. Enforce fn() instead of fn () '@stylistic/function-call-spacing': [ diff --git a/lib/configs/vue.ts b/lib/configs/vue.ts index bc46bd8e..85826288 100644 --- a/lib/configs/vue.ts +++ b/lib/configs/vue.ts @@ -143,7 +143,8 @@ export function vue(options: ConfigOptions): Linter.Config[] { 'vue/prefer-separate-static-class': 'error', // For consistent layout of components 'vue/define-macros-order': [ - 'error', { + 'error', + { order: [ 'defineOptions', 'defineModel', diff --git a/tests/fixtures/codestyle/input/array.js b/tests/fixtures/codestyle/input/array.js index d5e5abf9..9d33a3a1 100644 --- a/tests/fixtures/codestyle/input/array.js +++ b/tests/fixtures/codestyle/input/array.js @@ -1,16 +1,52 @@ -// This can be a single line -const arr = ['first', 'second'] +/* eslint-disable no-unused-vars */ -// This is not a single line already and should be one element per line -const arr2 = [ - 'first', 'second', - 'third', 'and', - 'so', 'on' -] - -// This has a missing trailing comma causing too much git diff -const arr3 = [ +// ❌ Trailing comma is required to make multi-line array diff-safe on changing the last element +// Here the trailing comma is missing on a multi-line array and extra comma is present on a single-line array +const items = [ 'first', 'second', 'third' ] +const LATIN_VOWELS = ['a', 'e', 'i', 'o', 'u',] + +// ❌ Multi-line array should have a single element per line to make it diff-safe and readable +// Here the last two elements are on the same line +const VARIANTS = [ + 'primary', + 'secondary', + 'tertiary', 'tertiary-no-background', +] + +// ✅ In general it is recommended to prefer a multi-line array to make it diff-safe on adding/removing elements +// It is especially important for dynamic array which entries may change +const sampleUsers = [ + 'admin', + 'alice', + 'bob', +] +// Even if there is only one element at the moment (more elements may be added later) +const MUTE_NOTIFICATIONS_USER_STATUSES = [ + 'dnd', +] + +// ✅ Single-line arrays are also fine for short and stable arrays which are not expected to change +// This is a developer's choice +const selectedItems = ['default_item'] +const HTML_FORM_ACTIONS = ['POST', 'GET'] + +// ❌ Single-line array should have brackets on the same line while multi-line array should have brackets on the next line +const USER_STATUSES = [ + 'online', + 'away', + 'dnd', + 'invisible', + 'offline'] +// 🚧 Currently this is an edge case and isn't fixed properly... +const WEEKDAYS = ['Monday', + 'Tuesday', + 'Wednesday', + 'Thursday', + 'Friday', + 'Saturday', + 'Sunday', +] diff --git a/tests/fixtures/codestyle/output/array.js b/tests/fixtures/codestyle/output/array.js index d154573f..d3a36487 100644 --- a/tests/fixtures/codestyle/output/array.js +++ b/tests/fixtures/codestyle/output/array.js @@ -1,19 +1,47 @@ -// This can be a single line -const arr = ['first', 'second'] +/* eslint-disable no-unused-vars */ -// This is not a single line already and should be one element per line -const arr2 = [ +// ❌ Trailing comma is required to make multi-line array diff-safe on changing the last element +// Here the trailing comma is missing on a multi-line array and extra comma is present on a single-line array +const items = [ 'first', 'second', 'third', - 'and', - 'so', - 'on', ] +const LATIN_VOWELS = ['a', 'e', 'i', 'o', 'u'] -// This has a missing trailing comma causing too much git diff -const arr3 = [ - 'first', - 'second', - 'third', +// ❌ Multi-line array should have a single element per line to make it diff-safe and readable +// Here the last two elements are on the same line +const VARIANTS = [ + 'primary', + 'secondary', + 'tertiary', + 'tertiary-no-background', +] + +// ✅ In general it is recommended to prefer a multi-line array to make it diff-safe on adding/removing elements +// It is especially important for dynamic array which entries may change +const sampleUsers = [ + 'admin', + 'alice', + 'bob', +] +// Even if there is only one element at the moment (more elements may be added later) +const MUTE_NOTIFICATIONS_USER_STATUSES = [ + 'dnd', +] + +// ✅ Single-line arrays are also fine for short and stable arrays which are not expected to change +// This is a developer's choice +const selectedItems = ['default_item'] +const HTML_FORM_ACTIONS = ['POST', 'GET'] + +// ❌ Single-line array should have brackets on the same line while multi-line array should have brackets on the next line +const USER_STATUSES = [ + 'online', + 'away', + 'dnd', + 'invisible', + 'offline', ] +// 🚧 Currently this is an edge case and isn't fixed properly... +const WEEKDAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] diff --git a/tests/fixtures/codestyle/output/function.ts b/tests/fixtures/codestyle/output/function.ts index 5b2fc91a..958cacd8 100644 --- a/tests/fixtures/codestyle/output/function.ts +++ b/tests/fixtures/codestyle/output/function.ts @@ -48,7 +48,10 @@ export function doSomething( * @param num * @param enable */ -export function doSomethingDifferent(num: number, enable: boolean) { +export function doSomethingDifferent( + num: number, + enable: boolean, +) { // ... } From 43dbc3542a348825e66e3faf207f3538d24270e1 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 6 Nov 2025 12:39:10 +0100 Subject: [PATCH 2/2] chore: adjust max array members in a single line to 3 items Signed-off-by: Ferdinand Thiessen --- lib/configs/codeStyle.ts | 15 ++++++++++++++- .../nextcloud-vue/rules/no-deprecated-props.ts | 10 +++++++++- tests/fixtures/codestyle/output/array.js | 18 ++++++++++++++++-- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/lib/configs/codeStyle.ts b/lib/configs/codeStyle.ts index 45a4ec6f..447a4a24 100644 --- a/lib/configs/codeStyle.ts +++ b/lib/configs/codeStyle.ts @@ -101,7 +101,20 @@ export function codeStyle(options: ConfigOptions): Linter.Config[] { '@stylistic/object-curly-newline': 'off', '@stylistic/object-curly-spacing': 'off', '@stylistic/object-property-newline': 'off', - '@stylistic/exp-list-style': 'error', + '@stylistic/exp-list-style': ['error', { + singleLine: { + spacing: 'never', + maxItems: 3, + }, + multiLine: { + minItems: 0, + }, + overrides: { + '{}': { + singleLine: { spacing: 'always', maxItems: Number.POSITIVE_INFINITY }, + }, + }, + }], // No space between function name and parenthesis. Enforce fn() instead of fn () '@stylistic/function-call-spacing': [ diff --git a/lib/plugins/nextcloud-vue/rules/no-deprecated-props.ts b/lib/plugins/nextcloud-vue/rules/no-deprecated-props.ts index 8dc1c519..ddced972 100644 --- a/lib/plugins/nextcloud-vue/rules/no-deprecated-props.ts +++ b/lib/plugins/nextcloud-vue/rules/no-deprecated-props.ts @@ -56,7 +56,15 @@ export default { const isNcTextFieldArrowEndValid = versionSatisfies('8.28.0') // #7002 const isCloseButtonOutsideValid = versionSatisfies('8.32.0') // #7553 - const legacyTypes = ['primary', 'error', 'warning', 'success', 'secondary', 'tertiary', 'tertiary-no-background'] + const legacyTypes = [ + 'primary', + 'error', + 'warning', + 'success', + 'secondary', + 'tertiary', + 'tertiary-no-background', + ] return vueUtils.defineTemplateBodyVisitor(context, { 'VElement VAttribute:has(VIdentifier[name="type"])': function(node) { diff --git a/tests/fixtures/codestyle/output/array.js b/tests/fixtures/codestyle/output/array.js index d3a36487..3a4213be 100644 --- a/tests/fixtures/codestyle/output/array.js +++ b/tests/fixtures/codestyle/output/array.js @@ -7,7 +7,13 @@ const items = [ 'second', 'third', ] -const LATIN_VOWELS = ['a', 'e', 'i', 'o', 'u'] +const LATIN_VOWELS = [ + 'a', + 'e', + 'i', + 'o', + 'u', +] // ❌ Multi-line array should have a single element per line to make it diff-safe and readable // Here the last two elements are on the same line @@ -44,4 +50,12 @@ const USER_STATUSES = [ 'offline', ] // 🚧 Currently this is an edge case and isn't fixed properly... -const WEEKDAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] +const WEEKDAYS = [ + 'Monday', + 'Tuesday', + 'Wednesday', + 'Thursday', + 'Friday', + 'Saturday', + 'Sunday', +]