google_forms/node_modules/eslint/lib/rules/symbol-description.js

74 lines
2.0 KiB
JavaScript
Raw Normal View History

2024-08-09 12:04:48 +00:00
/**
* @fileoverview Rule to enforce description with the `Symbol` object
* @author Jarek Rencz
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const astUtils = require("./utils/ast-utils");
//------------------------------------------------------------------------------
// 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: "suggestion",
docs: {
2024-08-21 06:34:30 +00:00
description: "Require symbol descriptions",
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/symbol-description"
2024-08-09 12:04:48 +00:00
},
fixable: null,
schema: [],
messages: {
expected: "Expected Symbol to have a description."
}
},
create(context) {
2024-08-21 06:34:30 +00:00
const sourceCode = context.sourceCode;
2024-08-09 12:04:48 +00:00
/**
* Reports if node does not conform the rule in case rule is set to
* report missing description
* @param {ASTNode} node A CallExpression node to check.
* @returns {void}
*/
function checkArgument(node) {
if (node.arguments.length === 0) {
context.report({
node,
messageId: "expected"
});
}
}
return {
2024-08-21 06:34:30 +00:00
"Program:exit"(node) {
const scope = sourceCode.getScope(node);
2024-08-09 12:04:48 +00:00
const variable = astUtils.getVariableByName(scope, "Symbol");
if (variable && variable.defs.length === 0) {
variable.references.forEach(reference => {
2024-08-21 06:34:30 +00:00
const idNode = reference.identifier;
2024-08-09 12:04:48 +00:00
2024-08-21 06:34:30 +00:00
if (astUtils.isCallee(idNode)) {
checkArgument(idNode.parent);
2024-08-09 12:04:48 +00:00
}
});
}
}
};
}
};