UNPKG

@nextcloud/eslint-config

Version:

Eslint shared config for nextcloud apps and libraries

177 lines (176 loc) 7.34 kB
import stylistic from '@stylistic/eslint-plugin'; import eslintAntfuPlugin from 'eslint-plugin-antfu'; import { GLOB_FILES_JAVASCRIPT, GLOB_FILES_TYPESCRIPT, GLOB_FILES_VUE, } from "../globs.js"; /** * Config factory for general code style related rules * See also: https://docs.nextcloud.com/server/latest/developer_manual/getting_started/coding_standards/javascript.html#code-style * * @param options options defining the config preset flavor */ export function codeStyle(options) { return [ // Nextcloud code style { name: '@stylistic/configs/recommended', files: [ ...GLOB_FILES_JAVASCRIPT, ...GLOB_FILES_TYPESCRIPT, ...GLOB_FILES_VUE, ], ...stylistic.configs.customize({ indent: 'tab', semi: false, quotes: 'single', quoteProps: 'as-needed', commaDangle: 'always-multiline', arrowParens: true, braceStyle: '1tbs', }), }, { name: 'nextcloud/stylistic/rules', files: [ ...GLOB_FILES_JAVASCRIPT, ...GLOB_FILES_TYPESCRIPT, ...GLOB_FILES_VUE, ], plugins: { antfu: eslintAntfuPlugin, }, rules: { // Overrides for the stylistic recommended rules // Tabs should only be used for indention '@stylistic/no-tabs': [ 'error', { allowIndentationTabs: true }, ], // allow spaces after tabs for alignment '@stylistic/no-mixed-spaces-and-tabs': [ 'error', 'smart-tabs', ], // allow backticks for strings that contain single quotes '@stylistic/quotes': [ 'error', 'single', { allowTemplateLiterals: 'never', avoidEscape: true, }, ], // Not included in stylistic preset but set by us: // Enforce camelCase but allow legacy webpack variables camelcase: [ 'error', { allow: ['^__webpack_'], properties: 'never', ignoreGlobals: true, }, ], // Make sure to use object shorthand properties 'object-shorthand': [ 'error', 'properties', { avoidQuotes: 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', }, overrides: { '{}': { singleLine: { spacing: 'always' }, }, }, }], // No space between function name and parenthesis. Enforce fn() instead of fn () '@stylistic/function-call-spacing': [ 'error', 'never', ], // No space between function name and parenthesis on definition. Enforce `function foo()` instead of `function foo ()`. '@stylistic/space-before-function-paren': [ 'error', { // good: `function() {}` bad: `function () {}` anonymous: 'never', // good `function foo() {}` bad: `function foo () {}` named: 'never', // consistency for arrow functions regardless of async or sync: // good `async () => {}` bad `async() => {}` asyncArrow: 'always', }, ], // Enforce consistent newlines in function parameters, if one parameter is separated by newline, than all should '@stylistic/function-call-argument-newline': [ 'error', 'consistent', ], // If parameters are separated by newlines, then the first one should also be separated by a newline from the parenthesis '@stylistic/function-paren-newline': [ 'error', 'multiline', ], // Generator functions should have the * on the function keyword as this defines the type of function. "function* generator()" '@stylistic/generator-star-spacing': [ 'error', 'after', ], // Arrow functions with implicit return should not have line breaks // TODO: Discuss '@stylistic/implicit-arrow-linebreak': [ 'error', 'beside', ], // Prevent issues with different OS by enforcing single line feed for new lien '@stylistic/linebreak-style': [ 'error', 'unix', ], // No useless semicolons '@stylistic/no-extra-semi': ['error'], 'no-useless-concat': 'error', // Prefer { ...foo } over Object.assign({}, foo) 'prefer-object-spread': 'warn', // Enforce function declarations for top level functions 'antfu/top-level-function': 'error', }, }, { name: 'nextcloud/stylistic/ts-rules', files: [ ...GLOB_FILES_TYPESCRIPT, ...(options.vueIsTypescript ? GLOB_FILES_VUE : []), ], rules: { // consistent spacing for types '@stylistic/type-annotation-spacing': 'error', // consistent spacing for generics '@stylistic/type-generic-spacing': 'error', '@stylistic/type-named-tuple-spacing': 'error', }, }, { name: 'nextcloud/stylistic/l10n', files: [ ...GLOB_FILES_JAVASCRIPT, ...GLOB_FILES_TYPESCRIPT, ...GLOB_FILES_VUE, ], // Enforce that translations use ellipsis instead of tripple dots rules: { '@nextcloud/l10n-non-breaking-space': 'error', '@nextcloud/l10n-enforce-ellipsis': 'error', }, }, ]; }