Skip to content

About

ESlint plugin to enforces the usage of specific return types.

Resources

Security policy

Stars

17 stars

Watchers

2 watching

Forks

Repository files navigation

eslint-plugin-return-type

ESLint plugin to enforce the access of specific return types.

Requirements

This plugin has no runtime dependencies.

Installation

npm install --save-dev eslint-plugin-return-type
# or
pnpm add --save-dev eslint-plugin-return-type

Supported Rules

  • enforce-access
    • typeNames: string[]
      • Type names whose values must be accessed. Each entry is a regular expression that must match the whole type name.

Usage

Flat config (eslint.config.js)

import tsParser from "@typescript-eslint/parser";
import returnType from "eslint-plugin-return-type";

export default [
  {
    files: ["**/*.ts", "**/*.tsx"],
    languageOptions: {
      parser: tsParser,
      parserOptions: {
        projectService: true,
        tsconfigRootDir: import.meta.dirname,
      },
    },
    plugins: {
      "return-type": returnType,
    },
    rules: {
      "return-type/enforce-access": ["error", { typeNames: ["SomeType", "\\w*Error"] }],
    },
  },
];

Legacy config (.eslintrc)

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "./tsconfig.json"
  },
  "plugins": ["return-type"],
  "rules": {
    "return-type/enforce-access": ["error", { "typeNames": ["SomeType", "\\w*Error"] }]
  }
}

Development

Requires pnpm (see packageManager in package.json). pnpm installs the Node.js version in devEngines.runtime and runs the scripts with it. Use pnpm instead of npm in this repository.

pnpm install
pnpm test       # Vitest
pnpm build      # Compile to dist/
pnpm fmt        # Format with oxfmt
pnpm fmt:check

Release

The Publish workflow publishes to npm with pnpm publish --provenance and trusted publishing.

  • It runs on the 15th of every month (patch release), or manually from the Actions tab with patch, minor, or major.
  • The job runs in the npm environment and waits for approval before publishing.
  • It bumps the version, publishes the package, pushes the version commit and tag, and creates a GitHub release.

License

MIT

About

ESlint plugin to enforces the usage of specific return types.

Resources

Security policy

Stars

17 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages