Files
NapCatQQ/.pnpm-store/v3/files/87/d73faa98ec70a35fe90669db8c152c6c5fb2c495291695a0aaf0c230cd100c73afa05ed883177b3bfbd9bda5dfb23a2a190d30b270457168251139438708e3
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

56 lines
1.6 KiB
Plaintext

'use strict';
var utils = require('../utils.js');
require('eslint-visitor-keys');
require('espree');
require('estraverse');
function isConditional(node) {
return node.type === "ConditionalExpression";
}
var noConfusingArrow = utils.createRule({
name: "no-confusing-arrow",
package: "js",
meta: {
type: "layout",
docs: {
description: "Disallow arrow functions where they could be confused with comparisons"
},
fixable: "code",
schema: [{
type: "object",
properties: {
allowParens: { type: "boolean", default: true },
onlyOneSimpleParam: { type: "boolean", default: false }
},
additionalProperties: false
}],
messages: {
confusing: "Arrow function used ambiguously with a conditional expression."
}
},
create(context) {
const config = context.options[0] || {};
const allowParens = config.allowParens || config.allowParens === void 0;
const onlyOneSimpleParam = config.onlyOneSimpleParam;
const sourceCode = context.sourceCode;
function checkArrowFunc(node) {
const body = node.body;
if (isConditional(body) && !(allowParens && utils.isParenthesised(sourceCode, body)) && !(onlyOneSimpleParam && !(node.params.length === 1 && node.params[0].type === "Identifier"))) {
context.report({
node,
messageId: "confusing",
fix(fixer) {
return allowParens ? fixer.replaceText(node.body, `(${sourceCode.getText(node.body)})`) : null;
}
});
}
}
return {
ArrowFunctionExpression: checkArrowFunc
};
}
});
module.exports = noConfusingArrow;