|
| 1 | +/********************************************************************** |
| 2 | + * Copyright (C) 2024 Red Hat, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * SPDX-License-Identifier: Apache-2.0 |
| 17 | + ***********************************************************************/ |
| 18 | + |
| 19 | +import path from 'node:path'; |
| 20 | +import { fileURLToPath } from 'node:url'; |
| 21 | + |
| 22 | +import { fixupConfigRules, fixupPluginRules } from '@eslint/compat'; |
| 23 | +import { FlatCompat } from '@eslint/eslintrc'; |
| 24 | +import js from '@eslint/js'; |
| 25 | +import tsParser from '@typescript-eslint/parser'; |
| 26 | +import vitest from '@vitest/eslint-plugin'; |
| 27 | +import etc from 'eslint-plugin-etc'; |
| 28 | +import fileProgress from 'eslint-plugin-file-progress'; |
| 29 | +import importPlugin from 'eslint-plugin-import'; |
| 30 | +import noNull from 'eslint-plugin-no-null'; |
| 31 | +import redundantUndefined from 'eslint-plugin-redundant-undefined'; |
| 32 | +import simpleImportSort from 'eslint-plugin-simple-import-sort'; |
| 33 | +import sonarjs from 'eslint-plugin-sonarjs'; |
| 34 | +import svelte from 'eslint-plugin-svelte'; |
| 35 | +import unicorn from 'eslint-plugin-unicorn'; |
| 36 | +import globals from 'globals'; |
| 37 | +import svelteParser from 'svelte-eslint-parser'; |
| 38 | +import typescriptLint from 'typescript-eslint'; |
| 39 | + |
| 40 | +const __filename = fileURLToPath(import.meta.url); |
| 41 | +const __dirname = path.dirname(__filename); |
| 42 | +const compat = new FlatCompat({ |
| 43 | + baseDirectory: __dirname, |
| 44 | + recommendedConfig: js.configs.recommended, |
| 45 | + allConfig: js.configs.all, |
| 46 | +}); |
| 47 | + |
| 48 | +export default [ |
| 49 | + { |
| 50 | + ignores: ['**/dist/**/*', '**/.svelte-kit/**', '**/coverage/**', '**/node_modules/**'], |
| 51 | + }, |
| 52 | + js.configs.recommended, |
| 53 | + ...typescriptLint.configs.recommended, |
| 54 | + sonarjs.configs.recommended, |
| 55 | + ...svelte.configs['flat/recommended'], |
| 56 | + ...fixupConfigRules( |
| 57 | + compat.extends('plugin:import/recommended', 'plugin:import/typescript', 'plugin:etc/recommended'), |
| 58 | + ), |
| 59 | + { |
| 60 | + plugins: { |
| 61 | + // compliant v9 plug-ins |
| 62 | + unicorn, |
| 63 | + 'file-progress': fileProgress, |
| 64 | + // non-compliant v9 plug-ins |
| 65 | + etc: fixupPluginRules(etc), |
| 66 | + import: fixupPluginRules(importPlugin), |
| 67 | + 'no-null': fixupPluginRules(noNull), |
| 68 | + 'redundant-undefined': fixupPluginRules(redundantUndefined), |
| 69 | + 'simple-import-sort': fixupPluginRules(simpleImportSort), |
| 70 | + vitest, |
| 71 | + }, |
| 72 | + settings: { |
| 73 | + 'import/resolver': { |
| 74 | + typescript: true, |
| 75 | + node: true, |
| 76 | + |
| 77 | + 'eslint-import-resolver-custom-alias': { |
| 78 | + alias: { |
| 79 | + '/@': './src', |
| 80 | + '/@gen': './src-generated', |
| 81 | + }, |
| 82 | + extensions: ['.ts', '.svelte'], |
| 83 | + }, |
| 84 | + }, |
| 85 | + 'file-progress/activate': { |
| 86 | + progress: { |
| 87 | + hide: false, |
| 88 | + successMessage: 'Lint done...', |
| 89 | + }, |
| 90 | + }, |
| 91 | + }, |
| 92 | + }, |
| 93 | + { |
| 94 | + linterOptions: { |
| 95 | + reportUnusedDisableDirectives: 'off', |
| 96 | + }, |
| 97 | + languageOptions: { |
| 98 | + globals: { |
| 99 | + ...Object.fromEntries(Object.entries(globals.node).map(([key]) => [key, 'off'])), |
| 100 | + ...globals.browser, |
| 101 | + }, |
| 102 | + // parser: tsParser, |
| 103 | + sourceType: 'module', |
| 104 | + parserOptions: { |
| 105 | + extraFileExtensions: ['.svelte'], |
| 106 | + warnOnUnsupportedTypeScriptVersion: false, |
| 107 | + project: ['./tsconfig.json', './tsconfig.node.json'], |
| 108 | + tsconfigRootDir: __dirname, |
| 109 | + }, |
| 110 | + }, |
| 111 | + }, |
| 112 | + { |
| 113 | + rules: { |
| 114 | + 'vitest/no-import-node-test': 'error', |
| 115 | + 'vitest/no-identical-title': 'error', |
| 116 | + eqeqeq: 'error', |
| 117 | + 'prefer-promise-reject-errors': 'error', |
| 118 | + semi: ['error', 'always'], |
| 119 | + 'comma-dangle': ['warn', 'always-multiline'], |
| 120 | + |
| 121 | + quotes: [ |
| 122 | + 'error', |
| 123 | + 'single', |
| 124 | + { |
| 125 | + allowTemplateLiterals: true, |
| 126 | + }, |
| 127 | + ], |
| 128 | + |
| 129 | + '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', caughtErrors: 'none' }], |
| 130 | + '@typescript-eslint/no-var-requires': 'off', |
| 131 | + '@typescript-eslint/consistent-type-imports': 'error', |
| 132 | + '@typescript-eslint/no-explicit-any': 'error', |
| 133 | + '@typescript-eslint/await-thenable': 'error', |
| 134 | + '@typescript-eslint/no-floating-promises': ['error', { ignoreVoid: false }], |
| 135 | + '@typescript-eslint/no-misused-promises': 'error', |
| 136 | + '@typescript-eslint/prefer-optional-chain': 'error', |
| 137 | + '@typescript-eslint/explicit-function-return-type': 'error', |
| 138 | + '@typescript-eslint/prefer-nullish-coalescing': [ |
| 139 | + 'error', |
| 140 | + { |
| 141 | + ignoreConditionalTests: true, |
| 142 | + }, |
| 143 | + ], |
| 144 | + '@typescript-eslint/no-require-imports': 'off', |
| 145 | + |
| 146 | + 'file-progress/activate': 'warn', |
| 147 | + |
| 148 | + // disabled import/namespace rule as the plug-in is not fully compatible using the compat mode |
| 149 | + 'import/namespace': 'off', |
| 150 | + 'import/no-duplicates': 'error', |
| 151 | + 'import/no-unresolved': 'off', |
| 152 | + 'import/default': 'off', |
| 153 | + 'import/no-named-as-default-member': 'off', |
| 154 | + 'import/no-named-as-default': 'off', |
| 155 | + 'import/first': 'error', |
| 156 | + 'import/newline-after-import': 'error', |
| 157 | + 'import/no-extraneous-dependencies': 'error', |
| 158 | + |
| 159 | + // unicorn custom rules |
| 160 | + 'unicorn/prefer-node-protocol': 'error', |
| 161 | + |
| 162 | + // sonarjs custom rules |
| 163 | + 'sonarjs/cognitive-complexity': 'off', |
| 164 | + 'sonarjs/no-duplicate-string': 'off', |
| 165 | + 'sonarjs/no-empty-collection': 'off', |
| 166 | + 'sonarjs/no-small-switch': 'off', |
| 167 | + // redundant with @typescript-eslint/no-unused-vars |
| 168 | + 'sonarjs/no-ignored-exceptions': 'off', |
| 169 | + 'sonarjs/no-nested-functions': 'off', |
| 170 | + 'sonarjs/todo-tag': 'off', |
| 171 | + 'sonarjs/sonar-max-params': 'off', |
| 172 | + 'sonarjs/no-nested-conditional': 'off', |
| 173 | + 'sonarjs/no-empty-function': 'off', |
| 174 | + 'sonarjs/no-base-to-string': 'off', |
| 175 | + 'sonarjs/unnecessary-character-escapes': 'off', |
| 176 | + 'sonarjs/different-types-comparison': 'off', |
| 177 | + 'sonarjs/new-cap': 'off', |
| 178 | + 'sonarjs/no-invariant-returns': 'off', |
| 179 | + 'sonarjs/updated-loop-counter': 'off', |
| 180 | + 'sonarjs/no-redundant-type-constituents': 'off', |
| 181 | + 'sonarjs/function-return-type': 'off', |
| 182 | + 'sonarjs/no-lonely-if': 'off', |
| 183 | + 'sonarjs/deprecation': 'off', |
| 184 | + 'sonarjs/use-type-alias': 'off', |
| 185 | + |
| 186 | + // failing with the AST parser |
| 187 | + 'sonarjs/sonar-no-fallthrough': 'off', |
| 188 | + 'sonarjs/prefer-enum-initializers': 'off', |
| 189 | + |
| 190 | + // etc custom rules |
| 191 | + 'etc/no-deprecated': 'off', |
| 192 | + // disable this rule as it's not compliant with eslint v9 |
| 193 | + 'etc/no-commented-out-code': 'off', |
| 194 | + |
| 195 | + // redundant-undefined custom rules |
| 196 | + 'redundant-undefined/redundant-undefined': 'error', |
| 197 | + |
| 198 | + // simple-import-sort custom rules |
| 199 | + 'simple-import-sort/imports': 'error', |
| 200 | + 'simple-import-sort/exports': 'error', |
| 201 | + }, |
| 202 | + }, |
| 203 | + |
| 204 | + { |
| 205 | + files: ['**/*.svelte'], |
| 206 | + |
| 207 | + languageOptions: { |
| 208 | + parser: svelteParser, |
| 209 | + ecmaVersion: 5, |
| 210 | + sourceType: 'script', |
| 211 | + parserOptions: { |
| 212 | + parser: tsParser, |
| 213 | + }, |
| 214 | + }, |
| 215 | + |
| 216 | + rules: { |
| 217 | + '@typescript-eslint/no-unused-expressions': 'off', |
| 218 | + 'unicorn/prefer-node-protocol': 'off', |
| 219 | + 'sonarjs/no-nested-assignment': 'off', |
| 220 | + 'sonarjs/no-alphabetical-sort': 'off', |
| 221 | + }, |
| 222 | + }, |
| 223 | + |
| 224 | + { |
| 225 | + files: ['**/*.spec.ts'], |
| 226 | + |
| 227 | + rules: { |
| 228 | + 'sonarjs/no-hardcoded-ip': 'off', |
| 229 | + 'sonarjs/no-clear-text-protocols': 'off', |
| 230 | + 'sonarjs/slow-regex': 'off', |
| 231 | + 'sonarjs/publicly-writable-directories': 'off', |
| 232 | + }, |
| 233 | + }, |
| 234 | +]; |
0 commit comments