Skip to content
This repository has been archived by the owner on Feb 21, 2022. It is now read-only.

Latest commit

 

History

History
78 lines (65 loc) · 2.44 KB

sortImportsRule.md

File metadata and controls

78 lines (65 loc) · 2.44 KB

sort-imports (ESLint: sort-imports)

rule_source test_source

enforce sorting import declarations within module

Rationale

When declaring multiple imports, a sorted list of import declarations make it easier for developers to read the code and find necessary imports later. This rule is purely a matter of style.

This rule checks all import declarations and verifies that all imports are first sorted by the used member syntax and then alphabetically by the first member or alias name.

Config

  • "ignore-case" does case-insensitive comparisons (default: false)
  • "ignore-member-sort" allows members in multiple type imports to occur in any order (default: false)
  • "member-syntax-sort-order" (default: ["none", "all", "multiple", "single", "alias"]); all 5 items must be present in the array, but you can change the order:
    • none = import module without exported bindings.
    • all = import all members provided by exported bindings.
    • multiple = import multiple members.
    • single = import a single member.
    • alias = creates an alias for a member. This is unique to TER and not in ESLint's sort-imports.

Examples

"sort-imports": [true]
"sort-imports": [true, { "ignore-case" }]
"sort-imports": [true, { "ignore-member-sort" }]
"sort-imports": [true, { "member-syntax-sort-order": ["all", "single", "multiple", "none", "alias"] }]

Schema

{
  "type": "object",
  "properties": {
    "member-syntax-sort-order": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "none",
          "all",
          "multiple",
          "single",
          "alias"
        ]
      },
      "minLength": 5,
      "maxLength": 5
    },
    "ignore-case": {
      "type": "boolean"
    },
    "ignore-member-sort": {
      "type": "boolean"
    }
  }
}

TSLint Rule: ordered-imports