google_forms/node_modules/eslint/lib/rules/no-spaced-func.js

84 lines
2.4 KiB
JavaScript
Raw Normal View History

2024-08-09 12:04:48 +00:00
/**
* @fileoverview Rule to check that spaced function application
* @author Matt DuVall <http://www.mattduvall.com>
* @deprecated in ESLint v3.3.0
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
2024-08-21 06:34:30 +00:00
/** @type {import('../shared/types').Rule} */
2024-08-09 12:04:48 +00:00
module.exports = {
meta: {
type: "layout",
docs: {
2024-08-21 06:34:30 +00:00
description: "Disallow spacing between function identifiers and their applications (deprecated)",
2024-08-09 12:04:48 +00:00
recommended: false,
2024-08-21 06:34:30 +00:00
url: "https://eslint.org/docs/latest/rules/no-spaced-func"
2024-08-09 12:04:48 +00:00
},
deprecated: true,
replacedBy: ["func-call-spacing"],
fixable: "whitespace",
schema: [],
messages: {
noSpacedFunction: "Unexpected space between function name and paren."
}
},
create(context) {
2024-08-21 06:34:30 +00:00
const sourceCode = context.sourceCode;
2024-08-09 12:04:48 +00:00
/**
* Check if open space is present in a function name
* @param {ASTNode} node node to evaluate
* @returns {void}
* @private
*/
function detectOpenSpaces(node) {
const lastCalleeToken = sourceCode.getLastToken(node.callee);
let prevToken = lastCalleeToken,
parenToken = sourceCode.getTokenAfter(lastCalleeToken);
// advances to an open parenthesis.
while (
parenToken &&
parenToken.range[1] < node.range[1] &&
parenToken.value !== "("
) {
prevToken = parenToken;
parenToken = sourceCode.getTokenAfter(parenToken);
}
// look for a space between the callee and the open paren
if (parenToken &&
parenToken.range[1] < node.range[1] &&
sourceCode.isSpaceBetweenTokens(prevToken, parenToken)
) {
context.report({
node,
loc: lastCalleeToken.loc.start,
messageId: "noSpacedFunction",
fix(fixer) {
return fixer.removeRange([prevToken.range[1], parenToken.range[0]]);
}
});
}
}
return {
CallExpression: detectOpenSpaces,
NewExpression: detectOpenSpaces
};
}
};