Skip to content

Commit

Permalink
Update to ESLint 9.20.1
Browse files Browse the repository at this point in the history
Update to ESLint 9 since
ESLint 8 reached end-of-life
on 2024-10-05 and is no longer
maintained.

The main part of this PR is
the new flat configuration
file, which is quite close to
a 1:1 migration of the previous
non-flat config. The majority
of lines is the rules section,
which is the same as before
except for the now deprecated
rules that I removed.
  • Loading branch information
pjonsson committed Feb 19, 2025
1 parent 0aea1b6 commit e09f146
Show file tree
Hide file tree
Showing 26 changed files with 421 additions and 314 deletions.
145 changes: 0 additions & 145 deletions .eslintrc.js

This file was deleted.

11 changes: 0 additions & 11 deletions buildprocess/.eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions doc/contributing/development-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Run any of these tasks with `yarn gulp <task name>` from within the TerriaJS dir
- `build` - Builds a non-minified version of the TerriaJS tests. This task may take 10 seconds or more, which is the main reason for the next task.
- `watch` - Starts the same as `build` but then it stays running and watches for changes to any TerriaJS or Cesium source file that was pulled in to the build. When a change to any of these files is detected, a fast incremental build is automatically kicked off. The incremental build is much faster than the full rebuild because dependencies between source files are cached.
- `release` - The same as `build` except that it also minifies the build tests.
- `lint` - Runs ESLint on the files in the `lib` folder and reports any problems. The ESLint rules are defined in the `.eslintrc.js` file in the root directory of TerriaJS.
- `lint` - Runs ESLint on the files in the `lib` folder and reports any problems. The ESLint rules are defined in the `eslint.config.mjs` file in the root directory of TerriaJS.
- `docs` - Generates the user guide and reference documentation. The user guide is served at `http://localhost:3002/doc/guide/` and the reference documentation is at `http://localhost:3002/doc/reference/`.
- `make-schema` - Generates [JSON Schema](http://json-schema.org/) for the TerriaJS [Initialization Files](../customizing/initialization-files.md) from the source code. The schema is written to `wwwroot/schema`.
- `test` - Detects browsers available on the local system and launches the test suite in each. The results are reported on the command line.
Expand All @@ -160,7 +160,7 @@ Run any of these tasks with `yarn gulp <task name>` from within the TerriaMap di
- `build` - Builds a non-minified version of TerriaMap, TerriaJS, Cesium, and all other dependencies, together in one JS file (called `wwwroot/build/TerriaMap.js`). Only the parts of TerriaJS and Cesium that we use (directly or indirectly) are pulled in. Web Workers, CSS, and other resources are also built by this task. This task may take 10 seconds or more, which is the main reason for the next task.
- `watch` - Starts the same as `build` but then it stays running and watches for changes to any TerriaMap, TerriaJS, or Cesium resource. When a change to any of these files is detected, a fast incremental build is automatically kicked off. The incremental build is much faster than the full rebuild because dependencies between source files are cached.
- `release` - The same as `build` except that it also minifies the built JavaScript files. This task should be used when building for production.
- `lint` - Runs ESLint on `index.js` and the files in the `lib` folder and reports any problems. The ESLint rules are defined in the `.eslintrc` file in the root directory of TerriaMap.
- `lint` - Runs ESLint on `index.js` and the files in the `lib` folder and reports any problems. The ESLint rules are defined in the `eslint.config.mjs` file in the root directory of TerriaMap.
- `make-package` - Creates a `.tar.gz` package in `deploy/packages` from the current build. This package can be copied to another machine to run the application there. The arguments are:

| Argument | Description |
Expand Down
222 changes: 222 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
// @ts-check

"use strict";

import globals from "globals";
import { fixupPluginRules } from "@eslint/compat";
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginReact from "eslint-plugin-react";
import pluginReactHooks from "eslint-plugin-react-hooks";
import eslintConfigPrettier from "eslint-config-prettier";

/** @type {import('eslint').Linter.Config[]} */
export default tseslint.config(
eslint.configs.recommended,
// https://github.com/typescript-eslint/typescript-eslint/blob/v8.18.1/packages/eslint-plugin/src/configs/recommended.ts
...tseslint.configs.recommended,
{
name: "Globals for buildprocess/",
// !!! WARNING !!!: do NOT put a space after "," inside {} in globs. Doing
// so will make ESLint produce errors for disabled rules
// because it has "forgotten" half of its config.
files: ["buildprocess/**/*.{js,ts,jsx,tsx}"],
languageOptions: {
globals: {
...globals.node
}
}
},
{
name: "Globals for ./ and lib/",
files: ["{,lib/**/}*.{js,ts,jsx,tsx}"],
languageOptions: {
globals: {
...globals.browser,
...globals.commonjs,
process: true
}
}
},
{
name: "Globals for test/",
files: ["test/**/*.{ts,tsx}"],
languageOptions: {
globals: {
...globals.jasmine
}
}
},
{
name: "Shared config for everything/",
files: ["{buildprocess,lib}/**/*.{js,ts,jsx,tsx}", "test/**/*.{ts,tsx}"],
extends: [
pluginReact.configs.flat.recommended
// TODO: Enable next line when upgrading to React 17+.
// pluginReact.configs.flat['jsx-runtime'],
],
plugins: {
"react-hooks": fixupPluginRules(pluginReactHooks)
},
languageOptions: {
// The React plugin's recommended config does not contain language options.
...pluginReact.configs.flat.recommended.languageOptions,
ecmaVersion: 2019,
sourceType: "script",

parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
ecmaFeatures: {
legacyDecorators: true
}
}
},
settings: {
react: {
version: "detect"
}
},
rules: {
// TODO: re-enable the disabled @typescript-eslint rules.
"@typescript-eslint/no-explicit-any": ["off", { ignoreRestArgs: true }],
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-this-alias": "off",

"@typescript-eslint/no-empty-object-type": [
"error",
{
allowInterfaces: "with-single-extends"
}
],
// The no-useless-constructor needs to be disabled for
// the @typescript-eslint-rule.
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/unified-signatures": "error",
"@typescript-eslint/consistent-type-assertions": "error",
"react-hooks/exhaustive-deps": "error",

"react/jsx-boolean-value": [
"error",
"never",
{
always: []
}
],

"react/no-arrow-function-lifecycle": "error",
"react/no-invalid-html-attribute": "error",
"react/jsx-no-useless-fragment": "error",
"react/jsx-no-constructed-context-values": "error",
"react/jsx-fragments": ["error", "syntax"],

"react/jsx-no-duplicate-props": [
"error",
{
ignoreCase: true
}
],

"react/jsx-pascal-case": [
"error",
{
allowAllCaps: true,
ignore: []
}
],

"react/no-danger": "warn",
"react/no-did-update-set-state": "error",
"react/no-will-update-set-state": "error",
"react/prop-types": "error",
"react/self-closing-comp": "error",

"react/jsx-no-undef": [
"error",
{
allowGlobals: true
}
],

// Possible Errors.
"no-console": "off",
"no-inner-declarations": [1, "functions"],
// Best Practices.
eqeqeq: ["error"],
"no-alert": ["error"],
"no-caller": ["error"],
"no-div-regex": ["error"],
"no-empty": ["error", { allowEmptyCatch: true }],
"no-eval": ["error"],
"no-extend-native": ["error"],
"no-fallthrough": 0,
"no-implied-eval": ["error"],
"no-iterator": ["error"],
"no-labels": ["error"],
"no-lone-blocks": ["error"],
"no-loop-func": ["error"],
"no-new-func": ["error"],
"no-new-wrappers": ["error"],
"no-new": ["error"],
"no-octal-escape": ["error"],
"no-proto": ["error"],
"no-return-assign": ["error"],
"no-script-url": ["error"],
"no-sequences": ["error"],
radix: "error",

// Strict Mode.
strict: [0, "global"],

// Variables.
"no-label-var": 1,
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "all",
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrors: "all",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
ignoreRestSiblings: true
}
],
camelcase: [
0,
{
properties: "always"
}
],

"no-array-constructor": "error",
"no-unneeded-ternary": 1,
// See:
// https://stackoverflow.com/questions/64646248/eslintrc-js-for-react-17-and-jsx-without-import-react/64646593#64646593
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off",
"react/no-unknown-property": [
"error",
{
ignore: ["css"]
}
]
}
},
{
name: "Disable type checked rules for JavaScript",
files: ["{buildprocess,lib}/**/*.{js,jsx}"],
extends: [tseslint.configs.disableTypeChecked]
},
{
name: "Globally ignored files",
ignores: [
"{dist,ts-out,lib/ThirdParty}/**",
"wwwroot/{build,third_party}/**",
"**/*.scss.d.ts",
"test/**/*.{js,jsx}"
]
},
eslintConfigPrettier
);
Loading

0 comments on commit e09f146

Please sign in to comment.