|
| 1 | +import path from "path"; |
| 2 | +import { fileURLToPath } from "url"; |
| 3 | + |
| 4 | +import { defineConfig, globalIgnores } from "eslint/config"; |
| 5 | + |
| 6 | +import tsParser from "@typescript-eslint/parser"; |
| 7 | +import typescriptEslint from "@typescript-eslint/eslint-plugin"; |
| 8 | +import unusedImports from "eslint-plugin-unused-imports"; |
| 9 | +import workspaces from "eslint-plugin-workspaces"; |
| 10 | +import notice from "eslint-plugin-notice"; |
| 11 | +import globals from "globals"; |
| 12 | +import js from "@eslint/js"; |
| 13 | +import reactNamingConvention from "eslint-plugin-react-naming-convention"; |
| 14 | +import extraneousDependencies from "eslint-plugin-import"; |
| 15 | +import { FlatCompat } from "@eslint/eslintrc"; |
| 16 | +import nodePlugin from "eslint-plugin-n"; |
| 17 | + |
| 18 | +const __filename = fileURLToPath(import.meta.url); |
| 19 | +const __dirname = path.dirname(__filename); |
| 20 | + |
| 21 | +const compat = new FlatCompat({ |
| 22 | + baseDirectory: __dirname, |
| 23 | + recommendedConfig: js.configs.recommended, |
| 24 | + allConfig: js.configs.all, |
| 25 | +}); |
| 26 | + |
| 27 | +export default defineConfig([ |
| 28 | + ...compat.extends( |
| 29 | + "eslint:recommended", |
| 30 | + "prettier", |
| 31 | + "plugin:@typescript-eslint/recommended", |
| 32 | + "plugin:workspaces/recommended", |
| 33 | + "plugin:n/recommended" |
| 34 | + ), |
| 35 | + // |
| 36 | + nodePlugin.configs["flat/recommended-script"], |
| 37 | + { |
| 38 | + languageOptions: { |
| 39 | + parser: tsParser, |
| 40 | + parserOptions: { |
| 41 | + tsconfigRootDir: __dirname, |
| 42 | + project: ["./tsconfig.eslint.json"], |
| 43 | + }, |
| 44 | + globals: { |
| 45 | + ...globals.node, |
| 46 | + }, |
| 47 | + }, |
| 48 | + plugins: { |
| 49 | + "@typescript-eslint": typescriptEslint, |
| 50 | + "unused-imports": unusedImports, |
| 51 | + workspaces, |
| 52 | + notice, |
| 53 | + "react-naming-convention": reactNamingConvention, |
| 54 | + "extraneous-dependencies": extraneousDependencies, |
| 55 | + n: nodePlugin, |
| 56 | + }, |
| 57 | + |
| 58 | + rules: { |
| 59 | + // *************** Ensure that copyright notice is present *************** |
| 60 | + "notice/notice": [ |
| 61 | + "error", |
| 62 | + { |
| 63 | + mustMatch: "Copyright \\(c\\) [0-9]{0,4} Contributors to the Eclipse Foundation", |
| 64 | + templateFile: __dirname + "/license.template.txt", |
| 65 | + onNonMatchingHeader: "replace", |
| 66 | + }, |
| 67 | + ], |
| 68 | + |
| 69 | + // *************** NodeJS specific rules - relaxing default setting of n ***************cs |
| 70 | + "n/no-path-concat": "error", |
| 71 | + "n/no-unsupported-features/es-syntax": [ |
| 72 | + "error", |
| 73 | + { |
| 74 | + ignores: ["modules"], |
| 75 | + }, |
| 76 | + ], |
| 77 | + |
| 78 | + // relax missing import rule to warning, as we sometimes have optional dependencies |
| 79 | + // import "../foo" will braise a warning , |
| 80 | + // import "../foo.js" is the correct way to import a file that may not exist |
| 81 | + "n/no-missing-import": "warn", |
| 82 | + |
| 83 | + "n/no-unsupported-features/node-builtins": "warn", |
| 84 | + "n/no-extraneous-import": "warn", |
| 85 | + "n/no-deprecated-api": "warn", |
| 86 | + "n/no-unpublished-import": "warn", |
| 87 | + "n/no-process-exit": "warn", |
| 88 | + "n/hashbang": "warn", |
| 89 | + |
| 90 | + // *************** Ensure that only used dependencies are imported *************** |
| 91 | + "extraneous-dependencies/no-extraneous-dependencies": "warn", |
| 92 | + |
| 93 | + // *************** Code style and best practices *************** |
| 94 | + "unused-imports/no-unused-imports": "error", |
| 95 | + "unused-imports/no-unused-vars": [ |
| 96 | + "warn", |
| 97 | + { |
| 98 | + args: "none", |
| 99 | + varsIgnorePattern: "Test", |
| 100 | + }, |
| 101 | + ], |
| 102 | + |
| 103 | + // **************** enforece kebab-case for filenames **************** |
| 104 | + "react-naming-convention/filename": [ |
| 105 | + "warn", |
| 106 | + { |
| 107 | + rule: "kebab-case", |
| 108 | + }, |
| 109 | + ], |
| 110 | + |
| 111 | + // *************** Customization of other typescript rules *************** |
| 112 | + "@typescript-eslint/no-use-before-define": "error", |
| 113 | + "@typescript-eslint/no-unused-vars": "off", |
| 114 | + "@typescript-eslint/no-unused-expressions": "off", |
| 115 | + "@typescript-eslint/no-require-imports": "warn", |
| 116 | + "@typescript-eslint/prefer-nullish-coalescing": "warn", |
| 117 | + "@typescript-eslint/no-empty-object-type": "warn", |
| 118 | + |
| 119 | + // **************** Enforce usage of `const` over `let` wherever possible, to prevent accidental reassignments |
| 120 | + "prefer-const": "warn", |
| 121 | + |
| 122 | + // *************** Other rules *************** |
| 123 | + "no-restricted-globals": "error", |
| 124 | + "no-restricted-properties": "error", |
| 125 | + |
| 126 | + "no-use-before-define": "error", |
| 127 | + |
| 128 | + "no-unused-private-class-members": "warn", |
| 129 | + "no-prototype-builtins": "off", |
| 130 | + "no-case-declarations": "off", |
| 131 | + |
| 132 | + // ***************** Enforce that for-in loops include an if statement to filter properties from the prototype chain |
| 133 | + "guard-for-in": "error", |
| 134 | + }, |
| 135 | + }, |
| 136 | + globalIgnores([ |
| 137 | + "utils/*", |
| 138 | + "packages/browser-bundle/types/index.d.ts", |
| 139 | + "packages/*/eslint.config.mjs", |
| 140 | + "eslint.config.mjs", |
| 141 | + "packages/browser-bundle/web-test-runner.config.mjs", |
| 142 | + "**/.eslintrc.js", |
| 143 | + "**/dist", |
| 144 | + "**/node_modules", |
| 145 | + "examples", |
| 146 | + "**/bin", |
| 147 | + "**/*.js", |
| 148 | + ]), |
| 149 | +]); |
0 commit comments