{"id":10822,"library":"eslint-etc","title":"ESLint TypeScript Rule Utilities","description":"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.","status":"active","version":"5.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/cartant/eslint-etc","tags":["javascript","eslint","typescript"],"install":[{"cmd":"npm install eslint-etc","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-etc","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-etc","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for core ESLint functionality and API compatibility.","package":"eslint","optional":false},{"reason":"Peer dependency, essential for processing TypeScript ASTs within ESLint rules.","package":"typescript","optional":false}],"imports":[{"note":"Primary utility for fixture-based ESLint rule testing, widely used in test files. ESM is generally preferred for modern JavaScript development.","wrong":"const { fromFixture } = require('eslint-etc')","symbol":"fromFixture","correct":"import { fromFixture } from 'eslint-etc'"},{"note":"Crucial for type-aware ESLint rules, providing access to the TypeScript program and type checker from the `@typescript-eslint/parser`.","wrong":"const { getParserServices } = require('eslint-etc')","symbol":"getParserServices","correct":"import { getParserServices } from 'eslint-etc'"},{"note":"A type guard function useful for narrowing `AST_NODE_TYPES` in TypeScript-based ESLint rule implementations.","wrong":"const { isIdentifier } = require('eslint-etc')","symbol":"isIdentifier","correct":"import { isIdentifier } from 'eslint-etc'"}],"quickstart":{"code":"import { RuleTester } from '@typescript-eslint/rule-tester';\nimport { fromFixture } from 'eslint-etc';\nimport { stripIndent } from 'common-tags'; // Often used for multiline strings in tests\n\n// Define a simple mock ESLint rule\nconst noConstRule = {\n  meta: {\n    type: 'suggestion',\n    messages: {\n      noConst: 'Do not use `const` for variable declarations.',\n    },\n    schema: [],\n  },\n  create(context) {\n    return {\n      VariableDeclaration(node) {\n        if (node.kind === 'const') {\n          context.report({\n            node,\n            messageId: 'noConst',\n          });\n        }\n      },\n    };\n  },\n};\n\nconst ruleTester = new RuleTester({\n  parser: '@typescript-eslint/parser',\n  parserOptions: {\n    ecmaVersion: 2020,\n    sourceType: 'module',\n    // Ensure tsconfig.json is properly configured for type-aware rules\n    project: './tsconfig.json',\n  },\n});\n\nruleTester.run('no-const-rule', noConstRule as any, {\n  valid: [\n    { code: 'let name = \"alice\";' },\n    { code: 'var age = 30;' },\n  ],\n  invalid: [\n    fromFixture(stripIndent`\n      const name = \"alice\";\n      ~~~~~                   [noConst]\n    `),\n    fromFixture(stripIndent`\n      const role = 'cto';\n      ~~~~~                   [noConst]\n      let value = 10;\n    `),\n    fromFixture(stripIndent`\n      const x = 1;\n      ~~~~~        [noConst]\n      const y = 2;\n      ~~~~~        [noConst]\n    `)\n  ],\n});","lang":"typescript","description":"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."},"warnings":[{"fix":"Always consult the package's changelog or release notes for specific migration guides when upgrading between major versions.","message":"Major 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.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"The documentation for `eslint-etc` is noted by its author as 'light', primarily serving the author's own use cases for implementing ESLint rules.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading 'program') (or similar for 'getTypeChecker')"},{"fix":"Add `import { fromFixture } from 'eslint-etc';` (or the relevant symbol) to the top of your test file to ensure the utility is available.","cause":"`fromFixture` (or another utility from `eslint-etc`) was used in a test file without being properly imported.","error":"ReferenceError: fromFixture is not defined (or similar for other exports)"}],"ecosystem":"npm"}