Skip to content

zachbryant/eslint-plugin-typescript-sort-keys

 
 

Repository files navigation

Tests

eslint-plugin-typescript-sort-keys

Sort interface and enum keys. Inspired by and sourced from eslint/sort-keys

Installation

This plugin is supported on Node 18+. You'll first need to install:

yarn add -D eslint typescript @typescript-eslint/parser

Next, install eslint-plugin-typescript-sort-keys:

yarn add -D eslint-plugin-typescript-sort-keys

Note: If you installed ESLint globally then you must also install eslint-plugin-typescript-sort-keys globally.

Usage

Specify the parser for typescript files in your .eslintrc configuration file:

{
  "parser": "@typescript-eslint/parser"
}

Add typescript-sort-keys to the plugins section. You can omit the eslint-plugin- prefix:

{
  "plugins": ["typescript-sort-keys"]
}

Then configure the rules you want to use under the rules section.

{
  "rules": {
    "typescript-sort-keys/interface": "error",
    "typescript-sort-keys/enum": "error"
  }
}

Or alternatively to the individual rules, enable all rules with defaults:

{
  "extends": ["plugin:typescript-sort-keys/recommended"]
}

If you'd like to enable the recommended config with interface required keys first:

{
  "extends": ["plugin:typescript-sort-keys/requiredFirst"]
}

Supported Rules

Key: ✔️ = recommended, 🔧 = fixable, ⚠️ = deprecated

Name Description
typescript-sort-keys/interface require interface keys to be sorted ✔️ 🔧
typescript-sort-keys/enum require enum members to be sorted ✔️ 🔧
typescript-sort-keys/string-enum (DEPRECATED) require string enum members to be sorted ⚠️ 🔧

About

A linter plugin to require sorting interface and string enum keys

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 96.5%
  • JavaScript 3.4%
  • Shell 0.1%