From ed951b316799dd169fdf208cd74d0b9eb1566055 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Wed, 9 Feb 2022 08:30:36 +0800 Subject: [PATCH] Update `test:dist-lint` script (#12262) --- .github/workflows/prod-test.yml | 2 +- package.json | 2 +- scripts/bundle-eslint-config.cjs | 70 ++++++++++++++++++++++++++++++++ scripts/bundle-eslint-config.js | 26 ------------ 4 files changed, 72 insertions(+), 28 deletions(-) create mode 100644 scripts/bundle-eslint-config.cjs delete mode 100644 scripts/bundle-eslint-config.js diff --git a/.github/workflows/prod-test.yml b/.github/workflows/prod-test.yml index fe4dbafaf..fa8b39172 100644 --- a/.github/workflows/prod-test.yml +++ b/.github/workflows/prod-test.yml @@ -65,7 +65,7 @@ jobs: path: dist - name: Lint Code - run: yarn lint:dist + run: yarn test:dist-lint test: timeout-minutes: 90 diff --git a/package.json b/package.json index 031a328a6..a4afae3ee 100644 --- a/package.json +++ b/package.json @@ -144,6 +144,7 @@ "test:dist": "cross-env NODE_ENV=production jest", "test:dist-standalone": "cross-env NODE_ENV=production TEST_STANDALONE=1 jest", "test:integration": "jest tests/integration", + "test:dist-lint": "eslint --no-eslintrc --no-ignore --no-inline-config --config=./scripts/bundle-eslint-config.cjs \"dist/**/*.{js,mjs}\"", "perf:repeat": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-repeat ${PERF_REPEAT:-1000} --loglevel debug ${PERF_FILE:-./index.js} > /dev/null", "perf:repeat-inspect": "yarn && yarn build && cross-env NODE_ENV=production node --inspect-brk ./dist/bin-prettier.js --debug-repeat ${PERF_REPEAT:-1000} --loglevel debug ${PERF_FILE:-./index.js} > /dev/null", "perf:benchmark": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-benchmark --loglevel debug ${PERF_FILE:-./index.js} > /dev/null", @@ -152,7 +153,6 @@ "lint:eslint": "cross-env EFF_NO_LINK_RULES=true eslint . --format friendly", "lint:changelog": "node ./scripts/lint-changelog.mjs", "lint:prettier": "prettier . \"!test*\" --check", - "lint:dist": "eslint --no-eslintrc --no-ignore --no-inline-config --config=./scripts/bundle-eslint-config.js \"dist/!(bin-prettier|index|third-party).js\"", "lint:spellcheck": "cspell --no-progress --relative --dot --gitignore", "lint:deps": "node ./scripts/check-deps.mjs", "lint:actionlint": "node-actionlint", diff --git a/scripts/bundle-eslint-config.cjs b/scripts/bundle-eslint-config.cjs new file mode 100644 index 000000000..e1f3c4bb8 --- /dev/null +++ b/scripts/bundle-eslint-config.cjs @@ -0,0 +1,70 @@ +"use strict"; + +const targets = require("../package.json").browserslist; + +module.exports = { + root: true, + parserOptions: { + ecmaVersion: "latest", + }, + settings: { + targets, + lintAllEsApis: true, + polyfills: [ + // These are not really polyfilled, but seems safe to use in target browsers + "BigInt", + "Symbol.asyncIterator", + ], + }, + plugins: ["compat"], + overrides: [ + { + files: ["**/*.mjs"], + parserOptions: { + sourceType: "module", + }, + }, + { + files: [ + "doc.js", + "parser-*.js", + "standalone.js", + "parser-*.mjs", + "standalone.mjs", + ], + env: { + browser: true, + }, + rules: { + "compat/compat": "error", + }, + }, + { + files: ["index.js", "bin-prettier.js", "third-party.js"], + rules: { + "no-restricted-syntax": [ + "error", + // Forbid top level `require()` parsers + { + selector: + 'CallExpression:not(:function *)[callee.name="require"][arguments.0.value=/parser-/]', + message: "Parsers should be inline `require()`d.", + }, + ], + }, + }, + { + files: ["doc.js", "parser-*.js", "standalone.js"], + rules: { + "no-restricted-syntax": [ + "error", + // Forbid `require()` + { + selector: 'CallExpression[callee.name="require"]', + message: "UMD bundles should not include any `require()` call.", + }, + ], + }, + }, + ], +}; diff --git a/scripts/bundle-eslint-config.js b/scripts/bundle-eslint-config.js deleted file mode 100644 index 01e9edda1..000000000 --- a/scripts/bundle-eslint-config.js +++ /dev/null @@ -1,26 +0,0 @@ -"use strict"; - -const targets = require("../package.json").browserslist; - -module.exports = { - root: true, - env: { - browser: true, - }, - parserOptions: { - ecmaVersion: "latest", - }, - settings: { - targets, - lintAllEsApis: true, - polyfills: [ - // These are not really polyfilled, but seems safe to use in target browsers - "BigInt", - "Symbol.asyncIterator", - ], - }, - plugins: ["compat"], - rules: { - "compat/compat": "error", - }, -};