Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions lib/configs/codeStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,28 @@ 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,
// 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', {
singleLine: {
spacing: 'never',
maxItems: 3,
},
],
'@stylistic/object-property-newline': [
'error',
{ allowAllPropertiesOnSameLine: true },
],
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': [
Expand Down
3 changes: 2 additions & 1 deletion lib/configs/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 9 additions & 1 deletion lib/plugins/nextcloud-vue/rules/no-deprecated-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
58 changes: 47 additions & 11 deletions tests/fixtures/codestyle/input/array.js
Original file line number Diff line number Diff line change
@@ -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',
]
66 changes: 54 additions & 12 deletions tests/fixtures/codestyle/output/array.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,61 @@
// 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',
]
5 changes: 4 additions & 1 deletion tests/fixtures/codestyle/output/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
// ...
}

Expand Down