|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +import { defineConfig } from 'eslint/config'; |
| 4 | +import js from '@eslint/js'; |
| 5 | +import tsPlugin from '@typescript-eslint/eslint-plugin'; |
| 6 | +import tsParser from '@typescript-eslint/parser'; |
| 7 | +import prettierConfig from 'eslint-config-prettier'; |
| 8 | +import simpleImportSort from 'eslint-plugin-simple-import-sort'; |
| 9 | +import globals from 'globals'; |
| 10 | + |
| 11 | +// Custom inline plugin for header checking |
| 12 | +const headerRule = { |
| 13 | + create(context) { |
| 14 | + return { |
| 15 | + Program(node) { |
| 16 | + const comments = context.sourceCode.getAllComments(); |
| 17 | + const hasHeader = comments[0]?.value.trim() === 'SPDX-License-Identifier: Apache-2.0'; |
| 18 | + |
| 19 | + if (!hasHeader) { |
| 20 | + context.report({ node, message: 'Missing SPDX license header' }); |
| 21 | + } |
| 22 | + }, |
| 23 | + }; |
| 24 | + }, |
| 25 | +}; |
| 26 | + |
| 27 | +export default defineConfig([ |
| 28 | + // Global ignores |
| 29 | + { |
| 30 | + ignores: ['**/node_modules/**', '**/dist/**'], |
| 31 | + }, |
| 32 | + |
| 33 | + // Base recommended configs |
| 34 | + js.configs.recommended, |
| 35 | + |
| 36 | + // Main configuration for all JS/TS files |
| 37 | + { |
| 38 | + files: ['**/*.js', '**/*.mjs', '**/*.cjs', '**/*.ts'], |
| 39 | + plugins: { |
| 40 | + '@typescript-eslint': tsPlugin, |
| 41 | + 'simple-import-sort': simpleImportSort, |
| 42 | + local: { |
| 43 | + rules: { |
| 44 | + header: headerRule, |
| 45 | + }, |
| 46 | + }, |
| 47 | + }, |
| 48 | + languageOptions: { |
| 49 | + ecmaVersion: 'latest', |
| 50 | + sourceType: 'module', |
| 51 | + parser: tsParser, |
| 52 | + globals: { |
| 53 | + ...globals.node, |
| 54 | + ...globals.es2021, |
| 55 | + __ENV: 'readonly', |
| 56 | + NodeJS: 'readonly', |
| 57 | + }, |
| 58 | + }, |
| 59 | + rules: { |
| 60 | + // Merge recommended TypeScript rules |
| 61 | + ...tsPlugin.configs.recommended.rules, |
| 62 | + // Merge prettier config rules (disables conflicting rules) |
| 63 | + ...prettierConfig.rules, |
| 64 | + // Custom rules |
| 65 | + '@typescript-eslint/ban-ts-comment': 'off', |
| 66 | + '@typescript-eslint/no-explicit-any': 'off', |
| 67 | + '@typescript-eslint/no-var-requires': 'warn', |
| 68 | + '@typescript-eslint/no-unused-vars': 'warn', |
| 69 | + 'no-trailing-spaces': 'error', |
| 70 | + 'no-useless-escape': 'warn', |
| 71 | + 'prefer-const': 'error', |
| 72 | + 'comma-dangle': [ |
| 73 | + 'error', |
| 74 | + { |
| 75 | + arrays: 'always-multiline', |
| 76 | + objects: 'always-multiline', |
| 77 | + imports: 'always-multiline', |
| 78 | + exports: 'always-multiline', |
| 79 | + functions: 'always-multiline', |
| 80 | + }, |
| 81 | + ], |
| 82 | + 'simple-import-sort/imports': 'error', |
| 83 | + 'simple-import-sort/exports': 'off', |
| 84 | + 'local/header': 'error', |
| 85 | + }, |
| 86 | + }, |
| 87 | + |
| 88 | + // Config for eslint config files themselves |
| 89 | + { |
| 90 | + files: ['eslint.config.js', '.eslintrc.{js,cjs}'], |
| 91 | + languageOptions: { |
| 92 | + sourceType: 'script', |
| 93 | + globals: { |
| 94 | + ...globals.node, |
| 95 | + }, |
| 96 | + }, |
| 97 | + }, |
| 98 | + |
| 99 | + // Test files - relaxed rules |
| 100 | + { |
| 101 | + files: ['**/*.spec.ts', '**/*.test.ts', '**/tests/**/*.ts'], |
| 102 | + languageOptions: { |
| 103 | + globals: { |
| 104 | + ...globals.mocha, |
| 105 | + }, |
| 106 | + }, |
| 107 | + rules: { |
| 108 | + '@typescript-eslint/no-unused-expressions': 'off', |
| 109 | + }, |
| 110 | + }, |
| 111 | +]); |
0 commit comments