|
| 1 | +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | +import { includeIgnoreFile } from "@eslint/compat"; |
| 4 | +import eslint from "@eslint/js"; |
| 5 | +import headerPlugin from "eslint-plugin-header"; |
| 6 | +import noUnsanitizedPlugin from "eslint-plugin-no-unsanitized"; |
| 7 | +import eslintPrettier from "eslint-plugin-prettier/recommended"; |
| 8 | +import reactPlugin from "eslint-plugin-react"; |
| 9 | +import reactHooksPlugin from "eslint-plugin-react-hooks"; |
| 10 | +import simpleImportSortPlugin from "eslint-plugin-simple-import-sort"; |
| 11 | +import unicornPlugin from "eslint-plugin-unicorn"; |
| 12 | +import globals from "globals"; |
| 13 | +import path from "node:path"; |
| 14 | +import tsEslint from "typescript-eslint"; |
| 15 | + |
| 16 | +import cloudscapeCommonRules from "@cloudscape-design/build-tools/eslint/index.js"; |
| 17 | + |
| 18 | +// https://github.com/Stuk/eslint-plugin-header/issues/57 |
| 19 | +headerPlugin.rules.header.meta.schema = false; |
| 20 | + |
| 21 | +export default tsEslint.config( |
| 22 | + includeIgnoreFile(path.resolve(".gitignore")), |
| 23 | + { |
| 24 | + settings: { |
| 25 | + react: { version: "detect" }, |
| 26 | + }, |
| 27 | + }, |
| 28 | + eslint.configs.recommended, |
| 29 | + tsEslint.configs.recommended, |
| 30 | + noUnsanitizedPlugin.configs.recommended, |
| 31 | + reactPlugin.configs.flat.recommended, |
| 32 | + reactPlugin.configs.flat["jsx-runtime"], |
| 33 | + reactHooksPlugin.configs["recommended-latest"], |
| 34 | + eslintPrettier, |
| 35 | + { |
| 36 | + files: ["**/*.{js,mjs,ts,tsx}"], |
| 37 | + languageOptions: { |
| 38 | + globals: { |
| 39 | + ...globals.browser, |
| 40 | + }, |
| 41 | + }, |
| 42 | + plugins: { |
| 43 | + "@cloudscape-design/build-tools": cloudscapeCommonRules, |
| 44 | + "simple-import-sort": simpleImportSortPlugin, |
| 45 | + unicorn: unicornPlugin, |
| 46 | + header: headerPlugin, |
| 47 | + }, |
| 48 | + rules: { |
| 49 | + "@typescript-eslint/no-unused-expressions": ["error", { allowTernary: true }], |
| 50 | + "@typescript-eslint/ban-ts-comment": ["error", { "ts-expect-error": "allow-with-description" }], |
| 51 | + "@typescript-eslint/no-namespace": "off", |
| 52 | + "@typescript-eslint/no-unused-vars": "error", |
| 53 | + "@typescript-eslint/consistent-type-definitions": ["error", "interface"], |
| 54 | + "@typescript-eslint/no-explicit-any": "off", |
| 55 | + "@cloudscape-design/build-tools/react-server-components-directive": "error", |
| 56 | + "react/display-name": "off", |
| 57 | + "react/no-danger": "error", |
| 58 | + "react/no-unstable-nested-components": ["error", { allowAsProps: true }], |
| 59 | + "react/prop-types": "off", |
| 60 | + "react/jsx-boolean-value": ["error", "always"], |
| 61 | + "@typescript-eslint/naming-convention": [ |
| 62 | + "error", |
| 63 | + { |
| 64 | + selector: "typeLike", |
| 65 | + format: ["PascalCase"], |
| 66 | + }, |
| 67 | + ], |
| 68 | + "react-hooks/exhaustive-deps": ["error"], |
| 69 | + "unicorn/filename-case": "error", |
| 70 | + curly: "error", |
| 71 | + "dot-notation": "error", |
| 72 | + eqeqeq: "error", |
| 73 | + "no-return-await": "error", |
| 74 | + "require-await": "error", |
| 75 | + "header/header": [ |
| 76 | + "error", |
| 77 | + "line", |
| 78 | + [" Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.", " SPDX-License-Identifier: Apache-2.0"], |
| 79 | + ], |
| 80 | + "no-warning-comments": "warn", |
| 81 | + "simple-import-sort/imports": [ |
| 82 | + "error", |
| 83 | + { |
| 84 | + groups: [ |
| 85 | + // External packages come first. |
| 86 | + ["^react", "^(?!@cloudscape)@?\\w"], |
| 87 | + // Cloudscape packages. |
| 88 | + ["^@cloudscape"], |
| 89 | + // Things that start with a letter (or digit or underscore), or `~` followed by a letter. |
| 90 | + ["^~\\w"], |
| 91 | + // Anything not matched in another group. |
| 92 | + ["^"], |
| 93 | + // Styles come last. |
| 94 | + ["^.+\\.?(css)$", "^.+\\.?(css.js)$", "^.+\\.?(scss)$", "^.+\\.?(selectors.js)$"], |
| 95 | + ], |
| 96 | + }, |
| 97 | + ], |
| 98 | + }, |
| 99 | + }, |
| 100 | + { |
| 101 | + files: ["test/**"], |
| 102 | + rules: { |
| 103 | + // useBrowser is not a hook |
| 104 | + "react-hooks/rules-of-hooks": "off", |
| 105 | + }, |
| 106 | + }, |
| 107 | +); |
0 commit comments