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

47 lines
1.4 KiB
Plaintext

/**
* Adapted from `eslint-plugin-unicorn`
* @license MIT
*/
'use strict'
const { isCommaToken } = require('@eslint-community/eslint-utils')
const { getParentheses } = require('../lib/parentheses.js')
function removeArgument(fixer, node, sourceCode) {
const callExpression = node.parent
const index = callExpression.arguments.indexOf(node)
const parentheses = getParentheses(node, sourceCode)
const firstToken = parentheses[0] || node
const lastToken = parentheses.at(-1) || node
let [start] = firstToken.range
let [, end] = lastToken.range
if (index !== 0) {
start = sourceCode.getTokenBefore(firstToken).range[0]
}
// If there are subsequent arguments, the trailing comma must be removed too
/* istanbul ignore else */
if (index < callExpression.arguments.length - 1) {
let tokenAfter = sourceCode.getTokenAfter(lastToken)
/* istanbul ignore else */
if (isCommaToken(tokenAfter)) {
// Advance to start of next token (after whitespace)
tokenAfter = sourceCode.getTokenAfter(tokenAfter)
end = tokenAfter.range[0]
}
}
// If the removed argument is the only argument, the trailing comma must be removed too
else if (callExpression.arguments.length === 1) {
const tokenAfter = sourceCode.getTokenBefore(lastToken)
if (isCommaToken(tokenAfter)) {
end = tokenAfter[1]
}
}
return fixer.replaceTextRange([start, end], '')
}
module.exports = removeArgument