diff --git a/eslint.js.react.jest.config.base.mjs b/eslint.js.react.jest.config.base.mjs new file mode 100644 index 00000000..47997596 --- /dev/null +++ b/eslint.js.react.jest.config.base.mjs @@ -0,0 +1,43 @@ +import eslint from '@eslint/js'; +import react from 'eslint-plugin-react'; +import { fixupPluginRules } from '@eslint/compat'; +import eslintPluginReactHooks from 'eslint-plugin-react-hooks'; +import jest from 'eslint-plugin-jest'; +import eslintConfigPrettier from 'eslint-config-prettier'; + +export default [ + { + files: ['test/**/*.js', 'test/**/*.jsx'], + ...eslint.configs.recommended, + }, + { + files: ['test/**/*.js', 'test/**/*.jsx'], + ...react.configs.flat.recommended, + }, + { + files: ['test/**/*.js', 'test/**/*.jsx'], + settings: { + react: { + version: 'detect', + }, + }, + }, + { + files: ['test/**/*.js', 'test/**/*.jsx'], + plugins: { + 'react-hooks': fixupPluginRules(eslintPluginReactHooks), + }, + }, + { + files: ['test/**/*.js', 'test/**/*.jsx'], + ...jest.configs['flat/recommended'], + }, + { + files: ['test/**/*.js', 'test/**/*.jsx'], + ...jest.configs['jest/style'], + }, + { + files: ['test/**/*.js', 'test/**/*.jsx'], + ...eslintConfigPrettier, + }, +]; diff --git a/extension/.eslintignore b/extension/.eslintignore deleted file mode 100644 index d8c3bcd8..00000000 --- a/extension/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules -dist -examples diff --git a/extension/.eslintrc b/extension/.eslintrc deleted file mode 100644 index 69fd0840..00000000 --- a/extension/.eslintrc +++ /dev/null @@ -1,31 +0,0 @@ -{ - "root": true, - "extends": "eslint-config-airbnb", - "globals": { - "chrome": true, - "__DEVELOPMENT__": true - }, - "env": { - "browser": true, - "node": true - }, - "rules": { - "react/jsx-uses-react": 2, - "react/jsx-uses-vars": 2, - "react/react-in-jsx-scope": 2, - "react/jsx-quotes": 0, - "block-scoped-var": 0, - "padded-blocks": 0, - "quotes": [1, "single"], - "comma-style": [2, "last"], - "no-use-before-define": [0, "nofunc"], - "func-names": 0, - "prefer-const": 0, - "comma-dangle": 0, - "id-length": 0, - "indent": [2, 2, { "SwitchCase": 1 }], - "new-cap": [2, { "capIsNewExceptions": ["Test"] }], - "default-case": 0 - }, - "plugins": ["react"] -} diff --git a/extension/eslint.config.mjs b/extension/eslint.config.mjs new file mode 100644 index 00000000..18e89a79 --- /dev/null +++ b/extension/eslint.config.mjs @@ -0,0 +1,38 @@ +import globals from 'globals'; +import eslintJs from '../eslint.js.config.base.mjs'; +import eslintTsReact from '../eslint.ts.react.config.base.mjs'; +import eslintJsReactJest from '../eslint.js.react.jest.config.base.mjs'; + +export default [ + ...eslintJs, + ...eslintTsReact(import.meta.dirname), + ...eslintJsReactJest, + { + ignores: [ + 'chrome', + 'dist', + 'edge', + 'examples', + 'firefox', + 'test/electron/fixture/dist', + ], + }, + { + files: ['build.mjs'], + languageOptions: { + globals: { + ...globals.nodeBuiltin, + }, + }, + }, + { + files: ['test/**/*.js', 'test/**/*.jsx'], + languageOptions: { + globals: { + ...globals.browser, + ...globals.node, + EUI: true, + }, + }, + }, +]; diff --git a/extension/jest.config.js b/extension/jest.config.cjs similarity index 87% rename from extension/jest.config.js rename to extension/jest.config.cjs index 2c331668..64f413ba 100644 --- a/extension/jest.config.js +++ b/extension/jest.config.cjs @@ -3,7 +3,7 @@ module.exports = { testPathIgnorePatterns: ['/examples'], testEnvironment: 'jsdom', moduleNameMapper: { - '\\.css$': '/test/__mocks__/styleMock.ts', + '\\.css$': '/test/__mocks__/styleMock.js', }, transformIgnorePatterns: [ 'node_modules/(?!.pnpm|@babel/code-frame|@babel/highlight|@babel/helper-validator-identifier|chalk|d3|dateformat|delaunator|internmap|jsondiffpatch|lodash-es|nanoid|robust-predicates|uuid)', diff --git a/extension/package.json b/extension/package.json index e4d87385..42ca9ad3 100644 --- a/extension/package.json +++ b/extension/package.json @@ -17,9 +17,10 @@ "clean": "rimraf dist && rimraf chrome/dist && rimraf edge/dist && rimraf firefox/dist", "test:app": "cross-env BABEL_ENV=test jest test/app", "test:chrome": "jest test/chrome", + "build:test:electron:fixture": "webpack --config test/electron/fixture/webpack.config.js", "test:electron": "pnpm run build:test:electron:fixture && jest test/electron", "test": "pnpm run test:app && pnpm run test:chrome && pnpm run test:electron", - "build:test:electron:fixture": "webpack --config test/electron/fixture/webpack.config.js", + "lint": "eslint .", "type-check": "tsc --noEmit" }, "dependencies": { @@ -64,12 +65,7 @@ "cross-env": "^7.0.3", "electron": "^31.6.0", "esbuild": "^0.23.1", - "eslint": "^8.57.1", - "eslint-config-airbnb": "^19.0.4", - "eslint-plugin-import": "^2.30.0", - "eslint-plugin-jsx-a11y": "^6.10.0", - "eslint-plugin-react": "^7.36.1", - "eslint-plugin-react-hooks": "^4.6.2", + "globals": "^15.9.0", "immutable": "^4.3.7", "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", diff --git a/extension/src/app/Actions.tsx b/extension/src/app/Actions.tsx index 656bb6d6..4261ee62 100644 --- a/extension/src/app/Actions.tsx +++ b/extension/src/app/Actions.tsx @@ -31,19 +31,19 @@ type Props = StateProps & DispatchProps & OwnProps; const isElectron = navigator.userAgent.includes('Electron'); -function sendMessage(message: SingleMessage) { - chrome.runtime.sendMessage(message); +async function sendMessage(message: SingleMessage) { + await chrome.runtime.sendMessage(message); } class Actions extends Component { - openWindow = (position: Position) => { - sendMessage({ type: 'OPEN', position }); + openWindow = async (position: Position) => { + await sendMessage({ type: 'OPEN', position }); }; - openOptionsPage = () => { - if (navigator.userAgent.indexOf('Firefox') !== -1) { - sendMessage({ type: 'OPEN_OPTIONS' }); + openOptionsPage = async () => { + if (navigator.userAgent.includes('Firefox')) { + await sendMessage({ type: 'OPEN_OPTIONS' }); } else { - chrome.runtime.openOptionsPage(); + await chrome.runtime.openOptionsPage(); } }; @@ -85,7 +85,7 @@ class Actions extends Component { {features.import && } {position && (position !== '#popup' || - navigator.userAgent.indexOf('Firefox') !== -1) && } + navigator.userAgent.includes('Firefox')) && } @@ -96,8 +96,8 @@ class Actions extends Component { {!isElectron && (