Files
NapCatQQ/.pnpm-store/v3/files/93/fa088f81cdc9c998f329925c4c9bd611c4d54bf84aec8a2b4fc282b58ed449ff2fa6b2ee3278feb7625286e2650c5cae2e0d84d6a5b9244fc884f21b7ad55d
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

59 lines
2.0 KiB
Plaintext

/**
* @author Toru Nagashima <https://github.com/mysticatea>
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils")
const { getSourceCode } = require("eslint-compat-utils")
module.exports = {
meta: {
docs: {
description: "disallow the subclassing of the built-in classes.",
category: "ES2015",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-subclassing-builtins.html",
},
fixable: null,
messages: {
forbidden: "ES2015 subclassing of '{{name}}' is forbidden.",
},
schema: [],
type: "problem",
},
create(context) {
return {
"Program:exit"(program) {
const sourceCode = getSourceCode(context)
const tracker = new ReferenceTracker(
sourceCode.getScope(program),
)
for (const { node, path } of tracker.iterateGlobalReferences({
Array: { [READ]: true },
Boolean: { [READ]: true },
Error: { [READ]: true },
RegExp: { [READ]: true },
Function: { [READ]: true },
Map: { [READ]: true },
Number: { [READ]: true },
Promise: { [READ]: true },
Set: { [READ]: true },
String: { [READ]: true },
})) {
if (
node.parent.type.startsWith("Class") &&
node.parent.superClass === node
) {
context.report({
node,
messageId: "forbidden",
data: { name: path.join(".") },
})
}
}
},
}
},
}