|
| 1 | +parser: "@typescript-eslint/parser" |
| 2 | + |
| 3 | +parserOptions: |
| 4 | + # allows for ES Modules |
| 5 | + sourceType: "module" |
| 6 | + # maps our tsconfig with appropriate settings (e.g. paths) to eslint |
| 7 | + project: "./tsconfig.json" |
| 8 | + # default recommended settings from vite // alligned with tsconfig |
| 9 | + ecmaVersion: 2020 |
| 10 | + ecmaFeatures: |
| 11 | + # enables to parse jsx code (react components) |
| 12 | + jsx: true |
| 13 | + |
| 14 | +env: |
| 15 | + # allows for browser specific globals like window, document etc. |
| 16 | + browser: true |
| 17 | + # allows for jest specific globals like test, expect etc. |
| 18 | + jest: true |
| 19 | + |
| 20 | +plugins: |
| 21 | + - "prettier" |
| 22 | + - "jest" |
| 23 | + - "promise" |
| 24 | + - "@typescript-eslint" |
| 25 | + |
| 26 | +# Important Note: The order of rules IS NOT ARBITRARY, but follows a specific order of precedence |
| 27 | +extends: |
| 28 | + # --------------------------- Core ------------------------------ |
| 29 | + # create basis for all JS rules, neutral opinions |
| 30 | + - "eslint:recommended" |
| 31 | + |
| 32 | + # create basis for all TS rules, neutral opinions, enhanced with typed-linting |
| 33 | + - "plugin:@typescript-eslint/strict-type-checked" |
| 34 | + - "plugin:@typescript-eslint/stylistic-type-checked" |
| 35 | + |
| 36 | + # this introduces React rules and overrides some of the JS and TS rules in favor of AirBnB opinions |
| 37 | + - airbnb |
| 38 | + - airbnb-typescript |
| 39 | + - airbnb/hooks |
| 40 | + |
| 41 | + # --------------------------- Additional JS --------------------- |
| 42 | + # NOTE: Make sure that none of the introduced rules conflict with the airbnb rules |
| 43 | + # suprisingly AirBnB has neither opinions on promises nor deprecations |
| 44 | + - "plugin:promise/recommended" |
| 45 | + - "plugin:deprecation/recommended" |
| 46 | + |
| 47 | + # --------------------------- Additional Libraries --------------- |
| 48 | + # -- JEST -- |
| 49 | + - "plugin:jest/recommended" |
| 50 | + - "plugin:jest/style" |
| 51 | + # -- STORYBOOK -- |
| 52 | + # NOTE: Quote from docs: "This plugin will only be applied to files following the *.stories.* (we recommend this) or *.story.* pattern." |
| 53 | + # Its recommended to lint also the config files in .storybook, which in our current file context, is painfull to achieve, so this is emmited. |
| 54 | + # It would not have made any major difference anyhow, can only help with mistyped addon names, we will survive without it... |
| 55 | + - "plugin:storybook/recommended" |
| 56 | + |
| 57 | + # --------------------------- Formatting ------------------------- |
| 58 | + # NOTE: Needs to go very last, because the formatting rules should be enforced ONLY by prettier, overwriting some AirBnB rules |
| 59 | + - "plugin:prettier/recommended" |
| 60 | + |
| 61 | +rules: |
| 62 | + # --------------------------- RESTORATION ------------------------------- |
| 63 | + # Note: restoring airbnb rules |
| 64 | + # overwrites are introduced by import/resolver |
| 65 | + import/order: off |
| 66 | + import/extensions: |
| 67 | + - error |
| 68 | + - ignorePackages |
| 69 | + - { js: never, jsx: never, ts: never, tsx: never } |
| 70 | + |
| 71 | + # --------------------------- DEVIATIONS ------------------------------- |
| 72 | + # Note: deviations from rules which are required because default community guidelines might not consider the stack context |
| 73 | + |
| 74 | + # the default type-definitions from typescript-eslint enforces interfaces (for OOP usage), but because we are in react 16+ functional component context we should stick with types |
| 75 | + "@typescript-eslint/consistent-type-definitions": ["error", "type"] |
| 76 | + |
| 77 | + # react is brought default into scope, so we can disable this rule |
| 78 | + "react/react-in-jsx-scope": off |
| 79 | + |
| 80 | + # --------------------------- ADDITIONS ------------------------------- |
| 81 | + # In order to ensure consistency in type imports and exports we enforce the consistent type imports and exports rules |
| 82 | + # these will make sure that imports and exports that concern types are prefixed with the word "type" |
| 83 | + # also these imports / exports must not be mixed with actual runtime code related imports / exports |
| 84 | + # essentially the defaults of both rules are enforced |
| 85 | + "@typescript-eslint/consistent-type-exports": "error" |
| 86 | + "@typescript-eslint/consistent-type-imports": "error" |
| 87 | + |
| 88 | + # --------------------------- FORMATTING -------------------------- |
| 89 | + # lints falsely formated code, easier to fix and will be subsequently enforced by ci/cd as well |
| 90 | + prettier/prettier: "warn" |
| 91 | + |
| 92 | +settings: |
| 93 | + # makes sure that eslint can resolve aliased imports derived from the paths config in tsconfig |
| 94 | + import/resolver: |
| 95 | + typescript: |
| 96 | + # in case third party packages dont ship their types with them, but with a seperate package, this will help resolve eslint errors |
| 97 | + # example: lodash might have types in @types/lodash |
| 98 | + alwaysTryTypes: true |
| 99 | + # project key is not specified, because if omited, it will default to the tsconfig in the root of the project |
| 100 | + # meaning: project: "./tsconfig.json" |
| 101 | + react: |
| 102 | + # corresponding to the package.json version |
| 103 | + version: "detect" |
| 104 | + |
| 105 | +# --------------------------- Overrides ------------------------------ |
| 106 | +# Note: In general, always denote the reasoning for the override, so that the next person can understand the context |
| 107 | +overrides: |
| 108 | + # for index files, named exports should be allowed |
| 109 | + - files: ["index.ts", "index.tsx", "hooks.ts", "hooks.tsx"] |
| 110 | + rules: |
| 111 | + import/prefer-default-export: off |
| 112 | + # is located at src location, but runs devDeps only |
| 113 | + - files: ["vite.config.mts"] |
| 114 | + rules: |
| 115 | + import/no-extraneous-dependencies: off |
| 116 | + - files: ["**/*"] |
| 117 | + rules: |
| 118 | + # because we are not using defaultProps but defaultArguments, we need to augment the rule to resolve when default arguments are provided for the props |
| 119 | + react/require-default-props: |
| 120 | + - error |
| 121 | + - functions: "defaultArguments" |
| 122 | + # test files, usual naming does not apply do needs to re-disable certain rules |
| 123 | + - files: ["**/*tests.ts", "**/*tests.tsx"] |
| 124 | + rules: |
| 125 | + import/no-extraneous-dependencies: off |
0 commit comments