12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- "use strict";
- module.exports = {
- meta: {
- docs: {
- url:
- "https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint-plugin-mozilla/no-useless-run-test.html",
- },
- fixable: "code",
- type: "suggestion",
- },
- create(context) {
- return {
- "Program > FunctionDeclaration": function(node) {
- if (
- node.id.name === "run_test" &&
- node.body.type === "BlockStatement" &&
- node.body.body.length === 1 &&
- node.body.body[0].type === "ExpressionStatement" &&
- node.body.body[0].expression.type === "CallExpression" &&
- node.body.body[0].expression.callee.name === "run_next_test"
- ) {
- context.report({
- node,
- fix: fixer => {
- let sourceCode = context.getSourceCode();
- let startNode;
- if (sourceCode.getCommentsBefore) {
-
- startNode = sourceCode.getCommentsBefore(node);
- } else if (node && node.body && node.leadingComments) {
-
- startNode = node.leadingComments;
- }
-
-
-
-
- if (startNode?.length) {
- startNode = startNode[startNode.length - 1];
- } else {
- startNode = sourceCode.getTokenBefore(node);
- }
- return fixer.removeRange([
-
-
- startNode ? startNode.range[1] + 1 : 0,
-
-
-
-
- node.range[1] + 1,
- ]);
- },
- message:
- "Useless run_test function - only contains run_next_test; whole function can be removed",
- });
- }
- },
- };
- },
- };
|