How to use the eslint-rule-composer.filterReports function in eslint-rule-composer

To help you get started, we’ve selected a few eslint-rule-composer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eslint / eslint / tools / internal-rules / multiline-comment-style.js View on Github external
* @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));
    }
);
github babel / babel / eslint / babel-eslint-plugin / src / rules / quotes.js View on Github external
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;
});
github babel / babel / eslint / babel-eslint-plugin / src / rules / semi.js View on Github external
} 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;
  },
);
github babel / babel / eslint / babel-eslint-plugin / src / rules / object-curly-spacing.js View on Github external
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;
github babel / babel / eslint / babel-eslint-plugin / src / rules / valid-typeof.js View on Github external
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";
});
github babel / babel / eslint / babel-eslint-plugin / src / rules / no-unused-expressions.js View on Github external
}

/**
 * @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),
);
github babel / babel / eslint / babel-eslint-plugin / src / rules / no-invalid-this.js View on Github external
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;
});
github babel / babel / eslint / babel-eslint-plugin / src / rules / new-cap.js View on Github external
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),
);

eslint-rule-composer

A utility for composing ESLint rules from other ESLint rules

MIT
Latest version published 7 years ago

Package Health Score

67 / 100
Full package analysis