UNPKG

@blitz/eslint-plugin

Version:

An ESLint config to enforce a consistent code styles across StackBlitz projects

85 lines 3.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tsRules = exports.getNamingConventionRule = exports.tsFileExtensions = void 0; const javascript_1 = require("./javascript"); exports.tsFileExtensions = ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts']; function getNamingConventionRule(extensions, tsx = false) { return { '@typescript-eslint/naming-convention': [ 'error', { selector: ['variable', 'function'], format: ['camelCase', 'UPPER_CASE', tsx && 'StrictPascalCase'].filter(Boolean), leadingUnderscore: 'allowSingleOrDouble', trailingUnderscore: 'forbid', filter: { regex: generateNamingConventionRegex(['__dirname'], extensions?.variable?.exceptions), match: false, }, }, { selector: 'parameter', format: ['camelCase'], leadingUnderscore: 'allow', ...(extensions?.parameter?.exceptions?.length && { filter: { regex: generateNamingConventionRegex([], extensions?.parameter?.exceptions), match: false, }, }), }, { selector: 'typeLike', format: ['PascalCase'], }, { selector: 'memberLike', modifiers: ['private'], format: ['camelCase'], leadingUnderscore: 'require', }, ], }; } exports.getNamingConventionRule = getNamingConventionRule; function tsRules(extensions) { return { ...javascript_1.jsRules, '@typescript-eslint/no-unused-vars': [ 'error', { argsIgnorePattern: '^_', ignoreRestSiblings: true, }, ], '@typescript-eslint/no-non-null-assertion': 'off', '@typescript-eslint/no-empty-function': 'warn', '@typescript-eslint/no-explicit-any': 'off', ...getNamingConventionRule(extensions?.namingConvention, false), '@typescript-eslint/explicit-module-boundary-types': 'off', '@typescript-eslint/no-extra-non-null-assertion': 'error', '@typescript-eslint/no-non-null-asserted-optional-chain': 'error', '@stylistic/ts/type-annotation-spacing': 'error', '@typescript-eslint/explicit-member-accessibility': [ 'error', { accessibility: 'no-public', }, ], '@typescript-eslint/ban-ts-comment': [ 'error', { 'ts-expect-error': true, 'ts-ignore': 'allow-with-description', 'ts-nocheck': true, 'ts-check': false, }, ], '@stylistic/ts/lines-around-comment': 'off', }; } exports.tsRules = tsRules; function generateNamingConventionRegex(defaults, extensions = []) { return `^(${defaults.concat(extensions).join('|')})$`; } //# sourceMappingURL=typescript.js.map