Preparation for https://github.com/webrecorder/archiveweb.page/issues/198 / https://github.com/webrecorder/archiveweb.page/pull/199. ## Changes - Organizes published files more cleanly, using `dist/types` folder as the target for type declarations and sourcemaps - Configures type field in `package.json` - Updates ESLint & its config - Sets up type-informed linting rules mirroring browsertrix - Adds a bunch of other useful eslint and eslint-typescript rules, and applies auto-fixes to the codebase - Cleans up a bunch of types throughout the codebase, particularly parts of the code used by ArchiveWebPage - Changes `ItemIndex#_deleting` from `private` to `protected` so that a part of AWP that extends it can do so properly - Makes a bunch of previously-implied [non-null assertions](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#non-null-assertion-operator-postfix-) explicit - Updates `URLResource` and `ItemType` types (and renames `Item` → `ItemType` to disambiguate from the `Item` class) - Removes `node-sass` and replaces it with `sass-embedded` for much quicker installs and compilation
111 lines
3.9 KiB
JavaScript
111 lines
3.9 KiB
JavaScript
/* eslint-env node */
|
|
/** @type {import('eslint').Linter.Config} */
|
|
module.exports = {
|
|
parser: "@typescript-eslint/parser",
|
|
env: {
|
|
browser: true,
|
|
commonjs: true,
|
|
es2017: true,
|
|
},
|
|
extends: [
|
|
"eslint:recommended",
|
|
"plugin:@typescript-eslint/eslint-recommended",
|
|
"plugin:wc/recommended",
|
|
"plugin:lit/recommended",
|
|
"prettier",
|
|
],
|
|
plugins: ["@typescript-eslint", "lit"],
|
|
parserOptions: {
|
|
project: ["./tsconfig.eslint.json"],
|
|
tsconfigRootDir: __dirname,
|
|
},
|
|
root: true,
|
|
rules: {
|
|
/* start stylistic rules */
|
|
"@typescript-eslint/adjacent-overload-signatures": "error",
|
|
"@typescript-eslint/array-type": "error",
|
|
"@typescript-eslint/consistent-type-imports": [
|
|
"error",
|
|
{
|
|
fixStyle: "inline-type-imports",
|
|
},
|
|
],
|
|
"@typescript-eslint/prefer-readonly": "warn",
|
|
"@typescript-eslint/class-literal-property-style": ["warn", "getters"],
|
|
"@typescript-eslint/consistent-generic-constructors": "error",
|
|
"@typescript-eslint/consistent-type-assertions": "error",
|
|
"@typescript-eslint/no-confusing-non-null-assertion": "warn",
|
|
"@typescript-eslint/no-inferrable-types": "warn",
|
|
"@typescript-eslint/non-nullable-type-assertion-style": "warn",
|
|
"@typescript-eslint/prefer-for-of": "warn",
|
|
// "@typescript-eslint/prefer-nullish-coalescing": "warn",
|
|
"@typescript-eslint/prefer-optional-chain": "warn",
|
|
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
|
/* end stylistic rules */
|
|
|
|
/* start recommended rules */
|
|
"no-restricted-globals": [2, "event", "error"],
|
|
"@typescript-eslint/no-base-to-string": "warn",
|
|
"@typescript-eslint/no-duplicate-enum-values": "error",
|
|
"@typescript-eslint/no-duplicate-type-constituents": "warn",
|
|
"@typescript-eslint/no-explicit-any": "warn",
|
|
"@typescript-eslint/no-extra-non-null-assertion": "error",
|
|
// "@typescript-eslint/no-floating-promises": "warn",
|
|
"@typescript-eslint/no-for-in-array": "warn",
|
|
"no-unused-vars": "off",
|
|
"@typescript-eslint/no-unused-vars": [
|
|
"warn",
|
|
{
|
|
argsIgnorePattern: "^_",
|
|
varsIgnorePattern: "^_",
|
|
destructuredArrayIgnorePattern: "^_",
|
|
},
|
|
],
|
|
"no-implied-eval": "off",
|
|
"@typescript-eslint/no-implied-eval": "error",
|
|
"no-loss-of-precision": "off",
|
|
"@typescript-eslint/no-loss-of-precision": "warn",
|
|
"@typescript-eslint/no-misused-new": "error",
|
|
"@typescript-eslint/no-misused-promises": [
|
|
"error",
|
|
{ checksVoidReturn: { arguments: false } },
|
|
],
|
|
"@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error",
|
|
"@typescript-eslint/no-non-null-asserted-optional-chain": "warn",
|
|
"@typescript-eslint/no-redundant-type-constituents": "warn",
|
|
"@typescript-eslint/no-this-alias": "warn",
|
|
"@typescript-eslint/no-unnecessary-type-assertion": "warn",
|
|
"@typescript-eslint/no-unnecessary-type-constraint": "warn",
|
|
// "@typescript-eslint/no-unsafe-argument": "warn",
|
|
// "@typescript-eslint/no-unsafe-assignment": "warn",
|
|
// "@typescript-eslint/no-unsafe-call": "warn",
|
|
"@typescript-eslint/no-unsafe-declaration-merging": "warn",
|
|
"@typescript-eslint/no-unsafe-enum-comparison": "warn",
|
|
// "@typescript-eslint/no-unsafe-member-access": "warn",
|
|
// "@typescript-eslint/no-unsafe-return": "warn",
|
|
"@typescript-eslint/prefer-as-const": "warn",
|
|
"require-await": "off",
|
|
"@typescript-eslint/require-await": "warn",
|
|
"@typescript-eslint/restrict-template-expressions": "warn",
|
|
"@typescript-eslint/unbound-method": "off",
|
|
},
|
|
reportUnusedDisableDirectives: true,
|
|
ignorePatterns: [
|
|
"__generated__",
|
|
"__mocks__",
|
|
"dist",
|
|
"ruffle",
|
|
"ui.js",
|
|
"sw.js",
|
|
],
|
|
overrides: [
|
|
{
|
|
extends: ["plugin:@typescript-eslint/disable-type-checked"],
|
|
files: ["webpack.*.js"],
|
|
rules: {
|
|
"@typescript-eslint/no-var-requires": "off",
|
|
},
|
|
},
|
|
],
|
|
};
|