|
| 1 | +import svelteEslint from 'eslint-plugin-svelte' |
| 2 | +import svelteParser from 'svelte-eslint-parser' |
| 3 | +import tsESLint, { type ConfigWithExtends } from 'typescript-eslint' |
| 4 | +import svelteConfig from './svelte.config' |
| 5 | +import type { NamingConventionRule } from './tslintNamingConventionRule' |
| 6 | + |
| 7 | +console.log(`[${new Date().toLocaleTimeString()}] Loading ESLint config`) |
| 8 | + |
| 9 | +const IGNORE_PATTERNS = [ |
| 10 | + '.DS_Store', |
| 11 | + '.env', |
| 12 | + '.env.*', |
| 13 | + '.github', |
| 14 | + '.vscode', |
| 15 | + '**/node_modules/**', |
| 16 | + |
| 17 | + // Blockbench Plugin Template |
| 18 | + 'dist/**/*', |
| 19 | + |
| 20 | + // Ignore files for PNPM, NPM and YARN |
| 21 | + 'pnpm-lock.yaml', |
| 22 | + 'package-lock.json', |
| 23 | + 'yarn.lock' |
| 24 | +] |
| 25 | + |
| 26 | +const CUSTOM_RULES: ConfigWithExtends['rules'] = { |
| 27 | + // ESLint |
| 28 | + semi: ['error', 'never'], |
| 29 | + 'prefer-const': 'warn', |
| 30 | + 'no-fallthrough': 'off', |
| 31 | + 'no-mixed-spaces-and-tabs': 'off', |
| 32 | + 'no-unreachable': 'warn', |
| 33 | + '@typescript-eslint/no-unused-vars': [ |
| 34 | + 'warn', |
| 35 | + { |
| 36 | + vars: 'local', |
| 37 | + args: 'after-used', |
| 38 | + argsIgnorePattern: '^_', |
| 39 | + ignoreRestSiblings: true |
| 40 | + } |
| 41 | + ], |
| 42 | + // Svelte |
| 43 | + 'svelte/html-quotes': ['warn', { prefer: 'double' }], |
| 44 | + 'svelte/block-lang': ['error', { script: ['ts', null], style: null }], |
| 45 | + 'svelte/comment-directive': ['error', { reportUnusedDisableDirectives: true }], |
| 46 | + // Check File |
| 47 | + 'check-file/filename-naming-convention': [ |
| 48 | + 'error', |
| 49 | + { |
| 50 | + 'src/**/*.{ts.d.ts}': 'CAMEL_CASE', |
| 51 | + 'tools/**/*.{ts.d.ts}': 'CAMEL_CASE' |
| 52 | + } |
| 53 | + ], |
| 54 | + 'check-file/folder-naming-convention': [ |
| 55 | + 'error', |
| 56 | + { |
| 57 | + 'src/**': 'KEBAB_CASE', |
| 58 | + 'tools/**': 'KEBAB_CASE' |
| 59 | + } |
| 60 | + ], |
| 61 | + // TypeScript |
| 62 | + '@typescript-eslint/no-explicit-any': 'off', |
| 63 | + '@typescript-eslint/no-floating-promises': ['error', { ignoreVoid: true }], |
| 64 | + '@typescript-eslint/array-type': ['warn', { default: 'array-simple' }], |
| 65 | + '@typescript-eslint/consistent-indexed-object-style': ['warn', 'record'], |
| 66 | + '@typescript-eslint/consistent-generic-constructors': 'warn', |
| 67 | + '@typescript-eslint/no-namespace': 'off', |
| 68 | + '@typescript-eslint/restrict-template-expressions': 'off', |
| 69 | + '@typescript-eslint/no-unsafe-member-access': 'off', |
| 70 | + '@typescript-eslint/no-unsafe-assignment': 'off', |
| 71 | + '@typescript-eslint/ban-ts-comment': 'off', |
| 72 | + '@typescript-eslint/require-await': 'warn', |
| 73 | + '@typescript-eslint/no-unsafe-call': 'off', |
| 74 | + '@typescript-eslint/unbound-method': 'off', |
| 75 | + '@typescript-eslint/no-non-null-assertion': 'off', |
| 76 | + '@typescript-eslint/triple-slash-reference': 'off', |
| 77 | + // Naming conventions |
| 78 | + '@typescript-eslint/naming-convention': [ |
| 79 | + 'warn', |
| 80 | + { |
| 81 | + // DFU Version imports |
| 82 | + selector: ['import'], |
| 83 | + modifiers: ['default'], |
| 84 | + filter: { |
| 85 | + regex: 'v\\d+_\\d+_\\d+$', |
| 86 | + match: true |
| 87 | + }, |
| 88 | + custom: { |
| 89 | + match: true, |
| 90 | + regex: 'v\\d+_\\d+_\\d+$' |
| 91 | + }, |
| 92 | + format: null |
| 93 | + }, |
| 94 | + { |
| 95 | + selector: ['import'], |
| 96 | + modifiers: ['default'], |
| 97 | + format: ['camelCase', 'PascalCase', 'UPPER_CASE'] |
| 98 | + }, |
| 99 | + { |
| 100 | + selector: 'class', |
| 101 | + format: ['PascalCase'] |
| 102 | + }, |
| 103 | + { |
| 104 | + selector: ['classProperty', 'classMethod'], |
| 105 | + format: ['camelCase'] |
| 106 | + }, |
| 107 | + { |
| 108 | + selector: ['classProperty', 'classMethod'], |
| 109 | + leadingUnderscore: 'allow', |
| 110 | + format: ['camelCase'] |
| 111 | + }, |
| 112 | + { |
| 113 | + selector: ['classProperty', 'classMethod'], |
| 114 | + modifiers: ['private'], |
| 115 | + leadingUnderscore: 'allowDouble', |
| 116 | + trailingUnderscore: 'allowDouble', |
| 117 | + format: ['camelCase'] |
| 118 | + }, |
| 119 | + { |
| 120 | + selector: 'typeProperty', |
| 121 | + format: null |
| 122 | + }, |
| 123 | + { |
| 124 | + selector: 'variable', |
| 125 | + modifiers: ['const', 'destructured'], |
| 126 | + format: null |
| 127 | + }, |
| 128 | + { |
| 129 | + selector: 'variable', |
| 130 | + modifiers: ['const', 'global'], |
| 131 | + types: ['function'], |
| 132 | + leadingUnderscore: 'allow', |
| 133 | + format: ['UPPER_CASE', 'camelCase'] |
| 134 | + }, |
| 135 | + { |
| 136 | + selector: 'variable', |
| 137 | + modifiers: ['const', 'global'], |
| 138 | + leadingUnderscore: 'allow', |
| 139 | + format: ['UPPER_CASE'] |
| 140 | + }, |
| 141 | + { |
| 142 | + selector: 'variable', |
| 143 | + modifiers: ['const', 'exported'], |
| 144 | + format: ['camelCase', 'UPPER_CASE'] |
| 145 | + }, |
| 146 | + { |
| 147 | + selector: 'variableLike', |
| 148 | + format: ['camelCase'] |
| 149 | + }, |
| 150 | + { selector: 'interface', format: ['PascalCase'] }, |
| 151 | + { |
| 152 | + selector: 'interface', |
| 153 | + modifiers: ['exported'], |
| 154 | + format: ['PascalCase'], |
| 155 | + prefix: ['I'] |
| 156 | + }, |
| 157 | + { selector: 'typeLike', format: ['PascalCase'] }, |
| 158 | + { selector: 'objectLiteralProperty', format: null }, |
| 159 | + { selector: 'default', format: ['camelCase'] }, |
| 160 | + { |
| 161 | + selector: 'parameter', |
| 162 | + modifiers: ['unused'], |
| 163 | + format: ['camelCase'], |
| 164 | + leadingUnderscore: 'allow' |
| 165 | + }, |
| 166 | + { |
| 167 | + selector: 'parameter', |
| 168 | + format: ['camelCase'] |
| 169 | + }, |
| 170 | + { |
| 171 | + selector: 'enumMember', |
| 172 | + format: ['camelCase', 'PascalCase', 'UPPER_CASE'] |
| 173 | + }, |
| 174 | + { |
| 175 | + selector: 'enum', |
| 176 | + format: ['UPPER_CASE'] |
| 177 | + } |
| 178 | + ] satisfies NamingConventionRule |
| 179 | +} |
| 180 | + |
| 181 | +export default tsESLint.config( |
| 182 | + { |
| 183 | + ignores: IGNORE_PATTERNS |
| 184 | + }, |
| 185 | + ...tsESLint.configs.stylisticTypeChecked, |
| 186 | + ...svelteEslint.configs['flat/prettier'], |
| 187 | + { |
| 188 | + plugins: { |
| 189 | + '@typescript-eslint': tsESLint.plugin, |
| 190 | + svelte: svelteEslint |
| 191 | + } |
| 192 | + }, |
| 193 | + { |
| 194 | + rules: CUSTOM_RULES |
| 195 | + }, |
| 196 | + { |
| 197 | + languageOptions: { |
| 198 | + parser: tsESLint.parser, |
| 199 | + parserOptions: { |
| 200 | + project: './tsconfig.json', |
| 201 | + extraFileExtensions: ['.svelte'] |
| 202 | + }, |
| 203 | + globals: { |
| 204 | + browser: true, |
| 205 | + node: true |
| 206 | + } |
| 207 | + } |
| 208 | + }, |
| 209 | + { |
| 210 | + files: ['**/*.svelte'], |
| 211 | + rules: { |
| 212 | + // Causes issues with Svelte and global types |
| 213 | + 'no-undef': 'off', |
| 214 | + '@typescript-eslint/naming-convention': [ |
| 215 | + 'warn', |
| 216 | + { |
| 217 | + selector: 'variable', |
| 218 | + modifiers: ['exported'], |
| 219 | + format: ['camelCase'] |
| 220 | + }, |
| 221 | + { |
| 222 | + selector: 'variable', |
| 223 | + modifiers: ['const', 'global'], |
| 224 | + format: ['UPPER_CASE'] |
| 225 | + }, |
| 226 | + { |
| 227 | + selector: 'variable', |
| 228 | + modifiers: ['const', 'global'], |
| 229 | + types: ['function'], |
| 230 | + format: ['camelCase'] |
| 231 | + }, |
| 232 | + { |
| 233 | + selector: 'variable', |
| 234 | + format: ['camelCase'], |
| 235 | + leadingUnderscore: 'allow' |
| 236 | + } |
| 237 | + ] satisfies NamingConventionRule |
| 238 | + }, |
| 239 | + languageOptions: { |
| 240 | + parser: svelteParser, |
| 241 | + parserOptions: { |
| 242 | + parser: tsESLint.parser, |
| 243 | + svelteConfig: svelteConfig, |
| 244 | + extraFileExtensions: ['.svelte'] |
| 245 | + }, |
| 246 | + globals: { |
| 247 | + browser: true, |
| 248 | + node: true |
| 249 | + } |
| 250 | + }, |
| 251 | + settings: { |
| 252 | + ignoreWarnings: ['svelte/a11y-no-onchange', 'a11y-no-onchange'] |
| 253 | + } |
| 254 | + }, |
| 255 | + { |
| 256 | + languageOptions: { |
| 257 | + parserOptions: { |
| 258 | + projectService: true, |
| 259 | + tsconfigRootDir: '.' |
| 260 | + } |
| 261 | + }, |
| 262 | + linterOptions: { |
| 263 | + reportUnusedDisableDirectives: true |
| 264 | + } |
| 265 | + } |
| 266 | +) |
0 commit comments