ESLint Test Utility

0.8.2 · deprecated · verified Sun Apr 19

eslint-tester is a utility package designed to facilitate testing within the ESLint project itself, and was initially intended for broader use by authors of custom ESLint rules. However, as of ESLint v1.0.0, this package has been deprecated and is no longer actively developed. Its functionality has been superseded by the `RuleTester` class, which is directly exposed within the main `eslint` package and is the recommended way to test ESLint rules. The package's last significant update (`v0.8.2`) was in June 2015, and its GitHub repository explicitly marks it as 'DEPRECATED'. Users should avoid this package and instead use `RuleTester` from `eslint` for current projects. The release cadence was irregular, with its primary focus being internal ESLint development.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates the conceptual usage of `eslint-tester` for defining and testing a simple custom ESLint rule. Note its deprecation.

const ESLintTester = require('eslint-tester');

// Mock a simple ESLint rule for demonstration
const myCustomRule = {
  meta: {
    type: 'suggestion',
    schema: [],
    messages: {
      avoidFoo: 'Avoid using the identifier `foo`.'
    }
  },
  create(context) {
    return {
      Identifier(node) {
        if (node.name === 'foo') {
          context.report({ node, messageId: 'avoidFoo' });
        }
      }
    };
  }
};

// Instantiate ESLintTester (note: actual usage would involve an ESLint config)
// This is a simplified example based on internal testing patterns.
// In a real scenario, you'd pass a configured ESLint instance or path to rules.
// As this package is deprecated, detailed external API examples are scarce.
const tester = new ESLintTester();

// An example of a valid test case (no errors expected)
const validCase = {
  code: 'const bar = 1;',
  parserOptions: { ecmaVersion: 6 }
};

// An example of an invalid test case (errors expected)
const invalidCase = {
  code: 'const foo = 2;',
  parserOptions: { ecmaVersion: 6 },
  errors: [{ messageId: 'avoidFoo', line: 1, column: 7 }]
};

// Run a test (this API is inferred and might not match direct public usage perfectly for older versions)
// The actual `eslint-tester` API is complex and meant for internal ESLint use.
// For modern rule testing, use `RuleTester` directly from `eslint`.
console.log('Running tests...');
// This part of the quickstart is conceptual as eslint-tester's public API for rule testing is not straightforward.
// Its primary use was internal to ESLint development.
// For actual rule testing, one would register rules and then run tests, similar to RuleTester.
// const results = tester.run('my-custom-rule', myCustomRule, { valid: [validCase], invalid: [invalidCase] });
// console.log(results);
console.log('`eslint-tester` is deprecated. Use `RuleTester` from `eslint` for modern rule testing.');
console.log('A complete runnable example for `eslint-tester` is difficult due to its internal-focused API and deprecation.');

view raw JSON →