2021-07-20 14:50:37 +00:00
|
|
|
/** @type {import("eslint").Linter.Config } */
|
|
|
|
module.exports = {
|
|
|
|
root: true,
|
2022-09-12 09:52:11 +00:00
|
|
|
ignorePatterns: [
|
|
|
|
"node_modules",
|
|
|
|
"dist",
|
|
|
|
"keycloak-theme",
|
|
|
|
"server",
|
|
|
|
// Keycloak JS follows a completely different and outdated style, so we'll exclude it for now.
|
|
|
|
// TODO: Eventually align the code-style for Keycloak JS.
|
|
|
|
"libs/keycloak-js",
|
|
|
|
],
|
2021-08-18 09:29:42 +00:00
|
|
|
parserOptions: {
|
2022-08-25 09:03:07 +00:00
|
|
|
tsconfigRootDir: __dirname,
|
2021-09-16 10:24:21 +00:00
|
|
|
project: "./tsconfig.eslint.json",
|
|
|
|
extraFileExtensions: [".mjs"],
|
2021-08-18 09:29:42 +00:00
|
|
|
},
|
2021-07-20 14:50:37 +00:00
|
|
|
env: {
|
|
|
|
node: true,
|
|
|
|
},
|
2022-02-02 10:33:57 +00:00
|
|
|
plugins: ["lodash"],
|
2021-07-20 14:50:37 +00:00
|
|
|
extends: [
|
|
|
|
"eslint:recommended",
|
2022-11-18 16:13:39 +00:00
|
|
|
"plugin:import/recommended",
|
|
|
|
"plugin:import/typescript",
|
2021-07-20 14:50:37 +00:00
|
|
|
"plugin:react/recommended",
|
2022-08-03 12:12:07 +00:00
|
|
|
"plugin:react/jsx-runtime",
|
2023-06-01 09:56:06 +00:00
|
|
|
"plugin:react-hooks/recommended",
|
2021-07-20 14:50:37 +00:00
|
|
|
"plugin:@typescript-eslint/base",
|
|
|
|
"plugin:@typescript-eslint/eslint-recommended",
|
|
|
|
"plugin:prettier/recommended",
|
|
|
|
],
|
|
|
|
settings: {
|
|
|
|
react: {
|
|
|
|
version: "detect",
|
|
|
|
},
|
2022-11-18 16:13:39 +00:00
|
|
|
"import/resolver": {
|
|
|
|
typescript: true,
|
|
|
|
node: true,
|
|
|
|
},
|
2021-07-20 14:50:37 +00:00
|
|
|
},
|
|
|
|
rules: {
|
2021-08-18 09:29:42 +00:00
|
|
|
// Prefer using `includes()` to check if values exist over `indexOf() === -1`, as it's a more appropriate API for this.
|
|
|
|
"@typescript-eslint/prefer-includes": "error",
|
|
|
|
// Prefer using an optional chain expression, as it's more concise and easier to read.
|
2021-08-12 11:15:47 +00:00
|
|
|
"@typescript-eslint/prefer-optional-chain": "error",
|
2021-07-20 14:50:37 +00:00
|
|
|
"no-unused-vars": "off",
|
2021-07-27 20:56:16 +00:00
|
|
|
"@typescript-eslint/no-empty-function": "error",
|
2021-09-08 09:59:14 +00:00
|
|
|
"@typescript-eslint/no-unnecessary-condition": "warn",
|
|
|
|
"@typescript-eslint/no-unused-vars": "error",
|
2022-02-02 10:33:57 +00:00
|
|
|
"lodash/import-scope": ["error", "member"],
|
2021-08-10 11:14:16 +00:00
|
|
|
// react/prop-types cannot handle generic props, so we need to disable it.
|
|
|
|
// https://github.com/yannickcr/eslint-plugin-react/issues/2777#issuecomment-814968432
|
|
|
|
"react/prop-types": "off",
|
2021-08-26 12:15:28 +00:00
|
|
|
// Prevent fragments from being added that have only a single child.
|
2021-09-01 05:55:53 +00:00
|
|
|
"react/jsx-no-useless-fragment": "error",
|
2023-01-31 11:34:33 +00:00
|
|
|
// Ban nesting components, as this will cause unintended re-mounting of components.
|
|
|
|
// TODO: All issues should be fixed and this rule should be set to "error".
|
|
|
|
"react/no-unstable-nested-components": ["warn", { allowAsProps: true }],
|
2021-10-04 06:03:19 +00:00
|
|
|
"prefer-arrow-callback": "error",
|
2021-09-01 05:55:53 +00:00
|
|
|
"prettier/prettier": [
|
|
|
|
"error",
|
|
|
|
{
|
|
|
|
endOfLine: "auto",
|
|
|
|
},
|
|
|
|
],
|
2022-08-03 12:12:07 +00:00
|
|
|
// Prevent default imports from React, named imports should be used instead.
|
|
|
|
"no-restricted-imports": [
|
|
|
|
"error",
|
|
|
|
{
|
|
|
|
paths: [
|
|
|
|
{
|
|
|
|
name: "react",
|
|
|
|
importNames: ["default"],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2023-10-23 18:12:55 +00:00
|
|
|
// Prefer using the `#private` syntax for private class members, we want to keep this consistent and use the same syntax.
|
|
|
|
"no-restricted-syntax": [
|
|
|
|
"error",
|
|
|
|
{
|
|
|
|
selector:
|
|
|
|
':matches(PropertyDefinition, MethodDefinition)[accessibility="private"]',
|
|
|
|
message: "Use #private instead",
|
|
|
|
},
|
|
|
|
],
|
2021-07-20 14:50:37 +00:00
|
|
|
},
|
2021-07-27 20:56:16 +00:00
|
|
|
overrides: [
|
|
|
|
{
|
|
|
|
files: ["*.test.*"],
|
|
|
|
rules: {
|
|
|
|
// For tests it can make sense to pass empty functions as mocks.
|
|
|
|
"@typescript-eslint/no-empty-function": "off",
|
|
|
|
},
|
|
|
|
},
|
2021-09-16 10:24:21 +00:00
|
|
|
{
|
2022-08-25 12:11:12 +00:00
|
|
|
files: ["**/cypress/**/*"],
|
2022-08-23 14:30:52 +00:00
|
|
|
extends: ["plugin:cypress/recommended", "plugin:mocha/recommended"],
|
2021-09-16 10:24:21 +00:00
|
|
|
// TODO: Set these rules to "error" when issues have been resolved.
|
|
|
|
rules: {
|
|
|
|
"cypress/no-unnecessary-waiting": "warn",
|
2023-03-30 10:34:14 +00:00
|
|
|
"cypress/unsafe-to-chain-command": "warn",
|
2022-08-23 14:30:52 +00:00
|
|
|
"mocha/max-top-level-suites": "off",
|
|
|
|
"mocha/no-exclusive-tests": "error",
|
|
|
|
"mocha/no-identical-title": "off",
|
|
|
|
"mocha/no-mocha-arrows": "off",
|
|
|
|
"mocha/no-setup-in-describe": "off",
|
2021-09-16 10:24:21 +00:00
|
|
|
},
|
|
|
|
},
|
2021-07-27 20:56:16 +00:00
|
|
|
],
|
2021-07-20 14:50:37 +00:00
|
|
|
};
|