|
| 1 | +/* |
| 2 | +Copyright 2024 Adobe. All rights reserved. |
| 3 | +This file is licensed to you under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. You may obtain a copy |
| 5 | +of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +
|
| 7 | +Unless required by applicable law or agreed to in writing, software distributed under |
| 8 | +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS |
| 9 | +OF ANY KIND, either express or implied. See the License for the specific language |
| 10 | +governing permissions and limitations under the License. |
| 11 | +*/ |
| 12 | + |
| 13 | +import { FlatCompat } from '@eslint/eslintrc'; |
| 14 | +// eslint-disable-next-line import/no-unresolved |
| 15 | +import { defineConfig, globalIgnores } from 'eslint/config'; |
| 16 | +import pluginJs from '@eslint/js'; |
| 17 | +import path from 'path'; |
| 18 | +import { fileURLToPath } from 'url'; |
| 19 | +import { glob } from 'glob'; |
| 20 | +import globals from 'globals'; |
| 21 | +import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'; |
| 22 | +import vitest from '@vitest/eslint-plugin'; |
| 23 | + |
| 24 | +const allComponentPaths = glob.sync('src/components/*/'); |
| 25 | +const filename = fileURLToPath(import.meta.url); |
| 26 | +const dirname = path.dirname(filename); |
| 27 | + |
| 28 | +const compat = new FlatCompat({ |
| 29 | + baseDirectory: dirname |
| 30 | +}); |
| 31 | + |
| 32 | +export default defineConfig([ |
| 33 | + ...compat.extends('airbnb-base'), |
| 34 | + globalIgnores(['src/__tests_helpers__/largeJsonResponse.json']), |
| 35 | + { |
| 36 | + files: ['**/*.{js,cjs,jsx}'], |
| 37 | + settings: { |
| 38 | + 'import/resolver': { |
| 39 | + node: { |
| 40 | + extensions: ['.js', '.cjs', '.mjs', '.jsx'] |
| 41 | + } |
| 42 | + } |
| 43 | + }, |
| 44 | + languageOptions: { |
| 45 | + ecmaVersion: 2021, |
| 46 | + globals: { |
| 47 | + ...globals.node |
| 48 | + } |
| 49 | + }, |
| 50 | + rules: { |
| 51 | + 'no-param-reassign': 'off', |
| 52 | + 'prettier/prettier': 'error', |
| 53 | + 'func-style': 'error', |
| 54 | + // Turning this off allows us to import devDependencies in our build tools. |
| 55 | + // We enable the rule in src/.eslintrc.js since that's the only place we |
| 56 | + // want to disallow importing extraneous dependencies. |
| 57 | + 'import/no-extraneous-dependencies': 'off', |
| 58 | + 'prefer-destructuring': 'off', |
| 59 | + 'import/prefer-default-export': 'off', |
| 60 | + 'import/no-restricted-paths': [ |
| 61 | + 'error', |
| 62 | + { |
| 63 | + zones: [ |
| 64 | + // prevent components from importing from other components, but allow |
| 65 | + // importing from themselves |
| 66 | + ...allComponentPaths.map((componentPath, _, allPaths) => ({ |
| 67 | + target: componentPath, |
| 68 | + from: [ |
| 69 | + 'src/core', |
| 70 | + 'src/baseCode', |
| 71 | + ...allPaths.filter((p) => p !== componentPath) |
| 72 | + ] |
| 73 | + })), |
| 74 | + { |
| 75 | + target: 'src/core', |
| 76 | + from: 'src/baseCode' |
| 77 | + }, |
| 78 | + { |
| 79 | + target: 'src/utils', |
| 80 | + from: ['src/core', 'src/components', 'src/baseCode'] |
| 81 | + }, |
| 82 | + { |
| 83 | + target: 'src/constants', |
| 84 | + from: ['src/core', 'src/components', 'src/utils', 'src/baseCode'] |
| 85 | + } |
| 86 | + ] |
| 87 | + } |
| 88 | + ] |
| 89 | + } |
| 90 | + }, |
| 91 | + { |
| 92 | + files: ['src/**/*.{cjs,js}'], |
| 93 | + languageOptions: { |
| 94 | + globals: { |
| 95 | + turbine: 'readonly' |
| 96 | + } |
| 97 | + }, |
| 98 | + rules: { |
| 99 | + 'import/no-extraneous-dependencies': 'error' |
| 100 | + } |
| 101 | + }, |
| 102 | + { |
| 103 | + files: ['test/unit/specs/**/*.{cjs,js}'], |
| 104 | + plugins: { |
| 105 | + vitest |
| 106 | + }, |
| 107 | + rules: { |
| 108 | + ...vitest.configs.recommended.rules |
| 109 | + } |
| 110 | + }, |
| 111 | + { |
| 112 | + files: ['test/**/*.{cjs,js}'], |
| 113 | + rules: { |
| 114 | + 'import/extensions': [ |
| 115 | + 'error', |
| 116 | + { |
| 117 | + js: 'always' |
| 118 | + } |
| 119 | + ] |
| 120 | + } |
| 121 | + }, |
| 122 | + { |
| 123 | + files: ['scripts/**/*.{cjs,js}'], |
| 124 | + rules: { |
| 125 | + 'no-console': 'off', |
| 126 | + 'import/extensions': [ |
| 127 | + 'error', |
| 128 | + { |
| 129 | + js: 'always' |
| 130 | + } |
| 131 | + ] |
| 132 | + } |
| 133 | + }, |
| 134 | + |
| 135 | + pluginJs.configs.recommended, |
| 136 | + eslintPluginPrettierRecommended |
| 137 | +]); |
0 commit comments