| // @ts-check |
| const { fixupPluginRules } = require('@eslint/compat'); |
| const { FlatCompat } = require('@eslint/eslintrc'); |
| const eslintJs = require('@eslint/js'); |
| const eslintTs = require('typescript-eslint'); |
| const angular = require('angular-eslint'); |
| // plugins |
| const jsdoc = require('eslint-plugin-jsdoc'); |
| const prettier = require('eslint-plugin-prettier'); |
| const unusedImports = require('eslint-plugin-unused-imports'); |
| const header = require('eslint-plugin-header'); |
| |
| // @see https://github.com/Stuk/eslint-plugin-header/issues/57#issuecomment-2378485611 |
| header.rules.header.meta.schema = false; |
| |
| const compat = new FlatCompat({ |
| baseDirectory: __dirname, |
| recommendedConfig: eslintJs.configs.recommended |
| }); |
| |
| /** |
| * @description Resolve a legacy plugin that does not support eslint@9 |
| * @see https://github.com/import-js/eslint-plugin-import/issues/2948#issuecomment-2148832701 |
| * @param {string} name the plugin name |
| * @param {string} alias the plugin alias |
| * @returns {import('eslint').ESLint.Plugin} |
| */ |
| function legacyPlugin(name, alias = name) { |
| const plugin = compat.plugins(name)[0]?.plugins?.[alias]; |
| |
| if (!plugin) { |
| throw new Error(`Unable to resolve plugin ${name} and/or alias ${alias}`); |
| } |
| |
| return fixupPluginRules(plugin); |
| } |
| |
| module.exports = eslintTs.config( |
| { |
| files: ['**/*.ts'], |
| plugins: { |
| jsdoc, |
| 'unused-imports': unusedImports, |
| header: legacyPlugin('eslint-plugin-header', 'header'), |
| import: legacyPlugin('eslint-plugin-import', 'import'), |
| prettier |
| }, |
| extends: [ |
| eslintJs.configs.recommended, |
| ...eslintTs.configs.recommended, |
| ...eslintTs.configs.stylistic, |
| ...angular.configs.tsRecommended |
| ], |
| processor: angular.processInlineTemplates, |
| rules: { |
| 'prettier/prettier': 'error', |
| 'header/header': [2, './license-header.js'], |
| 'unused-imports/no-unused-imports': 'error', |
| 'import/no-duplicates': 'error', |
| 'import/no-unused-modules': 'error', |
| 'import/no-unassigned-import': 'error', |
| 'import/order': [ |
| 'error', |
| { |
| alphabetize: { |
| order: 'asc', |
| caseInsensitive: false |
| }, |
| 'newlines-between': 'always', |
| groups: ['external', 'builtin', 'internal', ['parent', 'sibling', 'index']], |
| pathGroups: [ |
| { |
| pattern: '{@angular/**,rxjs,rxjs/operators}', |
| group: 'external', |
| position: 'before' |
| }, |
| { |
| pattern: '@paimon/**', |
| group: 'internal', |
| position: 'before' |
| } |
| ], |
| pathGroupsExcludedImportTypes: [] |
| } |
| ], |
| 'no-empty-function': 'off', |
| 'no-unused-expressions': 'error', |
| 'no-use-before-define': 'off', |
| 'no-bitwise': 'off', |
| 'no-duplicate-imports': 'error', |
| 'no-invalid-this': 'off', |
| 'no-irregular-whitespace': 'error', |
| 'no-magic-numbers': 'off', |
| 'no-multiple-empty-lines': 'error', |
| 'no-redeclare': 'off', |
| 'no-underscore-dangle': 'off', |
| 'no-sparse-arrays': 'error', |
| 'no-template-curly-in-string': 'off', |
| 'prefer-object-spread': 'error', |
| 'prefer-template': 'error', |
| yoda: 'error', |
| '@typescript-eslint/no-explicit-any': 'error', |
| '@typescript-eslint/no-non-null-assertion': 'off', |
| '@typescript-eslint/array-type': [ |
| 'error', |
| { |
| default: 'array-simple' |
| } |
| ], |
| '@typescript-eslint/consistent-type-definitions': 'error', |
| '@typescript-eslint/explicit-member-accessibility': [ |
| 'off', |
| { |
| accessibility: 'explicit' |
| } |
| ], |
| '@typescript-eslint/no-floating-promises': 'off', |
| '@typescript-eslint/no-inferrable-types': [ |
| 'error', |
| { |
| ignoreParameters: true, |
| ignoreProperties: true |
| } |
| ], |
| '@typescript-eslint/no-this-alias': 'error', |
| '@typescript-eslint/naming-convention': 'off', |
| '@typescript-eslint/no-unused-expressions': 'off', |
| '@typescript-eslint/explicit-function-return-type': [ |
| 'error', |
| { |
| allowExpressions: true, |
| allowConciseArrowFunctionExpressionsStartingWithVoid: true |
| } |
| ], |
| '@angular-eslint/directive-selector': [ |
| 'error', |
| { |
| type: 'attribute', |
| prefix: 'paimon', |
| style: 'camelCase' |
| } |
| ], |
| '@angular-eslint/component-selector': [ |
| 'error', |
| { |
| type: 'element', |
| prefix: 'paimon', |
| style: 'kebab-case' |
| } |
| ] |
| } |
| }, |
| { |
| files: ['**/*.html'], |
| extends: [...angular.configs.templateRecommended, ...angular.configs.templateAccessibility], |
| plugins: { |
| prettier |
| }, |
| rules: { |
| '@angular-eslint/template/click-events-have-key-events': ['off'], |
| '@angular-eslint/template/interactive-supports-focus': ['off'], |
| 'prettier/prettier': ['error', { parser: 'angular' }] |
| } |
| } |
| ); |