Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* @fileoverview A modified version of the `multiline-comment-style` rule that ignores banner comments.
* @author Teddy Katz
*/
"use strict";
const ruleComposer = require("eslint-rule-composer");
const multilineCommentStyle = require("../../lib/rules/multiline-comment-style");
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
// The `no-invalid-meta` internal rule has a false positive here.
// eslint-disable-next-line internal-rules/no-invalid-meta
module.exports = ruleComposer.filterReports(
multilineCommentStyle,
(problem, metadata) => {
const problemIndex = metadata.sourceCode.getIndexFromLoc(problem.loc.start);
const reportedToken = metadata.sourceCode.getTokenByRangeStart(problemIndex, { includeComments: true });
return !(reportedToken && reportedToken.type === "Line" && /^-{2,}$/u.test(reportedToken.value));
}
);
import ruleComposer from "eslint-rule-composer";
import eslint from "eslint";
const quotesRule = new eslint.Linter().getRules().get("quotes");
export default ruleComposer.filterReports(quotesRule, problem => {
// Workaround for JSX fragment syntax until
// https://github.com/eslint/eslint/issues/9662
if (problem.node.parent.type === "JSXFragment") {
return false;
}
return true;
});
} else {
if (!isSemicolon(lastToken)) {
if (!exceptOneLine || !isOneLinerBlock(context, node)) {
report(context, node);
}
} else {
if (exceptOneLine && isOneLinerBlock(context, node)) {
report(context, node, true);
}
}
}
},
}),
]);
export default ruleComposer.filterReports(
semiRuleWithClassProperty,
problem => {
const node = problem.node;
// Handle async iterator:
// for await (let something of {})
if (
node.type === "VariableDeclaration" &&
node.parent.type === "ForAwaitStatement"
) {
return false;
}
return true;
},
);
import ruleComposer from "eslint-rule-composer";
import eslint from "eslint";
const objectCurlySpacingRule = new eslint.Linter()
.getRules()
.get("object-curly-spacing");
export default ruleComposer.filterReports(
objectCurlySpacingRule,
(problem, metadata) => {
const node = problem.node;
// Allow `exportNamespaceFrom` and `exportDefaultFrom` syntax:
// export * as x from '...';
// export x from '...';
if (
node.type === "ExportNamedDeclaration" &&
node.specifiers.length > 0 &&
metadata.sourceCode.getTokenBefore(node.specifiers[0]).value === "export"
) {
return false;
}
return true;
import ruleComposer from "eslint-rule-composer";
import eslint from "eslint";
const validTypeOf = new eslint.Linter().getRules().get("valid-typeof");
export default ruleComposer.filterReports(validTypeOf, problem => {
return problem.node.value !== "bigint";
});
}
/**
* @param {ASTNode} node - any node
* @returns {boolean} whether the given node is an optional call expression,
* see https://github.com/tc39/proposal-optional-chaining
*/
function isOptionalCallExpression(node) {
return (
!!node &&
node.type === "ExpressionStatement" &&
node.expression.type === "OptionalCallExpression"
);
}
export default ruleComposer.filterReports(
rule,
problem =>
!isInDoStatement(problem.node) && !isOptionalCallExpression(problem.node),
);
import ruleComposer from "eslint-rule-composer";
import eslint from "eslint";
const noInvalidThisRule = new eslint.Linter().getRules().get("no-invalid-this");
export default ruleComposer.filterReports(noInvalidThisRule, problem => {
let inClassProperty = false;
let node = problem.node;
while (node) {
if (node.type === "ClassProperty" || node.type === "ClassPrivateProperty") {
inClassProperty = true;
return;
}
node = node.parent;
}
return !inClassProperty;
});
import ruleComposer from "eslint-rule-composer";
import eslint from "eslint";
const newCapRule = new eslint.Linter().getRules().get("new-cap");
/**
* Returns whether a node is under a decorator or not.
* @param {ASTNode} node CallExpression node
* @returns {Boolean} Returns true if the node is under a decorator.
*/
function isDecorator(node) {
return node.parent.type === "Decorator";
}
export default ruleComposer.filterReports(
newCapRule,
problem => !isDecorator(problem.node),
);