Fix test:dist-lint script (#16406)

This commit is contained in:
fisker Cheung authored and GitHub committed 2024-06-14 18:07:10 +08:00
1 parent be65292529
commit a7fbf9143a
3 files changed
+117 -90

No files matched your search

+2 -2
View File
@@ -130,7 +130,7 @@
"eslint": "9.4.0",
"eslint-config-prettier": "9.1.0",
"eslint-formatter-friendly": "7.0.0",
"eslint-plugin-compat": "4.2.0",
"eslint-plugin-compat": "5.0.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jest": "28.6.0",
"eslint-plugin-n": "17.8.1",
@@ -165,7 +165,7 @@
"test:dev-package": "cross-env INSTALL_PACKAGE=1 yarn test",
"test:dist": "cross-env NODE_ENV=production yarn test",
"test:dist-standalone": "cross-env TEST_STANDALONE=1 yarn test:dist",
"test:dist-lint": "eslint --no-ignore --no-inline-config --config=./scripts/bundle-eslint-config.js dist",
"test:dist-lint": "eslint dist --config=./scripts/bundle-eslint-config.js --quiet",
"perf": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin/prettier.cjs",
"perf:inspect": "yarn && yarn build && cross-env NODE_ENV=production node --inspect-brk ./dist/bin/prettier.cjs",
"perf:benchmark": "yarn perf --debug-benchmark",
+77 -67
View File
@@ -1,15 +1,67 @@
import fs from "node:fs/promises";
import url from "node:url";
import { FlatCompat } from "@eslint/eslintrc";
import eslintPluginCompat from "eslint-plugin-compat";
const { browserslist: targets } = JSON.parse(
await fs.readFile(new URL("../package.json", import.meta.url)),
);
const toPath = (file) => url.fileURLToPath(new URL(file, import.meta.url));
const compat = new FlatCompat({ baseDirectory: toPath("./") });
const browserFiles = [
"doc.js",
"doc.mjs",
"standalone.js",
"standalone.mjs",
"plugins/*",
];
const nodejsFiles = ["index.cjs", "index.mjs", "bin/*", "internal/*"];
const restrictedSyntaxes = [
{
selector: String.raw`CallExpression[callee.name="require"][arguments.0.value=/^\..*?\.mjs$/]`,
message: ".mjs file can't be `require()`d",
},
];
const browserRestrictedSyntaxes = [
{
selector: 'CallExpression[callee.name="require"]',
message: "Universal bundles should not include any `require()` call.",
},
{
selector: "ImportDeclaration",
message: "Universal bundles should not include any `import` declaration.",
},
{
selector:
":matches(ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration)[source]",
message: "Universal bundles should not `export` from other files.",
},
{
selector: "ImportExpression",
message: "Universal bundles should not include any `import()`.",
},
];
const nodejsRestrictedSyntaxes = [
// Forbid top level `require()` parsers
{
selector:
'CallExpression:not(:function *)[callee.name="require"][arguments.0.value=/plugins/]',
message: "Parsers should be inline `require()`d.",
},
// Forbid top level `import()` parsers
{
selector: "ImportExpression:not(:function *)[source.value=/plugins/]",
message: "Parsers should be inline `import()`ed.",
},
// Forbid `import`/`export` parsers
{
selector:
":matches(ImportDeclaration, ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration)[source.value=/plugins/]",
message: "Parsers should be inline `import()`ed.",
},
];
/* TODO[@fisker]: Fix `no-restricted-syntax` */
@@ -27,80 +79,38 @@ export default [
"Symbol.asyncIterator",
],
},
linterOptions: {
noInlineConfig: true,
reportUnusedDisableDirectives: "off",
},
rules: {
"compat/compat": "error",
"no-restricted-syntax": ["error", ...restrictedSyntaxes],
},
},
{
files: browserFiles,
rules: {
"no-restricted-syntax": [
"error",
// Forbid `require()` .mjs file
{
selector: String.raw`CallExpression[callee.name="require"][arguments.0.value=/^\..*?\.mjs$/]`,
message: ".mjs file can't be `require()`d",
},
...restrictedSyntaxes,
...browserRestrictedSyntaxes,
],
},
},
{
files: [
"doc.js",
"doc.mjs",
"standalone.js",
"standalone.mjs",
"plugins/*",
],
...compat.env({ browser: true }),
files: nodejsFiles,
rules: {
"compat/compat": "error",
// "no-restricted-syntax": [
// "error",
// // Forbid `require()`
// {
// selector: 'CallExpression[callee.name="require"]',
// message:
// "Universal bundles should not include any `require()` call.",
// },
// {
// selector: "ImportDeclaration",
// message:
// "Universal bundles should not include any `import` declaration.",
// },
// {
// selector:
// ":matches(ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration)[source]",
// message: "Universal bundles should not `export` from other files.",
// },
// {
// selector: "ImportExpression",
// message: "Universal bundles should not include any `import()`.",
// },
// ],
},
},
{
files: ["index.cjs", "index.mjs", "bin/*", "internal/*"],
rules: {
// "no-restricted-syntax": [
// "error",
// // Forbid top level `require()` parsers
// {
// selector:
// 'CallExpression:not(:function *)[callee.name="require"][arguments.0.value=/plugins/]',
// message: "Parsers should be inline `require()`d.",
// },
// // Forbid top level `import()` parsers
// {
// selector:
// "ImportExpression:not(:function *)[source.value=/plugins/]",
// message: "Parsers should be inline `import()`ed.",
// },
// // Forbid `import`/`export` parsers
// {
// selector:
// ":matches(ImportDeclaration, ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration)[source.value=/plugins/]",
// message: "Parsers should be inline `import()`ed.",
// },
// ],
"no-restricted-syntax": [
"error",
...restrictedSyntaxes,
...nodejsRestrictedSyntaxes,
],
},
},
{
files: ["bin/prettier.cjs"],
languageOptions: {
+38 -21
View File
@@ -1682,10 +1682,10 @@ __metadata:
languageName: node
linkType: hard
"@mdn/browser-compat-data@npm:^5.2.34, @mdn/browser-compat-data@npm:^5.3.13":
version: 5.4.1
resolution: "@mdn/browser-compat-data@npm:5.4.1"
checksum: 10/2772d72a73789a8ea3df4476c816b2f96c809a70495db472562170cdde84dc52d16a7fe0cdb49d568e9212b01389f213cd024c2644500db1da932306a73dbb95
"@mdn/browser-compat-data@npm:^5.2.34, @mdn/browser-compat-data@npm:^5.5.19":
version: 5.5.33
resolution: "@mdn/browser-compat-data@npm:5.5.33"
checksum: 10/1fb9fdf40308ecb77a4e2460049ae29c11935442fc02a6c9cf1081bb46f54538a8a820b3fc54aecc6a704f9eaac17aabd6f3c881cf3e676a86c8641f000a8e6e
languageName: node
linkType: hard
@@ -2631,7 +2631,7 @@ __metadata:
languageName: node
linkType: hard
"browserslist@npm:4.23.1, browserslist@npm:^4.21.10, browserslist@npm:^4.21.9, browserslist@npm:^4.23.0":
"browserslist@npm:4.23.1, browserslist@npm:^4.21.9, browserslist@npm:^4.23.0":
version: 4.23.1
resolution: "browserslist@npm:4.23.1"
dependencies:
@@ -2755,10 +2755,10 @@ __metadata:
languageName: node
linkType: hard
"caniuse-lite@npm:^1.0.30001524, caniuse-lite@npm:^1.0.30001629":
version: 1.0.30001632
resolution: "caniuse-lite@npm:1.0.30001632"
checksum: 10/80b8b75007e525c30ec204adff4a16797a83ac9faeec33ed20ad14b55239c2721693f248389ee3bc9a76f8fd0182870872af7a9c80d48484a3eab7c5e8af173f
"caniuse-lite@npm:^1.0.30001605, caniuse-lite@npm:^1.0.30001629":
version: 1.0.30001634
resolution: "caniuse-lite@npm:1.0.30001634"
checksum: 10/4d379e90127744a9e98b2f139d3e445c87aa7f89f6d219dc624f98e72198a99dacd8e395109b56c8e5469668f6796f5813abf8853eee163f852a487ff4a3759a
languageName: node
linkType: hard
@@ -3828,20 +3828,21 @@ __metadata:
languageName: node
linkType: hard
"eslint-plugin-compat@npm:4.2.0":
version: 4.2.0
resolution: "eslint-plugin-compat@npm:4.2.0"
"eslint-plugin-compat@npm:5.0.0":
version: 5.0.0
resolution: "eslint-plugin-compat@npm:5.0.0"
dependencies:
"@mdn/browser-compat-data": "npm:^5.3.13"
"@mdn/browser-compat-data": "npm:^5.5.19"
ast-metadata-inferer: "npm:^0.8.0"
browserslist: "npm:^4.21.10"
caniuse-lite: "npm:^1.0.30001524"
browserslist: "npm:^4.23.0"
caniuse-lite: "npm:^1.0.30001605"
find-up: "npm:^5.0.0"
globals: "npm:^13.24.0"
lodash.memoize: "npm:^4.1.2"
semver: "npm:^7.5.4"
semver: "npm:^7.6.0"
peerDependencies:
eslint: ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0
checksum: 10/01bb4adbb38dd9549ad24e5b4bc2f5b8dd31e67a4b5c89e9110be3352fee3cdca4fde786a7cd25eccf193eebffb5af79afc02de036ff7cd27b84a3e9a8a402cf
checksum: 10/e211daeb41d99b580c01bba9aaeb81dd6a42b41c172cbdcc1f8eb16b843a8b9a1b79905113f41aa8806e6ca606bb463f6431f4e9cc34ba37fd5eaadeca680a81
languageName: node
linkType: hard
@@ -4622,6 +4623,15 @@ __metadata:
languageName: node
linkType: hard
"globals@npm:^13.24.0":
version: 13.24.0
resolution: "globals@npm:13.24.0"
dependencies:
type-fest: "npm:^0.20.2"
checksum: 10/62c5b1997d06674fc7191d3e01e324d3eda4d65ac9cc4e78329fa3b5c4fd42a0e1c8722822497a6964eee075255ce21ccf1eec2d83f92ef3f06653af4d0ee28e
languageName: node
linkType: hard
"globals@npm:^14.0.0":
version: 14.0.0
resolution: "globals@npm:14.0.0"
@@ -4630,9 +4640,9 @@ __metadata:
linkType: hard
"globals@npm:^15.0.0":
version: 15.3.0
resolution: "globals@npm:15.3.0"
checksum: 10/ad4e845884e045d211fd7c4511f51a3484d6db8438d7a8ec9366919771f802596964aaa514f2561bd375ee7d0d57e83a056ef50996eee5a676400534c75e4d06
version: 15.4.0
resolution: "globals@npm:15.4.0"
checksum: 10/886e687466ceee48fe61f1a6c69fb714e79a84b9e11953baa355b94da0d72caf0e8186d64dcf1299d27ef5f231029baadd197593323ccc6617d487216e561c9b
languageName: node
linkType: hard
@@ -7359,7 +7369,7 @@ __metadata:
eslint: "npm:9.4.0"
eslint-config-prettier: "npm:9.1.0"
eslint-formatter-friendly: "npm:7.0.0"
eslint-plugin-compat: "npm:4.2.0"
eslint-plugin-compat: "npm:5.0.0"
eslint-plugin-import: "npm:2.29.1"
eslint-plugin-jest: "npm:28.6.0"
eslint-plugin-n: "npm:17.8.1"
@@ -8613,6 +8623,13 @@ __metadata:
languageName: node
linkType: hard
"type-fest@npm:^0.20.2":
version: 0.20.2
resolution: "type-fest@npm:0.20.2"
checksum: 10/8907e16284b2d6cfa4f4817e93520121941baba36b39219ea36acfe64c86b9dbc10c9941af450bd60832c8f43464974d51c0957f9858bc66b952b66b6914cbb9
languageName: node
linkType: hard
"type-fest@npm:^0.21.3":
version: 0.21.3
resolution: "type-fest@npm:0.21.3"