How to use the @typescript-eslint/eslint-plugin.rules function in @typescript-eslint/eslint-plugin

To help you get started, we’ve selected a few @typescript-eslint/eslint-plugin 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 SonarSource / SonarJS / eslint-bridge / src / linter.ts View on Github external
}

export interface AdditionalRule {
  ruleId: string;
  ruleModule: ESLintRule.RuleModule;
  ruleConfig: any[];
}

const linter = new Linter();
linter.defineRules(sonarjsRules);
linter.defineRules(internalRules);

try {
  // we load "@typescript-eslint/eslint-plugin" dynamically as it requires TS and so we don't need typescript dependency when analysing pure JS project
  const typescriptEslintRules = require("@typescript-eslint/eslint-plugin").rules;
  linter.defineRules(typescriptEslintRules);
} catch {
  // do nothing, "typescript" is not there
}

// core implementation of this rule raises FPs on chai framework
linter.defineRule("no-unused-expressions", chaiFriendlyRules["no-unused-expressions"]);

/**
 * 'additionalRules' - rules used for computing metrics (incl. highlighting) when it requires access to the rule context; resulting value is encoded in the message
 */
export function analyze(
  sourceCode: SourceCode,
  filePath: string,
  inputRules: Rule[],
  ...additionalRules: AdditionalRule[]
) {