|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +import js from '@eslint/js' |
| 18 | +import i18n from '@m6web/eslint-plugin-i18n'; |
| 19 | +import headers from 'eslint-plugin-headers'; |
| 20 | +import i18next from 'eslint-plugin-i18next'; |
| 21 | +import * as importPlugin from 'eslint-plugin-import'; |
| 22 | +import playwright from 'eslint-plugin-playwright' |
| 23 | +import react from 'eslint-plugin-react' |
| 24 | +import reactHooks from 'eslint-plugin-react-hooks' |
| 25 | +import reactRefresh from 'eslint-plugin-react-refresh' |
| 26 | +import simpleImportSort from 'eslint-plugin-simple-import-sort' |
| 27 | +import unusedImports from 'eslint-plugin-unused-imports' |
| 28 | +import globals from 'globals' |
| 29 | +import tseslint from 'typescript-eslint' |
| 30 | + |
| 31 | +const importRules = tseslint.config({ |
| 32 | + plugins: { |
| 33 | + 'unused-imports': unusedImports, |
| 34 | + 'simple-import-sort': simpleImportSort, |
| 35 | + 'import': importPlugin, |
| 36 | + }, |
| 37 | + rules: { |
| 38 | + 'no-unused-vars': 'off', |
| 39 | + 'unused-imports/no-unused-imports': 'error', |
| 40 | + 'unused-imports/no-unused-vars': [ |
| 41 | + 'warn', |
| 42 | + { |
| 43 | + 'vars': 'all', |
| 44 | + 'varsIgnorePattern': '^_', |
| 45 | + 'args': 'after-used', |
| 46 | + 'argsIgnorePattern': '^_', |
| 47 | + }, |
| 48 | + ], |
| 49 | + 'simple-import-sort/imports': 'error', |
| 50 | + 'simple-import-sort/exports': 'error', |
| 51 | + 'import/first': 'error', |
| 52 | + 'import/newline-after-import': 'error', |
| 53 | + 'import/no-duplicates': 'error', |
| 54 | + 'import/no-unresolved': 'off', |
| 55 | + 'import/no-named-as-default-member': 'off', |
| 56 | + } |
| 57 | +}) |
| 58 | + |
| 59 | +const e2eRules = tseslint.config({ |
| 60 | + extends: [importRules], |
| 61 | + ...playwright.configs['flat/recommended'], |
| 62 | + files: ['e2e/**/*.spec.ts'], |
| 63 | + rules: { |
| 64 | + ...playwright.configs['flat/recommended'].rules, |
| 65 | + }, |
| 66 | +}); |
| 67 | + |
| 68 | +const i18nRules = tseslint.config({ |
| 69 | + files: ['src/**/*.{ts,tsx,js}'], |
| 70 | + plugins: { |
| 71 | + i18next: i18next, |
| 72 | + i18n: i18n, |
| 73 | + }, |
| 74 | + rules: { |
| 75 | + ...i18next.configs['flat/recommended'].rules, |
| 76 | + 'i18n/no-unknown-key': 'error', |
| 77 | + 'i18n/no-text-as-children': [ |
| 78 | + 'error', |
| 79 | + { ignorePattern: '^\\s?[/.]\\s?$' }, |
| 80 | + ], |
| 81 | + 'i18n/no-text-as-attribute': ['error', { attributes: ['alt', 'title'] }], |
| 82 | + 'i18n/interpolation-data': [ |
| 83 | + 'error', |
| 84 | + { interpolationPattern: '\\{\\.+\\}' }, |
| 85 | + ], |
| 86 | + }, |
| 87 | + settings: { |
| 88 | + i18n: { |
| 89 | + principalLangs: [ |
| 90 | + { |
| 91 | + name: 'en', |
| 92 | + translationPath: 'src/locales/en/common.json', |
| 93 | + }, |
| 94 | + ], |
| 95 | + functionName: 't', |
| 96 | + }, |
| 97 | + }, |
| 98 | +}) |
| 99 | + |
| 100 | +export default tseslint.config( |
| 101 | + { ignores: ['dist', 'src/routeTree.gen.ts'] }, |
| 102 | + e2eRules, |
| 103 | + i18nRules, |
| 104 | + { |
| 105 | + extends: [js.configs.recommended, ...tseslint.configs.recommended, importRules], |
| 106 | + files: ['src/**/*.{ts,tsx}', 'eslint.config.ts'], |
| 107 | + languageOptions: { |
| 108 | + ecmaVersion: 2020, |
| 109 | + globals: globals.browser, |
| 110 | + sourceType: 'module', |
| 111 | + }, |
| 112 | + plugins: { |
| 113 | + 'react-hooks': reactHooks, |
| 114 | + 'react-refresh': reactRefresh, |
| 115 | + react: react, |
| 116 | + 'unused-imports': unusedImports, |
| 117 | + 'simple-import-sort': simpleImportSort, |
| 118 | + import: importPlugin, |
| 119 | + headers: headers, |
| 120 | + }, |
| 121 | + settings: { |
| 122 | + react: { |
| 123 | + version: 'detect', |
| 124 | + }, |
| 125 | + }, |
| 126 | + rules: { |
| 127 | + ...react.configs.flat.recommended.rules, |
| 128 | + ...react.configs.flat['jsx-runtime'].rules, |
| 129 | + ...reactHooks.configs.recommended.rules, |
| 130 | + ...importPlugin.flatConfigs?.recommended.rules, |
| 131 | + ...importPlugin.flatConfigs?.typescript.rules, |
| 132 | + 'no-console': 'warn', |
| 133 | + 'no-unused-vars': 'off', |
| 134 | + 'unused-imports/no-unused-imports': 'error', |
| 135 | + 'unused-imports/no-unused-vars': [ |
| 136 | + 'warn', |
| 137 | + { |
| 138 | + vars: 'all', |
| 139 | + varsIgnorePattern: '^_', |
| 140 | + args: 'after-used', |
| 141 | + argsIgnorePattern: '^_', |
| 142 | + }, |
| 143 | + ], |
| 144 | + 'simple-import-sort/imports': 'error', |
| 145 | + 'simple-import-sort/exports': 'error', |
| 146 | + 'import/first': 'error', |
| 147 | + 'import/newline-after-import': 'error', |
| 148 | + 'import/no-duplicates': 'error', |
| 149 | + 'import/no-unresolved': 'off', |
| 150 | + 'import/no-named-as-default-member': 'off', |
| 151 | + 'react-refresh/only-export-components': [ |
| 152 | + 'warn', |
| 153 | + { allowConstantExport: true }, |
| 154 | + ], |
| 155 | + 'react/jsx-curly-brace-presence': [ |
| 156 | + 'error', |
| 157 | + { |
| 158 | + props: 'never', |
| 159 | + children: 'never', |
| 160 | + }, |
| 161 | + ], |
| 162 | + 'react/no-unescaped-entities': [ |
| 163 | + 'error', |
| 164 | + { |
| 165 | + forbid: ['>', '}'], |
| 166 | + }, |
| 167 | + ], |
| 168 | + 'react/no-children-prop': [ |
| 169 | + 'error', |
| 170 | + { |
| 171 | + allowFunctions: true, |
| 172 | + }, |
| 173 | + ], |
| 174 | + 'react/self-closing-comp': [ |
| 175 | + 'error', |
| 176 | + { |
| 177 | + component: true, |
| 178 | + html: true, |
| 179 | + }, |
| 180 | + ], |
| 181 | + 'headers/header-format': [ |
| 182 | + 'error', |
| 183 | + { |
| 184 | + source: 'file', |
| 185 | + path: '.actions/ASFLicenseHeader.txt', |
| 186 | + }, |
| 187 | + ], |
| 188 | + 'quotes': [ |
| 189 | + 'error', |
| 190 | + 'single', |
| 191 | + { |
| 192 | + 'avoidEscape': true, |
| 193 | + 'allowTemplateLiterals': false |
| 194 | + } |
| 195 | + ], |
| 196 | + }, |
| 197 | + } |
| 198 | +); |
0 commit comments