Files
pezkuwi-dev/packages/dev/config/eslint.js
T
Satoshi Qazi Muhammed f9f04f6adc Move the toolchain to eslint 10, typescript-eslint 8 and current plugins
eslint 8 and typescript-eslint 6 are past their support, and the webpack
dev server chain carried the dependency alerts every repository using this
package inherited. Upstream @polkadot/dev still pins the same versions, so
this leaves it on purpose.

The rules are carried over with their options, so the lint means what it
meant:

- eslint-config-standard 17 (written for eslint 8) is replaced by its 161
  rules in config/eslint.standard.js, with their options. Its 48 formatting
  rules, deprecated in eslint core, are the same rules in @stylistic;
  no-new-object and no-new-symbol are no-object-constructor and
  no-new-native-nonconstructor; import/* is import-x/*.
- eslint-plugin-import (eslint <= 9) is eslint-plugin-import-x;
  eslint-plugin-deprecation is @typescript-eslint/no-deprecated; the
  formatting rules of core, typescript-eslint and eslint-plugin-react used
  in eslint.rules.js are their @stylistic versions with the same options.
- typescript-eslint 8's preset swaps core no-unused-expressions for its own
  with default options; standard's (short circuit, ternary and tagged
  templates allowed) are carried over to it.
- eslint-plugin-react and eslint-plugin-header still call context methods
  eslint 10 removed; @eslint/compat's fixupPluginRules supplies them. The
  header rule also gets `schema: false`, as eslint 9+ rejects options for a
  rule with no schema. The original header plugin stays rather than its
  fork: it reports at the first token after leading comments, so a
  generated file's /* eslint-disable */ still covers it, as it always has.

The effective config was compared rule by rule (--print-config) for .ts,
.tsx, .spec.ts and .mjs files before and after. Every rule that left has
its successor active; option differences are eslint 10 spelling out
defaults. New rules come from the eslint 10, typescript-eslint 8 and
react-hooks 7 presets. no-inner-declarations left eslint's preset upstream.

Also current: webpack-dev-server 6, webpack-cli 7, webpack-merge 6, rollup
plugins, madge 8, gh-release 8, globals 17, espree 11; Node >= 20.19 for
the dev package, which eslint 10 requires.

In this repository the new rules found: Function types now named by
no-unsafe-function-type; optional chains, includes() and RegExp#exec where
they say the same thing; createWrapper returns Describe, so its three casts
were redundant; rootCjs.spec casts through unknown, so the lint result does
not depend on whether build/ exists. lint, build and test (149 passed) pass,
and lint leaves the tree unchanged with and without a build.
2026-10-09 08:56:18 +04:00

187 lines
5.0 KiB
JavaScript

// Copyright 2017-2026 @pezkuwi/dev authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { fixupPluginRules } from '@eslint/compat';
import eslintJs from '@eslint/js';
import stylisticPlugin from '@stylistic/eslint-plugin';
import tsPlugin from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
// @ts-expect-error No definition for this one
import headerPlugin from 'eslint-plugin-header';
// @ts-expect-error No definition for this one
import importNewlinesPlugin from 'eslint-plugin-import-newlines';
import importPlugin from 'eslint-plugin-import-x';
import jestPlugin from 'eslint-plugin-jest';
import nPlugin from 'eslint-plugin-n';
// @ts-expect-error No definition for this one
import promisePlugin from 'eslint-plugin-promise';
import reactPlugin from 'eslint-plugin-react';
import reactHooksPlugin from 'eslint-plugin-react-hooks';
import simpleImportSortPlugin from 'eslint-plugin-simple-import-sort';
// @ts-expect-error No definition for this one
import sortDestructureKeysPlugin from 'eslint-plugin-sort-destructure-keys';
import globals from 'globals';
import { overrideAll, overrideJs, overrideJsx, overrideSpec } from './eslint.rules.js';
import { standardRules } from './eslint.standard.js';
/**
* eslint-plugin-header declares no options schema, and eslint 9+ rejects
* options for a rule without one. `schema: false` is how a rule says it
* validates its own options; the rule itself is unchanged.
*/
const headerPluginFixed = {
...headerPlugin,
rules: {
header: {
...headerPlugin.rules.header,
meta: { ...headerPlugin.rules.header.meta, schema: false }
}
}
};
const EXT_JS = ['.cjs', '.js', '.mjs'];
const EXT_TS = ['.ts', '.tsx'];
const EXT_ALL = [...EXT_JS, ...EXT_TS];
/**
* @internal
* Converts a list of EXT_* defined above to globs
* @param {string[]} exts
* @returns {string[]}
*/
function extsToGlobs (exts) {
return exts.map((e) => `**/*${e}`);
}
export default [
{
ignores: [
'**/.github/',
'**/.vscode/',
'**/.yarn/',
'**/build/',
'**/build-*/',
'**/coverage/',
'**/cjs/**',
// Build output files (generated from src/)
'packages/*/*.d.ts',
'packages/*/*.js',
'packages/*/*.mjs',
'packages/*/*.cjs',
'packages/*/rootJs/**',
'packages/*/rootTests.*',
'packages/*/browser.*',
'packages/*/node.*',
'packages/*/types.*',
'packages/*/env/**'
]
},
{
languageOptions: {
globals: {
...globals.browser,
...globals.node
},
parser: tsParser,
parserOptions: {
ecmaVersion: 'latest',
project: './tsconfig.eslint.json',
sourceType: 'module',
warnOnUnsupportedTypeScriptVersion: false
}
},
plugins: {
'@stylistic': stylisticPlugin,
'@typescript-eslint': tsPlugin,
// eslint-plugin-header reports at the first token after the leading
// comments, so a generated file's /* eslint-disable */ covers it; the
// maintained fork reports at line 1 instead. The compat layer supplies the
// context methods eslint 10 removed; headerPluginFixed, the options schema.
header: fixupPluginRules(headerPluginFixed),
'import-newlines': importNewlinesPlugin,
'import-x': importPlugin,
n: nPlugin,
promise: promisePlugin,
'simple-import-sort': simpleImportSortPlugin,
'sort-destructure-keys': sortDestructureKeysPlugin
},
settings: {
'import-x/extensions': EXT_ALL,
'import-x/parsers': {
'@typescript-eslint/parser': EXT_TS,
espree: EXT_JS
},
'import-x/resolver': {
node: {
extensions: EXT_ALL
},
typescript: {
project: './tsconfig.eslint.json'
}
}
}
},
{
files: extsToGlobs(EXT_ALL),
rules: {
...eslintJs.configs.recommended.rules,
...standardRules,
...tsPlugin.configs['recommended-type-checked'].rules,
...tsPlugin.configs['stylistic-type-checked'].rules,
...overrideAll
}
},
{
files: extsToGlobs(EXT_JS),
rules: {
...overrideJs
}
},
{
files: [
'**/*.tsx',
'**/use*.ts'
],
plugins: {
// eslint-plugin-react still calls context methods eslint 10 removed
// (getFilename and others); the compat layer provides them.
react: fixupPluginRules(reactPlugin),
'react-hooks': reactHooksPlugin
},
rules: {
...reactPlugin.configs.recommended.rules,
...reactHooksPlugin.configs.recommended.rules,
...overrideJsx
},
settings: {
react: {
version: 'detect'
}
}
},
{
files: [
'**/*.spec.ts',
'**/*.spec.tsx'
],
languageOptions: {
globals: {
...globals.jest
}
},
plugins: {
jest: jestPlugin
},
rules: {
...jestPlugin.configs.recommended.rules,
...overrideSpec
},
settings: {
jest: {
version: 27
}
}
}
];