Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to ESLint 9 and ESLint flat config #1617

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .eslintignore

This file was deleted.

51 changes: 0 additions & 51 deletions .eslintrc

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ dist/
node_modules/
coverage/

.eslintcache

# The client uses yarn rather than npm to manage the lockfile.
package-lock.json

Expand Down
94 changes: 94 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import hypothesis from 'eslint-config-hypothesis';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{
ignores: [
'.yalc/**/*',
'.yarn/**/*',
'build/**/*',
'dist/**/*',
'**/vendor/**/*.js',
'**/coverage/**/*',
'docs/_build/*',
// TODO - Lint these files
'rollup*.config.js',
Comment on lines +15 to +16
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept these ignored as it was before. We can change this later.

],
},
...hypothesis,
...tseslint.configs.recommended,
{
rules: {
'prefer-arrow-callback': ['error', { allowNamedFunctions: true }],
'object-shorthand': ['error', 'properties'],

// Upgrade TS rules from warning to error.
'@typescript-eslint/no-unused-vars': 'error',

// Disable TS rules that we dislike.
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-this-alias': 'off',

// Enforce consistency in cases where TypeScript supports old and new
// syntaxes for the same thing.
//
// - Require `<var> as <type>` for casts
// - Require `import type` for type imports. The corresponding rule for
// exports is not enabled yet because that requires setting up type-aware
// linting.
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
},
languageOptions: {
globals: {
chrome: false,
},
},
},

// Entry points which get loaded as non-module scripts.
{
files: ['src/unload-client.js'],
rules: {
strict: ['error', 'global'],
},
languageOptions: {
parserOptions: {
sourceType: 'script',
},
},
},

// CommonJS scripts which run in Node
{
files: ['tests/karma.config.cjs'],
rules: {
strict: ['error', 'global'],
},
languageOptions: {
parserOptions: {
sourceType: 'script',
},
globals: {
...globals.node,
},
},
},

// ESM scripts which run in Node
{
files: ['tools/*.js'],
rules: {
'no-console': 'off',
},
languageOptions: {
globals: {
...globals.node,
},
},
},
);
2 changes: 0 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-console */
/* eslint-env node */
// @ts-nocheck

import { spawn } from 'node:child_process';
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@
"@rollup/plugin-multi-entry": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.3.0",
"@types/chrome": "^0.0.277",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"babel-plugin-istanbul": "^7.0.0",
"babel-plugin-mockable-imports": "^2.0.1",
"chai": "^5.1.1",
"chrome-webstore-upload-cli": "^3.3.1",
"diff": "^7.0.0",
"eslint": "^8.57.0",
"eslint-config-hypothesis": "^2.6.0",
"eslint-plugin-mocha": "^10.4.1",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint": "^9.12.0",
"eslint-config-hypothesis": "^3.0.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-react": "^7.37.1",
"eslint-plugin-react-hooks": "^5.0.0",
Comment on lines +30 to +31
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project does not really need these two plugins, but they are eslint-config-hypothesis peer dependencies.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add separate entry points in future for Preact and non-Preact using libs/apps.

"git-describe": "^4.1.1",
"globals": "^15.11.0",
"gulp": "^5.0.0",
"hypothesis": "^1.1527.0",
"is-equal-shallow": "^0.1.3",
Expand All @@ -47,10 +46,12 @@
"rollup": "^4.24.0",
"sinon": "^19.0.2",
"typescript": "^5.6.3",
"typescript-eslint": "^8.9.0",
"web-ext": "^7.12.0"
},
"browserslist": "chrome 85, firefox 75",
"scripts": {
"lint": "eslint --cache .",
"test": "rollup -c rollup-tests.config.js && karma start tests/karma.config.cjs --single-run",
"typecheck": "tsc --build src/tsconfig.json"
},
Expand Down
5 changes: 0 additions & 5 deletions src/background/.eslintrc

This file was deleted.

5 changes: 0 additions & 5 deletions tests/background/.eslintrc

This file was deleted.

3 changes: 1 addition & 2 deletions tests/karma.config.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-require-imports */
'use strict';

/* global __dirname */

const path = require('path');

module.exports = function (config) {
Expand Down
9 changes: 0 additions & 9 deletions tools/.eslintrc

This file was deleted.

Loading