Skip to content

Latest commit

 

History

History
367 lines (307 loc) · 77.5 KB

README.md

File metadata and controls

367 lines (307 loc) · 77.5 KB

eslint-plugin-typefest

Latest npm version. Monthly npm downloads. Supported Node.js versions. Bundled TypeScript declarations. Package dependents. Codecov coverage. GitHub Actions checks on main. GitHub stars. NPM license.

ESLint plugin for teams that want consistent TypeScript-first conventions based on:

The plugin ships focused rule sets for modern flat config usage, with parser setup included in each preset config.

The all and experimental presets also cover newer upstream helpers. These rules resolve the library from the linted file and activate for type-fest 6 or ts-extras 2 and 3, as applicable. The upstream coverage guide lists each public export, its rule, or the reason for its exclusion.

Oxlint: Not compatible as a complete plugin (verified with Oxlint 1.80.0). Parser-agnostic rules can work, but rules that require TypeScript parser services cannot run under the JS-plugin bridge; Oxlint does not support type-aware JavaScript plugin rules. Use ESLint for the complete rule and preset surface.

Table of contents

  1. Installation
  2. Quick start (flat config)
  3. Presets
  4. Configuration examples by preset
  5. Global settings
  6. Rules
  7. Contributors ✨

Installation

npm install --save-dev eslint-plugin-typefest typescript

@typescript-eslint/parser is loaded automatically by plugin presets.

Compatibility

  • Supported ESLint versions: 9.x and 10.x
  • Config system: Flat Config only (eslint.config.*)
  • Node.js runtime: >=22.0.0

Quick start (flat config)

import typefest from "eslint-plugin-typefest";

export default [typefest.configs.recommended];

That is enough for TypeScript files (**/*.{ts,tsx,mts,cts}).

Presets

This plugin intentionally exports eight presets:

Preset
🟢 typefest.configs.minimal
🟡 typefest.configs.recommended
🟠 typefest.configs["recommended-type-checked"]
🔴 typefest.configs.strict
🟣 typefest.configs.all
🧪 typefest.configs.experimental
💠 typefest.configs["type-fest/types"]
✴️ typefest.configs["ts-extras/type-guards"]

Configuration examples by preset

import typefest from "eslint-plugin-typefest";

export default [
 // Smallest baseline footprint.
 typefest.configs.minimal,

 // Balanced default for most teams.
 // typefest.configs.recommended,

 // Recommended plus type-aware ts-extras helper rules.
 // typefest.configs["recommended-type-checked"],

 // Recommended plus additional stable runtime utilities.
 // typefest.configs.strict,

 // Every stable rule.
 // typefest.configs.all,

 // Every stable rule plus experimental candidate rules.
 // typefest.configs.experimental,

 // Focused subsets:
 // typefest.configs["type-fest/types"],
 // typefest.configs["ts-extras/type-guards"],
];

Parser setup behavior

Each preset already includes:

  • files: ["**/*.{ts,tsx,mts,cts}"]
  • languageOptions.parser (@typescript-eslint/parser)
  • languageOptions.parserOptions:
    • ecmaVersion: "latest"
    • projectService: true (for presets that include typed rules, such as recommended-type-checked, strict, all, and experimental)
    • sourceType: "module"

End users usually do not need to wire parser config manually.

If you need custom parser options (for example tsconfigRootDir), extend a preset:

import typefest from "eslint-plugin-typefest";

const recommended = typefest.configs.recommended;

export default [
 {
  ...recommended,
  languageOptions: {
   ...recommended.languageOptions,
   parserOptions: {
    ...recommended.languageOptions?.parserOptions,
    // Add projectService only when you opt into a type-aware preset.
   },
  },
 },
];

Global settings

You can globally disable autofixes that add missing imports while still keeping rule reports and non-import autofixes enabled.

import typefest from "eslint-plugin-typefest";

export default [
 {
  ...typefest.configs.recommended,
  settings: {
   typefest: {
    // Disable all autofixes while keeping suggestions enabled.
    // disableAllAutofixes: true,

    // Disable only autofixes that add missing imports.
    disableImportInsertionFixes: true,
   },
  },
 },
];

When settings.typefest.disableImportInsertionFixes is true, rules that would normally add a missing type-fest or ts-extras import will report without applying that import-adding autofix. Autofixes that do not require inserting a new import (for example, when the replacement symbol is already in scope) still apply.

When settings.typefest.disableAllAutofixes is true, all rule autofixes are suppressed, but reports and suggestions remain available.

If both settings are enabled, disableAllAutofixes takes precedence for autofix behavior.

Rules

Rule Fix Preset key
prefer-ts-extras-array-at 🔧 🔴 🟣
prefer-ts-extras-array-concat 🔧 🔴 🟣
prefer-ts-extras-array-first 🔧 💡 🔴 🟣
prefer-ts-extras-array-includes 🔧 💡 🟠 🔴 🟣 ✴️
prefer-ts-extras-array-index-of — 🟣 🧪
prefer-ts-extras-array-is-array — 🟣 🧪
prefer-ts-extras-array-join 🔧 🔴 🟣
prefer-ts-extras-array-last 🔧 💡 🟠 🔴 🟣
prefer-ts-extras-array-last-index-of — 🟣 🧪
prefer-ts-extras-as-writable 🔧 🔴 🟣
prefer-ts-extras-assert 💡 🔴 🟣 ✴️
prefer-ts-extras-assert-defined 🔧 💡 🟡 🔴 🟣 ✴️
prefer-ts-extras-assert-error 💡 🟡 🔴 🟣 ✴️
prefer-ts-extras-assert-never 💡 🟡 🔴 🟣 ✴️
prefer-ts-extras-assert-present 🔧 💡 🟡 🔴 🟣 ✴️
prefer-ts-extras-has-at-least — 🟣 🧪
prefer-ts-extras-is-defined 🔧 🟡 🔴 🟣 ✴️
prefer-ts-extras-is-defined-filter 🔧 🟢 🟡 🔴 🟣 ✴️
prefer-ts-extras-is-empty 🔧 🟠 🔴 🟣 ✴️
prefer-ts-extras-is-equal-type 💡 🟣
prefer-ts-extras-is-finite 🔧 🟡 🔴 🟣 ✴️
prefer-ts-extras-is-infinite 🔧 🟡 🔴 🟣 ✴️
prefer-ts-extras-is-integer 🔧 🟡 🔴 🟣 ✴️
prefer-ts-extras-is-non-empty — 🟣 🧪
prefer-ts-extras-is-present 🔧 🟡 🔴 🟣 ✴️
prefer-ts-extras-is-present-filter 🔧 🟢 🟡 🔴 🟣 ✴️
prefer-ts-extras-is-property-defined 💡 🟢 🟡 🔴 🟣 ✴️
prefer-ts-extras-is-property-present 💡 🟢 🟡 🔴 🟣 ✴️
prefer-ts-extras-is-safe-integer 🔧 🟡 🔴 🟣 ✴️
prefer-ts-extras-is-truthy — 🟣 🧪
prefer-ts-extras-key-in 🔧 💡 🟡 🔴 🟣 ✴️
prefer-ts-extras-map-has — 🟣 🧪
prefer-ts-extras-not 🔧 🟡 🔴 🟣 ✴️
prefer-ts-extras-object-assign 🔧 🔴 🟣
prefer-ts-extras-object-entries 🔧 🔴 🟣
prefer-ts-extras-object-from-entries 🔧 🔴 🟣
prefer-ts-extras-object-has-in 🔧 💡 🟡 🔴 🟣 ✴️
prefer-ts-extras-object-has-own 🔧 💡 🟡 🔴 🟣 ✴️
prefer-ts-extras-object-keys 🔧 🔴 🟣
prefer-ts-extras-object-map-values — 🧪
prefer-ts-extras-object-values 🔧 🔴 🟣
prefer-ts-extras-safe-cast-to 🔧 🟠 🔴 🟣 ✴️
prefer-ts-extras-set-has 🔧 💡 🟠 🔴 🟣 ✴️
prefer-ts-extras-string-ends-with — 🟣 🧪
prefer-ts-extras-string-split 🔧 🔴 🟣
prefer-ts-extras-string-starts-with — 🟣 🧪
prefer-type-fest-absolute 🔧 🟡 🔴 🟣 💠
prefer-type-fest-abstract-constructor 🔧 🟡 🔴 🟣 💠
prefer-type-fest-and 🔧 🟡 🔴 🟣 💠
prefer-type-fest-and-all 🔧 🟡 🔴 🟣 💠
prefer-type-fest-array-element 🔧 🟠 🔴 🟣
prefer-type-fest-array-length 🔧 🟠 🔴 🟣
prefer-type-fest-array-values 🔧 🟠 🔴 🟣
prefer-type-fest-arrayable 🔧 🟢 🟡 🔴 🟣 💠
prefer-type-fest-async-return-type 🔧 🟡 🔴 🟣 💠
prefer-type-fest-asyncify — 🧪
prefer-type-fest-conditional-except — 🧪
prefer-type-fest-conditional-keys — 🧪
prefer-type-fest-conditional-pick 🔧 🟡 🔴 🟣 💠
prefer-type-fest-conditional-pick-deep 🔧 🟡 🔴 🟣 💠
prefer-type-fest-constructor 🔧 🟡 🔴 🟣 💠
prefer-type-fest-distributed-omit — 🧪
prefer-type-fest-distributed-pick — 🧪
prefer-type-fest-empty-array — 🟣 🧪
prefer-type-fest-entries 🔧 🟡 🔴 🟣 💠
prefer-type-fest-entry 🔧 🟡 🔴 🟣 💠
prefer-type-fest-except 🔧 🟢 🟡 🔴 🟣 💠
prefer-type-fest-extract-rest-element 🔧 🟡 🔴 🟣 💠
prefer-type-fest-falsy 🔧 🟣 🧪
prefer-type-fest-function 🔧 🟣 🧪
prefer-type-fest-guarded-type 🔧 🟣 🧪
prefer-type-fest-has-optional-keys 🔧 🟡 🔴 🟣 💠
prefer-type-fest-has-readonly-keys 🔧 🟡 🔴 🟣 💠
prefer-type-fest-has-required-keys 🔧 🟡 🔴 🟣 💠
prefer-type-fest-has-writable-keys 🔧 🟡 🔴 🟣 💠
prefer-type-fest-if 🔧 🟡 🔴 🟣 💠
prefer-type-fest-is-any 🔧 🟡 🔴 🟣 💠
prefer-type-fest-is-mutually-assignable 🔧 🟣 🧪
prefer-type-fest-is-never 🔧 🟡 🔴 🟣 💠
prefer-type-fest-is-null 🔧 🟡 🔴 🟣 💠
prefer-type-fest-is-nullable 🔧 🟡 🔴 🟣 💠
prefer-type-fest-is-tuple 🔧 🟡 🔴 🟣 💠
prefer-type-fest-is-undefined 🔧 🟡 🔴 🟣 💠
prefer-type-fest-is-unknown 🔧 🟡 🔴 🟣 💠
prefer-type-fest-iterable-element 🔧 🟡 🔴 🟣 💠
prefer-type-fest-json-array 🔧 🟢 🟡 🔴 🟣 💠
prefer-type-fest-json-object 🔧 🟢 🟡 🔴 🟣 💠
prefer-type-fest-json-primitive 🔧 🟢 🟡 🔴 🟣 💠
prefer-type-fest-json-value 💡 🟢 🟡 🔴 🟣 💠
prefer-type-fest-keys-of-union 🔧 🟡 🔴 🟣 💠
prefer-type-fest-less-than 🔧 🟡 🔴 🟣 💠
prefer-type-fest-less-than-or-equal 🔧 🟡 🔴 🟣 💠
prefer-type-fest-literal-union 🔧 🟡 🔴 🟣 💠
prefer-type-fest-merge — 🧪
prefer-type-fest-merge-exclusive 🔧 🟡 🔴 🟣 💠
prefer-type-fest-minimum-length-array 🔧 🟣 🧪
prefer-type-fest-non-empty-tuple 🔧 🟡 🔴 🟣 💠
prefer-type-fest-non-nullable-deep 🔧 🟡 🔴 🟣 💠
prefer-type-fest-not 🔧 🟣 🧪
prefer-type-fest-omit-index-signature 🔧 🟡 🔴 🟣 💠
prefer-type-fest-optional 🔧 🟡 🔴 🟣 💠
prefer-type-fest-optional-keys-of 🔧 🟡 🔴 🟣 💠
prefer-type-fest-or 🔧 🟡 🔴 🟣 💠
prefer-type-fest-or-all 🔧 🟡 🔴 🟣 💠
prefer-type-fest-overload-parameters 🔧 🟣 🧪
prefer-type-fest-overload-return-type 🔧 🟣 🧪
prefer-type-fest-partial-deep 🔧 🟡 🔴 🟣 💠
prefer-type-fest-pick-index-signature — 🧪
prefer-type-fest-primitive 🔧 🟢 🟡 🔴 🟣 💠
prefer-type-fest-promisable 🔧 🟢 🟡 🔴 🟣 💠
prefer-type-fest-readonly-date 🔧 🟣 🧪
prefer-type-fest-readonly-deep 🔧 🟡 🔴 🟣 💠
prefer-type-fest-readonly-keys-of 🔧 🟡 🔴 🟣 💠
prefer-type-fest-require-all-or-none 🔧 🟡 🔴 🟣 💠
prefer-type-fest-require-at-least-one 🔧 🟡 🔴 🟣 💠
prefer-type-fest-require-exactly-one 🔧 🟡 🔴 🟣 💠
prefer-type-fest-require-none — 🟣 🧪
prefer-type-fest-require-one-or-none 🔧 🟡 🔴 🟣 💠
prefer-type-fest-required-deep 🔧 🟡 🔴 🟣 💠
prefer-type-fest-required-keys-of 🔧 🟡 🔴 🟣 💠
prefer-type-fest-required-non-nullable — 🟣 🧪
prefer-type-fest-schema 🔧 🟡 🔴 🟣 💠
prefer-type-fest-set-non-nullable 🔧 🟡 🔴 🟣 💠
prefer-type-fest-set-optional 🔧 🟡 🔴 🟣 💠
prefer-type-fest-set-readonly 🔧 🟡 🔴 🟣 💠
prefer-type-fest-set-required 🔧 🟡 🔴 🟣 💠
prefer-type-fest-set-return-type — 🧪
prefer-type-fest-simplify 🔧 🟡 🔴 🟣 💠
prefer-type-fest-string-length 🔧 🟡 🔴 🟣 💠
prefer-type-fest-stringified — 🧪
prefer-type-fest-subset-of 🔧 🟣 🧪
prefer-type-fest-tagged-brands 🔧 🟡 🔴 🟣 💠
prefer-type-fest-thunkable — 🟣 🧪
prefer-type-fest-truthy 🔧 🟣 🧪
prefer-type-fest-tuple-of 🔧 🟡 🔴 🟣 💠
prefer-type-fest-union-length 🔧 🟡 🔴 🟣 💠
prefer-type-fest-union-member 🔧 🟡 🔴 🟣 💠
prefer-type-fest-union-to-intersection — 🧪
prefer-type-fest-union-to-tuple 🔧 🟡 🔴 🟣 💠
prefer-type-fest-unknown-array 🔧 🟡 🔴 🟣 💠
prefer-type-fest-unknown-map 🔧 🟡 🔴 🟣 💠
prefer-type-fest-unknown-record 🔧 🟢 🟡 🔴 🟣 💠
prefer-type-fest-unknown-set 🔧 🟡 🔴 🟣 💠
prefer-type-fest-unwrap-tagged 🔧 🟡 🔴 🟣 💠
prefer-type-fest-value-of 🔧 🟡 🔴 🟣 💠
prefer-type-fest-writable 🔧 🟡 🔴 🟣 💠
prefer-type-fest-writable-deep 🔧 🟡 🔴 🟣 💠
prefer-type-fest-writable-keys-of 🔧 🟡 🔴 🟣 💠

Contributors ✨

All Contributors.

Thanks goes to these wonderful people (emoji key):

Nick2bad4u
Nick2bad4u

🐛 💻 📖 🤔 🚇 🚧 👀 ⚠️ 🔧
Snyk bot
Snyk bot

🛡️ 🚇 🚧 👀
StepSecurity Bot
StepSecurity Bot

🛡️ 🚇 🚧
dependabot[bot]
dependabot[bot]

🚇 🛡️
github-actions[bot]
github-actions[bot]

💻 🚇