Switch to the new ESLint config (#15869)
This commit is contained in:
1 parent
6432f9b931
commit
d3dca92292
8 files changed
+628
-587
No files matched your search
@@ -1,117 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
const targets = require("../package.json").browserslist;
|
||||
|
||||
/* TODO[@fisker]: Fix `no-restricted-syntax` */
|
||||
|
||||
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: ["**/*"],
|
||||
rules: {
|
||||
"no-restricted-syntax": [
|
||||
"error",
|
||||
// Forbid `require()` .mjs file
|
||||
{
|
||||
selector:
|
||||
'CallExpression[callee.name="require"][arguments.0.value=/^\\..*?\\.mjs$/]',
|
||||
message: ".mjs file can't be `require()`d",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["**/*.mjs"],
|
||||
parserOptions: {
|
||||
sourceType: "module",
|
||||
},
|
||||
},
|
||||
{
|
||||
files: [
|
||||
"doc.js",
|
||||
"doc.mjs",
|
||||
"standalone.js",
|
||||
"standalone.mjs",
|
||||
"plugins/*",
|
||||
],
|
||||
env: {
|
||||
browser: true,
|
||||
},
|
||||
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.",
|
||||
// },
|
||||
// ],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["bin/prettier.cjs"],
|
||||
parserOptions: {
|
||||
ecmaVersion: 5,
|
||||
},
|
||||
rules: {
|
||||
"compat/compat": "error",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,114 @@
|
||||
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("./") });
|
||||
|
||||
/* TODO[@fisker]: Fix `no-restricted-syntax` */
|
||||
|
||||
export default [
|
||||
{
|
||||
plugins: {
|
||||
compat: eslintPluginCompat,
|
||||
},
|
||||
settings: {
|
||||
targets,
|
||||
lintAllEsApis: true,
|
||||
polyfills: [
|
||||
// These are not really polyfilled, but seems safe to use in target browsers
|
||||
"BigInt",
|
||||
"Symbol.asyncIterator",
|
||||
],
|
||||
},
|
||||
rules: {
|
||||
"no-restricted-syntax": [
|
||||
"error",
|
||||
// Forbid `require()` .mjs file
|
||||
{
|
||||
selector:
|
||||
'CallExpression[callee.name="require"][arguments.0.value=/^\\..*?\\.mjs$/]',
|
||||
message: ".mjs file can't be `require()`d",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
files: [
|
||||
"doc.js",
|
||||
"doc.mjs",
|
||||
"standalone.js",
|
||||
"standalone.mjs",
|
||||
"plugins/*",
|
||||
],
|
||||
...compat.env({ browser: true }),
|
||||
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.",
|
||||
// },
|
||||
// ],
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["bin/prettier.cjs"],
|
||||
languageOptions: {
|
||||
ecmaVersion: 5,
|
||||
},
|
||||
rules: {
|
||||
"compat/compat": "error",
|
||||
},
|
||||
},
|
||||
];
|
||||
+1
-3
@@ -164,9 +164,7 @@ module.exports = {
|
||||
fixable: "code",
|
||||
},
|
||||
create(context) {
|
||||
const { ignoreSingleType, onlyTopLevelFunctions } = {
|
||||
ignoreSingleType: false,
|
||||
onlyTopLevelFunctions: false,
|
||||
const { ignoreSingleType = false, onlyTopLevelFunctions = false } = {
|
||||
...context.options[0],
|
||||
};
|
||||
const sourceCode = context.getSourceCode();
|
||||
|
||||
Reference in new issue
Block a user