@babel/eslint-plugin
Version:
Companion rules for @babel/eslint-parser
70 lines (63 loc) • 1.86 kB
JavaScript
import { builtinRules } from 'eslint/use-at-your-own-risk';
function filterReports(rule, predicate) {
return Object.freeze({
create(context) {
return rule.create(Object.freeze(Object.create(context, {
report: {
enumerable: true,
value(...args) {
const violation = args[0];
if (predicate(violation, context)) {
context.report(...args);
}
}
}
})));
},
meta: rule.meta
});
}
const rule$2 = builtinRules.get("new-cap");
function isDecorator(node) {
return node.parent.type === "Decorator";
}
const newCap = filterReports(rule$2, problem => !isDecorator(problem.node));
const rule$1 = builtinRules.get("no-undef");
const rule = builtinRules.get("no-unused-expressions");
function isFinalStatementInBlockStatement(node) {
const parent = node.parent;
return /^(?:If|Expression)Statement$/.test(node.type) && parent.type === "BlockStatement" && parent.body[parent.body.length - 1] === node;
}
function isInDoStatement(node) {
if (!node) return false;
if (node.type === "DoExpression") return true;
if (node.type === "IfStatement" && node.parent && node.parent.type === "IfStatement") {
return isInDoStatement(node.parent);
}
if (isFinalStatementInBlockStatement(node)) {
return isInDoStatement(node.parent.parent);
}
return false;
}
const noUnusedExpressions = filterReports(rule, problem => !isInDoStatement(problem.node));
const meta = {
name: "@babel/eslint-plugin",
version: "8.0.1"
};
const rules = {
"new-cap": newCap,
"no-undef": rule$1,
"no-unused-expressions": noUnusedExpressions
};
const rulesConfig = {
"new-cap": "off",
"no-undef": "off",
"no-unused-expressions": "off"
};
const index = {
meta,
rules,
rulesConfig
};
export { index as default };
//# sourceMappingURL=index.js.map