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

67 lines
2.0 KiB
Plaintext

"use strict"
const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")
module.exports = {
meta: {
docs: {
description:
"disallow the `String.prototype.{trimLeft,trimRight}` methods.",
category: "legacy",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-string-prototype-trimleft-trimright.html",
},
fixable: "code",
messages: {
forbidden: "Annex B feature '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
hasSuggestions: true,
},
create(context) {
return definePrototypeMethodHandler(
context,
{
String: ["trimLeft", "trimRight"],
},
{
createReport({ objectTypeResult, node, propertyName }) {
if (node.computed) {
return null
}
const newPropertyName =
propertyName === "trimLeft" ? "trimStart" : "trimEnd"
if (objectTypeResult !== true) {
return {
suggest: [
{
desc: `Replace with '${newPropertyName}'`,
fix,
},
],
}
}
return {
fix,
}
function fix(fixer) {
return fixer.replaceText(node.property, newPropertyName)
}
},
},
)
},
}