UNPKG

@nextcloud/eslint-config

Version:

Eslint shared config for nextcloud apps and libraries

61 lines (60 loc) 2.36 kB
import typescriptPlugin from 'typescript-eslint'; import { GLOB_FILES_TESTING, GLOB_FILES_TYPESCRIPT, GLOB_FILES_TYPESCRIPT_DECLARATIONS, GLOB_FILES_VUE, } from "../globs.js"; import { restrictConfigFiles } from "../utils.js"; /** * Typescript related ESLint rules for Nextcloud * * @param options options defining the config preset flavor */ export function typescript(options) { return [ ...restrictConfigFiles(typescriptPlugin.configs.recommended, [ ...GLOB_FILES_TYPESCRIPT, ...(options.vueIsTypescript ? GLOB_FILES_VUE : []), ]), { name: 'nextcloud/typescript/rules', files: [ ...GLOB_FILES_TYPESCRIPT, ...(options.vueIsTypescript ? GLOB_FILES_VUE : []), ], rules: { // Do not allow to import types with `import` but require `import type` '@typescript-eslint/consistent-type-imports': 'error', // Allow expect-error as we can sometimes not prevent it... '@typescript-eslint/ban-ts-comment': [ 'error', { 'ts-expect-error': 'allow-with-description', minimumDescriptionLength: 9, }, ], // No nullish coalescing if left side can not be nullish '@typescript-eslint/no-non-null-asserted-nullish-coalescing': 'error', // Do not use types, variables etc before they are defined 'no-use-before-define': 'off', '@typescript-eslint/no-use-before-define': [ 'error', { functions: false, }, ], }, }, { name: 'nextcloud/typescript/declaration-rules', files: [...GLOB_FILES_TYPESCRIPT_DECLARATIONS], rules: { '@typescript-eslint/consistent-type-imports': ['error', { disallowTypeAnnotations: false }], }, }, { files: GLOB_FILES_TESTING, rules: { // Allow "any" in tests '@typescript-eslint/no-explicit-any': 'off', }, name: 'nextcloud/typescript/test-rules', }, ]; }