browsertrix/frontend/.eslintrc.js
Emma Segal-Grossman b15c5ccddd
ESLint & Typescript fixes (#1407)
Closes #1405

- Properly uses `typescript-eslint`: we were missing the preset from it,
so some of the default `eslint` rules (that don't properly work with
typescript) were being applied and causing false positives
- I also moved the `eslint` config into its own file, and enabled
`typescript-eslint`'s type-awareness, so that we can enable more
type-aware rules in the future if we like
- Adds `ts-lit-plugin` to the typescript config, which _hopefully_ will
allow us to catch issues during build (in CI)
- It looks like `ts-lit-plugin` is sort of abandonware at the moment,
and unfortunately _doesn't_ actually work for this purpose right now,
but the lit team is working on a replacement here:
https://www.npmjs.com/package/@lit-labs/analyzer
- Adds `fork-ts-checker-webpack-plugin`, which allows the typescript
checking process to be run on a separate forked thread in Webpack, which
can help speed up builds & checking
- Enables incremental type checking for better speed
- Fixes a whole bunch of `eslint`-auto-fixable issues (unused imports
and variables, some type issues, etc)
- Fixes a bunch of `lit-analyzer` issues (mostly attribute naming, some
type issues as well)
- Fixes various other type issues:
- Improves type safety in a bunch of places, notably anywhere `apiFetch`
and `APIPaginatedList` are used
  - Removes some `any`s
2023-11-24 12:32:53 -05:00

48 lines
1.2 KiB
JavaScript

/** @type {import('eslint').Linter.Config} */
module.exports = {
parser: "@typescript-eslint/parser",
env: {
browser: true,
commonjs: true,
es2017: true,
},
extends: [
"plugin:wc/recommended",
"plugin:lit/recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
plugins: ["@typescript-eslint", "lit"],
parserOptions: {
project: ["./tsconfig.eslint.json"],
tsconfigRootDir: __dirname,
},
root: true,
rules: {
"no-restricted-globals": [2, "event", "error"],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
},
],
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/consistent-type-exports": "error",
"@typescript-eslint/no-explicit-any": "warn",
},
reportUnusedDisableDirectives: true,
ignorePatterns: ["__generated__", "__mocks__"],
overrides: [
{
extends: ["plugin:@typescript-eslint/disable-type-checked"],
files: ["webpack.*.js"],
rules: {
"@typescript-eslint/no-var-requires": "off",
},
},
],
};