diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index dfa65e1..0000000 --- a/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -dist -_*.js -*.ts diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 94b62f9..0000000 --- a/.eslintrc +++ /dev/null @@ -1,50 +0,0 @@ -{ - "parser": "@babel/eslint-parser", - "parserOptions": { - "ecmaVersion": 6, - "ecmaFeatures": { - "jsx": true - } - }, - "extends": [ - "eslint:recommended", - "plugin:react/recommended" - ], - "plugins": [ - "react" - ], - "globals": { - "flushConsoleOutput": true, - "jest": true - }, - "settings": { - "react": { - "version": "18" - } - }, - "env": { - "es6": true, - "node": true, - "browser": true - }, - "rules": { - "semi": ["error", "always"], - "curly": "error", - "no-var": "error", - "quotes": ["error", "single"], - "no-console": "error", - "no-debugger": "warn", - "no-unused-vars": ["error", {"ignoreRestSiblings": true}], - "eol-last": "error", - "object-curly-spacing": ["error", "always"], - "react/prop-types": "off", - "react/display-name": "off", - "space-before-function-paren": ["error", "never"], - "space-before-blocks": ["error", "always"], - "space-in-parens": ["error", "never"], - "comma-dangle": ["error", "only-multiline"], - "func-call-spacing": ["error", "never"], - "no-multi-spaces": "error", - "indent": ["error", 2] - } -} diff --git a/.vscode/settings.json b/.vscode/settings.json index d2b3277..9df8f92 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,6 +10,7 @@ "eslint.alwaysShowStatus": true, "eslint.format.enable": true, "eslint.codeActionsOnSave.mode": "problems", + "editor.formatOnSave": true, "flow.enabled": false, @@ -19,6 +20,7 @@ "jestrunner.debugOptions": {"args": ["--watch"]}, "jestrunner.configPath": "jest.config.js", + "cSpell.words": [ "astring", "lcov", diff --git a/demo/src/hooks/useContext.js b/demo/src/hooks/useContext.js index e006a4d..f9352da 100644 --- a/demo/src/hooks/useContext.js +++ b/demo/src/hooks/useContext.js @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ import React from 'react'; import createStepLogger from '../createStepLogger'; diff --git a/demo/src/ssr/index.js b/demo/src/ssr/index.js index f57cb94..51b6844 100644 --- a/demo/src/ssr/index.js +++ b/demo/src/ssr/index.js @@ -7,7 +7,7 @@ import DemoComponent from './DemoComponent'; export default { description: 'Server Side (hydrate)', - fn({ reactDomRoot, whyDidYouRender }) { + fn({ reactDomRoot, domElement, whyDidYouRender }) { const stepLogger = createStepLogger(); fetch('/ssrComponent') diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..413f060 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,65 @@ +const reactPlugin = require('eslint-plugin-react'); +const js = require('@eslint/js'); +const globals = require('globals'); +const { includeIgnoreFile } = require('@eslint/compat'); +const pluginCypress = require('eslint-plugin-cypress/flat'); + +// TODO: remove once all deps are using the latest version +globals.browser['AudioWorkletGlobalScope'] = globals.browser['AudioWorkletGlobalScope ']; +delete globals.browser['AudioWorkletGlobalScope ']; + + +module.exports = [ + includeIgnoreFile(__dirname +'/.gitignore'), + js.configs.recommended, + pluginCypress.configs.globals, + { + plugins: { + cypress: pluginCypress + }, + rules: { + 'cypress/unsafe-to-chain-command': 'error' + }, + }, + { + ...reactPlugin.configs.flat.recommended, + languageOptions: { + ...reactPlugin.configs.flat.recommended.languageOptions, + globals: { + ...globals.browser, + ...globals.jest, + ...globals.node, + ...globals.console, + flushConsoleOutput: 'readable', + }, + }, + rules: { + 'semi': ['error', 'always'], + 'curly': 'error', + 'no-var': 'error', + 'quotes': ['error', 'single'], + 'no-console': 'error', + 'no-debugger': 'warn', + 'react/jsx-uses-vars': 'error', + 'react/jsx-uses-react': 'error', + 'no-unused-vars': ['error', { + 'ignoreRestSiblings': true, + 'varsIgnorePattern': '^_', + 'argsIgnorePattern': '^_', + 'caughtErrorsIgnorePattern': '^_', + 'destructuredArrayIgnorePattern': '^_' + }], + 'eol-last': 'error', + 'object-curly-spacing': ['error', 'always'], + 'react/prop-types': 'off', + 'react/display-name': 'off', + 'space-before-function-paren': ['error', 'never'], + 'space-before-blocks': ['error', 'always'], + 'space-in-parens': ['error', 'never'], + 'comma-dangle': ['error', 'only-multiline'], + 'func-call-spacing': ['error', 'never'], + 'no-multi-spaces': 'error', + 'indent': ['error', 2] + } + } +]; diff --git a/jest.polyfills.js b/jest.polyfills.js index b9f8b7d..d1d453f 100644 --- a/jest.polyfills.js +++ b/jest.polyfills.js @@ -10,14 +10,14 @@ */ const { TextDecoder, TextEncoder } = require('node:util'); -// eslint-disable-next-line no-undef + Object.defineProperties(globalThis, { TextDecoder: { value: TextDecoder }, TextEncoder: { value: TextEncoder }, }); const { Blob, File } = require('node:buffer'); -// eslint-disable-next-line no-undef + Object.defineProperties(globalThis, { Blob: { value: Blob }, File: { value: File }, diff --git a/package.json b/package.json index aa95cf4..e4b7bb7 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "build": "cross-env NODE_ENV=production rollup --config --bundleConfigAsCjs", "test": "jest --config=jest.config.js", "test:ci": "yarn test --coverage", - "lint": "eslint . --ext=js --max-warnings 0 --cache --cache-location .cache/eslint-cache", + "lint": "eslint . --max-warnings 0 --cache --cache-location .cache/eslint-cache", "clear": "rimraf .cache dist demo/dist", "watch": "concurrently --names \"Serve,Test\" \"npm:start\" \"npm:test:watch\"", "checkHealth": "yarn lint && yarn test", @@ -82,6 +82,7 @@ "@babel/plugin-transform-class-properties": "^7.25.9", "@babel/preset-env": "^7.26.0", "@babel/preset-react": "^7.26.3", + "@eslint/compat": "^1.2.4", "@rollup/plugin-alias": "^5.1.1", "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-commonjs": "^28.0.2", diff --git a/src/patches/patchClassComponent.js b/src/patches/patchClassComponent.js index 7042900..3c66ffb 100644 --- a/src/patches/patchClassComponent.js +++ b/src/patches/patchClassComponent.js @@ -4,7 +4,6 @@ import wdyrStore from '../wdyrStore'; import { checkIfInsideAStrictModeTree } from '../utils'; import getUpdateInfo from '../getUpdateInfo'; -import { getCurrentOwner } from '../helpers'; export default function patchClassComponent(ClassComponent, { displayName, defaultProps }) { class WDYRPatchedClassComponent extends ClassComponent { @@ -61,7 +60,7 @@ export default function patchClassComponent(ClassComponent, { displayName, defau try { WDYRPatchedClassComponent.displayName = displayName; - } catch (e) { + } catch (_e) { // not crucial if displayName couldn't be set } diff --git a/src/patches/patchForwardRefComponent.js b/src/patches/patchForwardRefComponent.js index 368f586..802dc2d 100644 --- a/src/patches/patchForwardRefComponent.js +++ b/src/patches/patchForwardRefComponent.js @@ -29,7 +29,7 @@ export default function patchForwardRefComponent(ForwardRefComponent, { displayN try { WDYRForwardRefFunctionalComponent.displayName = displayName; - } catch (e) { + } catch (_e) { // not crucial if displayName couldn't be set } diff --git a/src/patches/patchFunctionalOrStrComponent.js b/src/patches/patchFunctionalOrStrComponent.js index 9bc734c..633bea0 100644 --- a/src/patches/patchFunctionalOrStrComponent.js +++ b/src/patches/patchFunctionalOrStrComponent.js @@ -49,7 +49,7 @@ export default function patchFunctionalOrStrComponent(FunctionalOrStringComponen try { WDYRFunctionalComponent.displayName = displayName; - } catch (e) { + } catch (_e) { // not crucial if displayName couldn't be set } diff --git a/src/patches/patchMemoComponent.js b/src/patches/patchMemoComponent.js index 131ec7b..e4134f5 100644 --- a/src/patches/patchMemoComponent.js +++ b/src/patches/patchMemoComponent.js @@ -27,7 +27,7 @@ export default function patchMemoComponent(MemoComponent, { displayName, default try { PatchedInnerComponent.displayName = getDisplayName(WrappedFunctionalComponent); - } catch (e) { + } catch (_e) { // not crucial if displayName couldn't be set } @@ -41,7 +41,7 @@ export default function patchMemoComponent(MemoComponent, { displayName, default try { WDYRMemoizedFunctionalComponent.displayName = displayName; - } catch (e) { + } catch (_e) { // not crucial if displayName couldn't be set } diff --git a/tests/librariesTests/styled-components.test.js b/tests/librariesTests/styled-components.test.js index fe66f4e..29c217c 100644 --- a/tests/librariesTests/styled-components.test.js +++ b/tests/librariesTests/styled-components.test.js @@ -1,4 +1,4 @@ -/* eslint-disable no-console */ + import React from 'react'; import styled from 'styled-components/dist/styled-components.js'; import * as rtl from '@testing-library/react'; diff --git a/yarn.lock b/yarn.lock index 00a06b3..f0bda89 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1041,6 +1041,11 @@ resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.12.1.tgz#cfc6cffe39df390a3841cde2abccf92eaa7ae0e0" integrity sha512-CCZCDJuduB9OUkFkY2IgppNZMi2lBQgD2qzwXkEia16cge2pijY/aXi96CJMquDMn3nJdlPV1A5KrJEXwfLNzQ== +"@eslint/compat@^1.2.4": + version "1.2.4" + resolved "https://registry.yarnpkg.com/@eslint/compat/-/compat-1.2.4.tgz#b69b0d76ce73fe66d7f8633c406acea151f5c559" + integrity sha512-S8ZdQj/N69YAtuqFt7653jwcvuUj131+6qGLUyDqfDg1OIoBQ66OCuXC473YQfO2AaxITTutiRQiDwoo7ZLYyg== + "@eslint/config-array@^0.19.0": version "0.19.1" resolved "https://registry.yarnpkg.com/@eslint/config-array/-/config-array-0.19.1.tgz#734aaea2c40be22bbb1f2a9dac687c57a6a4c984"