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

Upgrade to Eslint 9 #3969

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

57 changes: 0 additions & 57 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions __tests__/src/components/WorkspaceElastic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe('WorkspaceElastic', () => {
setWorkspaceViewportPosition: mockDragStop,
});

/** */
container.getBoundingClientRect = () => ({
left: -2500,
offsetHeight: 5000,
Expand Down
1 change: 1 addition & 0 deletions __tests__/src/components/WorkspaceElasticWindow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('WorkspaceElasticWindow', () => {
updateElasticWindowLayout: mockOnResize,
});

/** */
container.getBoundingClientRect = () => ({
left: -2500,
offsetHeight: 5000,
Expand Down
4 changes: 2 additions & 2 deletions __tests__/utils/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ function renderWithProviders(
};
}

export * from '@testing-library/react';
export { renderWithProviders as render };
export * from '@testing-library/react'; // eslint-disable-line import/export
export { renderWithProviders as render }; // eslint-disable-line import/export
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const moduleFormatMap = {
es: false,
};

// eslint-disable-next-line func-names
// eslint-disable-next-line jsdoc/require-jsdoc
module.exports = function (api) {
const isDevelopmentEnv = api.env('development');
const isProductionEnv = api.env('production');
Expand Down
145 changes: 145 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { fixupConfigRules, fixupPluginRules } from "@eslint/compat";
import jest from "eslint-plugin-jest";
import jestDom from "eslint-plugin-jest-dom";
import jsxA11y from 'eslint-plugin-jsx-a11y';
import react from "eslint-plugin-react";
import reactHooks from "eslint-plugin-react-hooks";
import testingLibrary from "eslint-plugin-testing-library";
import jsdoc from 'eslint-plugin-jsdoc';
import babelParser from "@babel/eslint-parser";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
allConfig: js.configs.all,
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
});

export default [{
ignores: ["**/dist/", "**/config/", "**/coverage/", "**/styles/"],
}, ...fixupConfigRules(compat.extends(
"plugin:import/recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:jest-dom/recommended",
"plugin:jsx-a11y/recommended",
"plugin:testing-library/react",
)), {

languageOptions: {
ecmaVersion: 6,
globals: {
...jest.environments.globals.globals,
document: true,
page: true,
},
parser: babelParser,
sourceType: "module",
},
plugins: {
jest,
"jest-dom": fixupPluginRules(jestDom),
jsdoc,
jsxA11y,
react: fixupPluginRules(react),
"react-hooks": fixupPluginRules(reactHooks),
"testing-library": fixupPluginRules(testingLibrary),
},

rules: {
"arrow-parens": "off",
"default-param-last": "off",
eqeqeq: ["warn", "smart"],
"import/no-anonymous-default-export": "off",


"import/no-unresolved": [2, {
ignore: ["test-utils"],
}],

"import/prefer-default-export": "off",

"jsdoc/require-jsdoc": ["error", {
minLineCount: 6,
require: {
ArrowFunctionExpression: true,
ClassDeclaration: true,
FunctionDeclaration: true,
FunctionExpression: true,
MethodDefinition: true,
},
}],

"jsx-a11y/no-autofocus": "warn",

"max-len": ["error", {
code: 120,
ignoreComments: true,
ignoreRegExpLiterals: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
}],
"no-console": "off",

"no-mixed-operators": ["warn", {
allowSamePrecedence: false,
groups: [
["&", "|", "^", "~", "<<", ">>", ">>>"],
["==", "!=", "===", "!==", ">", ">=", "<", "<="],
["&&", "||"],
["in", "instanceof"],
],
}],
"no-param-reassign": ["error", { "props": false }],

"no-restricted-globals": ["error"],
"no-restricted-syntax": ["warn", "WithStatement"],
"no-undef": "off",
"no-underscore-dangle": "off",
"no-unused-expressions": ["error", {
allowShortCircuit: true,
allowTernary: true,
}],
"no-unused-vars": "off",

"no-use-before-define": ["warn", {
classes: false,
functions: false,
variables: false,
}],

"react-hooks/exhaustive-deps": "error",

"react/function-component-definition": "off",

"react/jsx-filename-extension": [1, {
extensions: [".js", ".jsx"],
}],

"react/jsx-props-no-spreading": "off",
"react/jsx-uses-react": "off",
"react/prefer-stateless-function": "off",
"react/react-in-jsx-scope": "off",
"react/require-default-props": "off",
"sort-keys": ["error", "asc", {
caseSensitive: false,
natural: false,
}],

"testing-library/no-render-in-lifecycle": ["error", {
allowTestingFrameworkSetupHook: "beforeEach",
}],
"testing-library/render-result-naming-convention": "off",

},
settings: {
react: {
version: "detect",
},
},
}];
24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,21 @@
"devDependencies": {
"@babel/cli": "^7.22.10",
"@babel/core": "^7.22.10",
"@babel/eslint-parser": "^7.25.9",
"@babel/plugin-transform-regenerator": "^7.22.10",
"@babel/plugin-transform-runtime": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"@babel/preset-react": "^7.22.10",
"@eslint/compat": "^1.2.2",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.13.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.4",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.4.3",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@typescript-eslint/eslint-plugin": "^8.12.0",
"@typescript-eslint/parser": "^8.12.0",
"babel-jest": "^29.3.1",
"babel-loader": "^9.1.0",
"babel-plugin-lodash": "^3.3.4",
Expand All @@ -102,17 +106,15 @@
"canvas": "^2.11.0",
"chalk": "^4.1.0",
"core-js": "^3.21.1",
"eslint": "^8.11.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-react-app": "^7.0.0",
"eslint-plugin-flowtype": "^8.0.3",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^27.1.5",
"eslint": "^9.0.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^28.8.3",
"eslint-plugin-jest-dom": "^5.1.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-jsdoc": "^50.4.3",
"eslint-plugin-jsx-a11y": "^6.10.2",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-testing-library": "^6.2.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-testing-library": "^7.0.0-beta.3",
"glob": "^10.3.0",
"http-server": "^14.1.0",
"jest": "^29.3.1",
Expand Down
2 changes: 1 addition & 1 deletion setupJest.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jest.mock('react-i18next', () => ({
init: jest.fn(),
type: '3rdParty',
},
// this mock makes sure any components using the translate HoC receive the t function as a prop
/** this mock makes sure any components using the translate HoC receive the t function as a prop */
withTranslation: () => (Component) => {
Component.defaultProps = { // eslint-disable-line no-param-reassign
...Component.defaultProps, t: k => k,
Expand Down
2 changes: 1 addition & 1 deletion src/components/GalleryViewThumbnail.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class GalleryViewThumbnail extends Component {
this.handleIntersection = this.handleIntersection.bind(this);
}

// eslint-disable-next-line require-jsdoc
// eslint-disable-next-line jsdoc/require-jsdoc
componentDidMount() {
const { selected } = this.props;
if (selected) {
Expand Down
2 changes: 2 additions & 0 deletions src/components/PluginHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ export const PluginHook = forwardRef((props, ref) => {
))
) : null;
});

PluginHook.displayName = 'PluginHook';
2 changes: 1 addition & 1 deletion src/components/SidebarIndexList.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class SidebarIndexList extends Component {
<MenuList variant="selectedMenu">
{
canvasesIdAndLabel.map((canvas, canvasIndex) => {
const onClick = () => { setCanvas(windowId, canvas.id); }; // eslint-disable-line require-jsdoc, max-len
const onClick = () => { setCanvas(windowId, canvas.id); }; // eslint-disable-line jsdoc/require-jsdoc, max-len

return (
<ScrollTo
Expand Down
1 change: 1 addition & 0 deletions src/containers/WorkspaceAddButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function useWidth() {
);
}

/* eslint react/display-name: "off" */
/**
* withWidth
* @memberof WorkspaceControlPanel
Expand Down
1 change: 1 addition & 0 deletions src/extend/withRef.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export const withRef = () => (Component) => {
const WithRefs = forwardRef((props, ref) => (
<Component innerRef={ref} {...props} />
));
WithRefs.displayName = 'WithRefs';
return WithRefs;
};
2 changes: 1 addition & 1 deletion src/lib/CanvasWorld.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class CanvasWorld {
let canvasHeight = 0;
let canvasWidth = 0;

if (!isNaN(canvas.aspectRatio)) {
if (!Number.isNaN(canvas.aspectRatio)) {
if (dirY === 0) {
// constant height
canvasHeight = scale;
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const baseConfig = mode => ({
},
});

/** */
module.exports = (env, options) => {
const isProduction = options.mode === 'production';
const config = baseConfig(options.mode);
Expand Down
Loading