diff --git a/.eslintrc b/.eslintrc index c16f1ca1fb..b08aae00ed 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,10 +1,7 @@ { "root": true, "parser": "@typescript-eslint/parser", - "plugins": [ - "@typescript-eslint", - "security" - ], + "plugins": ["@typescript-eslint", "security"], "env": { "browser": true }, @@ -13,6 +10,9 @@ "webpack": { "config": "./browsers/webpack.config.js" } + }, + "react": { + "version": "detect" } }, "extends": [ @@ -21,28 +21,51 @@ "plugin:@typescript-eslint/recommended", "plugin:react/recommended", "plugin:react-hooks/recommended", - "plugin:import/errors", - "plugin:import/warnings", "plugin:import/typescript", "plugin:security/recommended" + + // TODO: Restore these after https://github.com/benmosher/eslint-plugin-import/issues/1931 + // "plugin:import/errors", + // "plugin:import/warnings", ], "rules": { + "@typescript-eslint/no-empty-function": "off", "react/prop-types": "off", "@typescript-eslint/ban-types": ["warn"], "@typescript-eslint/no-explicit-any": ["warn"], - "@typescript-eslint/ban-ts-comment": ["error", { - "ts-ignore": "allow-with-description", - "minimumDescriptionLength": 3 - }] + "@typescript-eslint/ban-ts-comment": [ + "error", + { + "ts-ignore": "allow-with-description", + "minimumDescriptionLength": 3 + } + ] }, "ignorePatterns": [ - "browsers/chrome/webpack/**", - "browsers/firefox/webpack/**", - "browsers/webpack.config.js", - "scripts/webpack.scripts.js", - "src/vendors/libraryDetector/**", - "src/**/*.test.ts", - "src/**/*.test.js", + "node_modules", + ".idea", + "browsers/dist", + "artifacts", + "scripts/bin", + "src/vendors", "src/support.js" + ], + "overrides": [ + { + "files": [ + "webpack.*.js", + "*.config.js", + "test-env.js", + "**/__mocks__/**", + "*.test.js" + ], + "env": { + "node": true, + "jest": true + }, + "rules": { + "@typescript-eslint/no-var-requires": "off" + } + } ] } diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index ffb1267f51..976a506646 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -63,3 +63,20 @@ jobs: name: brick-headers path: headers.json retention-days: 5 + + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: "14.x" + - uses: bahmutov/npm-install@v1 + # Run eslint without GitHub Actions annotations + # https://stackoverflow.com/a/65964721/288906 + - name: npm run lint + run: | + echo "::remove-matcher owner=eslint-compact::" + echo "::remove-matcher owner=eslint-stylish::" + npm run lint diff --git a/.gitignore b/.gitignore index 8fcef5096d..1ac7921689 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ db.sqlite3 .env .env.* staticfiles +.vscode # User-specific stuff: .idea/workspace.xml diff --git a/browsers/webpack.config.js b/browsers/webpack.config.js index dc1e55f262..0f16855762 100644 --- a/browsers/webpack.config.js +++ b/browsers/webpack.config.js @@ -351,6 +351,10 @@ module.exports = (env, options) => ({ type: "json", // Required by Webpack v4 use: "yaml-loader", }, + { + test: /\.txt/, + type: "asset/source", + }, ], }, }); diff --git a/package-lock.json b/package-lock.json index 0c90d6d649..5fa4c0d2ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6402,65 +6402,24 @@ } }, "@typescript-eslint/parser": { - "version": "4.20.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-4.20.0.tgz", - "integrity": "sha512-m6vDtgL9EABdjMtKVw5rr6DdeMCH3OA1vFb0dAyuZSa3e5yw1YRzlwFnm9knma9Lz6b2GPvoNSa8vOXrqsaglA==", + "version": "4.27.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-4.27.0.tgz", + "integrity": "sha512-XpbxL+M+gClmJcJ5kHnUpBGmlGdgNvy6cehgR6ufyxkEJMGP25tZKCaKyC0W/JVpuhU3VU1RBn7SYUPKSMqQvQ==", "dev": true, "requires": { - "@typescript-eslint/scope-manager": "4.20.0", - "@typescript-eslint/types": "4.20.0", - "@typescript-eslint/typescript-estree": "4.20.0", - "debug": "^4.1.1" + "@typescript-eslint/scope-manager": "4.27.0", + "@typescript-eslint/types": "4.27.0", + "@typescript-eslint/typescript-estree": "4.27.0", + "debug": "^4.3.1" }, "dependencies": { - "@typescript-eslint/scope-manager": { - "version": "4.20.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-4.20.0.tgz", - "integrity": "sha512-/zm6WR6iclD5HhGpcwl/GOYDTzrTHmvf8LLLkwKqqPKG6+KZt/CfSgPCiybshmck66M2L5fWSF/MKNuCwtKQSQ==", - "dev": true, - "requires": { - "@typescript-eslint/types": "4.20.0", - "@typescript-eslint/visitor-keys": "4.20.0" - } - }, - "@typescript-eslint/types": { - "version": "4.20.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-4.20.0.tgz", - "integrity": "sha512-cYY+1PIjei1nk49JAPnH1VEnu7OYdWRdJhYI5wiKOUMhLTG1qsx5cQxCUTuwWCmQoyriadz3Ni8HZmGSofeC+w==", - "dev": true - }, - "@typescript-eslint/typescript-estree": { - "version": "4.20.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-4.20.0.tgz", - "integrity": "sha512-Knpp0reOd4ZsyoEJdW8i/sK3mtZ47Ls7ZHvD8WVABNx5Xnn7KhenMTRGegoyMTx6TiXlOVgMz9r0pDgXTEEIHA==", - "dev": true, - "requires": { - "@typescript-eslint/types": "4.20.0", - "@typescript-eslint/visitor-keys": "4.20.0", - "debug": "^4.1.1", - "globby": "^11.0.1", - "is-glob": "^4.0.1", - "semver": "^7.3.2", - "tsutils": "^3.17.1" - } - }, - "@typescript-eslint/visitor-keys": { - "version": "4.20.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-4.20.0.tgz", - "integrity": "sha512-NXKRM3oOVQL8yNFDNCZuieRIwZ5UtjNLYtmMx2PacEAGmbaEYtGgVHUHVyZvU/0rYZcizdrWjDo+WBtRPSgq+A==", - "dev": true, - "requires": { - "@typescript-eslint/types": "4.20.0", - "eslint-visitor-keys": "^2.0.0" - } - }, - "semver": { - "version": "7.3.5", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", - "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "debug": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", + "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", "dev": true, "requires": { - "lru-cache": "^6.0.0" + "ms": "2.1.2" } } } @@ -11442,20 +11401,6 @@ "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", "dev": true }, - "globby": { - "version": "11.0.1", - "resolved": "https://registry.npmjs.org/globby/-/globby-11.0.1.tgz", - "integrity": "sha512-iH9RmgwCmUJHi2z5o2l3eTtGBtXek1OYlHrbcxOYugyHLmAsZrPj43OtHThd62Buh/Vv6VyCBD2bdyWcGNQqoQ==", - "dev": true, - "requires": { - "array-union": "^2.1.0", - "dir-glob": "^3.0.1", - "fast-glob": "^3.1.1", - "ignore": "^5.1.4", - "merge2": "^1.3.0", - "slash": "^3.0.0" - } - }, "globule": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/globule/-/globule-1.3.2.tgz", @@ -19186,15 +19131,6 @@ "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" }, - "tsutils": { - "version": "3.17.1", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.17.1.tgz", - "integrity": "sha512-kzeQ5B8H3w60nFY2g8cJIuH7JDpsALXySGtwGJ0p2LSjLgay3NdIpqq5SoOBe46bKDW2iq25irHCr8wjomUS2g==", - "dev": true, - "requires": { - "tslib": "^1.8.1" - } - }, "tty-browserify": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz", diff --git a/package.json b/package.json index 64050dcf26..5784c8b9c5 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "test": "jest", "test:watch": "jest --watchAll", - "lint": "eslint src/**", + "lint": "eslint src", "watch": "ENV_FILE='.env.development' webpack --mode development --config browsers/webpack.config.js --watch", "build": "NODE_OPTIONS=--max_old_space_size=8192 webpack --mode production --config browsers/webpack.config.js", "build:scripts": "webpack --mode production --config scripts/webpack.scripts.js", @@ -156,7 +156,7 @@ "@types/webpack-env": "^1.16.0", "@types/yup": "^0.29.11", "@typescript-eslint/eslint-plugin": "^4.27.0", - "@typescript-eslint/parser": "^4.20.0", + "@typescript-eslint/parser": "^4.27.0", "axios-mock-adapter": "^1.19.0", "babel-jest": "^27.0.2", "compass-mixins": "^0.12.10", diff --git a/src/devTools/editor/SelectorSelectorField.tsx b/src/devTools/editor/SelectorSelectorField.tsx index faf8806e7e..035e9a0abe 100644 --- a/src/devTools/editor/SelectorSelectorField.tsx +++ b/src/devTools/editor/SelectorSelectorField.tsx @@ -39,7 +39,6 @@ import { Framework } from "@/messaging/constants"; import { reportError } from "@/telemetry/logging"; // eslint is complaining that it can't parse the Option file -// eslint-disable-next-line import/namespace import { OptionProps } from "react-select/src/components/Option"; import { useToasts } from "react-toast-notifications"; diff --git a/src/helpers.ts b/src/helpers.ts index 69cc2913cd..33638391e6 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -60,7 +60,7 @@ export function engineRenderer( } // first part of the path can be global context with a @ -const pathRegex = /^(@?[a-zA-Z0-9_\-]+\??)(\.[a-zA-Z0-9_\-]+\??)*$/; +const pathRegex = /^(@?[a-zA-Z0-9_-]+\??)(\.[a-zA-Z0-9_-]+\??)*$/; /** * Return true if maybePath refers to a property in ctxt. diff --git a/src/import-svg.d.ts b/src/import-assets.d.ts similarity index 91% rename from src/import-svg.d.ts rename to src/import-assets.d.ts index cef4c7f881..ccb0e83e70 100644 --- a/src/import-svg.d.ts +++ b/src/import-assets.d.ts @@ -20,3 +20,8 @@ declare module "*.svg" { const value: any; export default value; } + +declare module "*.txt" { + const value: string; + export default value; +} diff --git a/src/options/pages/brickEditor/CodeEditor.tsx b/src/options/pages/brickEditor/CodeEditor.tsx index 4a52b9371b..9d6871fbef 100644 --- a/src/options/pages/brickEditor/CodeEditor.tsx +++ b/src/options/pages/brickEditor/CodeEditor.tsx @@ -21,21 +21,13 @@ import Select from "react-select"; import React, { useState, useRef, Suspense, useEffect } from "react"; import { useField, useFormikContext } from "formik"; -// https://webpack.js.org/loaders/raw-loader/#examples -const serviceTemplate = require("raw-loader!@contrib/templates/service.txt?esModule=false") - .default; -const emberjsTemplate = require("raw-loader!@contrib/templates/reader-emberjs.txt?esModule=false") - .default; -const jqueryTemplate = require("raw-loader!@contrib/templates/reader-jquery.txt?esModule=false") - .default; -const reactTemplate = require("raw-loader!@contrib/templates/reader-react.txt?esModule=false") - .default; -const menuTemplate = require("raw-loader!@contrib/templates/foundation-menu-item.txt?esModule=false") - .default; -const panelTemplate = require("raw-loader!@contrib/templates/foundation-panel.txt?esModule=false") - .default; -const blueprintTemplate = require("raw-loader!@contrib/templates/blueprint-menu.txt?esModule=false") - .default; +import serviceTemplate from "@contrib/templates/service.txt"; +import emberjsTemplate from "@contrib/templates/reader-emberjs.txt"; +import jqueryTemplate from "@contrib/templates/reader-jquery.txt"; +import reactTemplate from "@contrib/templates/reader-react.txt"; +import menuTemplate from "@contrib/templates/foundation-menu-item.txt"; +import panelTemplate from "@contrib/templates/foundation-panel.txt"; +import blueprintTemplate from "@contrib/templates/blueprint-menu.txt"; const AceEditor = React.lazy( () =>