Registry / testing / eslint-etc

eslint-etc

JSON →
library5.2.1jsnpmunverified

eslint-etc provides a collection of utility functions designed primarily to aid in the implementation and testing of custom ESLint rules, particularly those targeting TypeScript codebases. The current stable version is 5.2.1. While there isn't a stated release cadence, updates are typically made as needed for new features, bug fixes, or compatibility with newer ESLint and TypeScript versions. A key differentiator is the `fromFixture` utility, which enables a TSLint-like fixture testing approach for ESLint rules. This simplifies the creation of test cases by allowing developers to directly annotate expected error locations and messages within multiline code strings, abstracting away the need for explicit line and column numbers. This library is largely used by its author for their own suite of ESLint rules, indicating a practical, developer-focused design, though documentation can be light for external users.

npm install eslint-etc
INSTALL
IMPORT
SIG · ESLINT-ETC
E
eslint-etc
testingjavascriptv5.2.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fromFixture
import { fromFixture } from 'eslint-etc'
const { fromFixture } = require('eslint-etc')
Primary utility for fixture-based ESLint rule testing, widely used in test files. ESM is generally preferred for modern JavaScript development.
getParserServices
import { getParserServices } from 'eslint-etc'
const { getParserServices } = require('eslint-etc')
Crucial for type-aware ESLint rules, providing access to the TypeScript program and type checker from the `@typescript-eslint/parser`.
isIdentifier
import { isIdentifier } from 'eslint-etc'
const { isIdentifier } = require('eslint-etc')
A type guard function useful for narrowing `AST_NODE_TYPES` in TypeScript-based ESLint rule implementations.

This quickstart demonstrates how to use `fromFixture` with `@typescript-eslint/rule-tester` to simplify the testing of a custom ESLint rule that disallows `const` declarations. It shows how to define a rule and then write test cases using annotated code snippets instead of explicit line and column numbers.

import { RuleTester } from '@typescript-eslint/rule-tester'; import { fromFixture } from 'eslint-etc'; import { stripIndent } from 'common-tags'; // Often used for multiline strings in tests // Define a simple mock ESLint rule const noConstRule = { meta: { type: 'suggestion', messages: { noConst: 'Do not use `const` for variable declarations.', }, schema: [], }, create(context) { return { VariableDeclaration(node) { if (node.kind === 'const') { context.report({ node, messageId: 'noConst', }); } }, }; }, }; const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', parserOptions: { ecmaVersion: 2020, sourceType: 'module', // Ensure tsconfig.json is properly configured for type-aware rules project: './tsconfig.json', }, }); ruleTester.run('no-const-rule', noConstRule as any, { valid: [ { code: 'let name = "alice";' }, { code: 'var age = 30;' }, ], invalid: [ fromFixture(stripIndent` const name = "alice"; ~~~~~ [noConst] `), fromFixture(stripIndent` const role = 'cto'; ~~~~~ [noConst] let value = 10; `), fromFixture(stripIndent` const x = 1; ~~~~~ [noConst] const y = 2; ~~~~~ [noConst] `) ], });
Debug
Known issues
breakingMajor version increments (e.g., v3.0.0, v4.0.0, v5.0.0) in `eslint-etc` often introduce breaking changes due to updates in peer dependencies like ESLint or TypeScript, or internal API refactors.
fix
Always consult the package's changelog or release notes for specific migration guides when upgrading between major versions.
affects: >=1.0.0
gotchaThe documentation for `eslint-etc` is noted by its author as 'light', primarily serving the author's own use cases for implementing ESLint rules.
fix
For advanced usage or unclear scenarios, it's often necessary to review the package's source code or examine how the author uses these utilities in their own ESLint rule projects.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'program') (or similar for 'getTypeChecker')
An ESLint rule is attempting to access TypeScript parser services (e.g., `parserServices.program` or `parserServices.getTypeChecker`) but `@typescript-eslint/parser` is not correctly configured, or the file being linted is not recognized as a TypeScript file.
fix
Ensure your ESLint configuration includes `parser: '@typescript-eslint/parser'` and, for type-aware rules, `parserOptions.project` is correctly set to point to your `tsconfig.json` file.
ReferenceError: fromFixture is not defined (or similar for other exports)
`fromFixture` (or another utility from `eslint-etc`) was used in a test file without being properly imported.
fix
Add `import { fromFixture } from 'eslint-etc';` (or the relevant symbol) to the top of your test file to ensure the utility is available.
Upgrade
Version history
5.2.1latest on npm
Audit
Dependencies
eslintrequiredPeer dependency for core ESLint functionality and API compatibility.
typescriptrequiredPeer dependency, essential for processing TypeScript ASTs within ESLint rules.
Agent activity
2 hits · last 30 days
node
2
Resources
eslint-etc — npm install eslint-etc · libregistry