Skip to content

Enhancement: member-ordering default configuration #5452

Closed
@nbouvrette

Description

@nbouvrette

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/member-ordering

Description

Based on my experimentations and also on the documentation, to apply the "default configuration" you have to copy/paste this list: https://typescript-eslint.io/rules/member-ordering/#default-configuration which contains 88 lines.

Adding this in the ESLint config will make it less maintainable and having an option to omit this list and use the default would be preferable.

One idea would be to add a new option called memberTypesPreset where you could pick default - or maybe even its default value would be default and you don't have to specify it.

Or another idea would be that if memberTypes: [] (empty array) or, if memberTypes is simply omitted, the default configuration is applied.

Fail

---
# eslintrc.yaml
root: true # Disables inheritance from parent config.
overrides:
  # TypeScript configurations
  - files:
      - '*.ts'
      - '*.mts'
      - '*.cts'
      - '*.tsx'
    parser: '@typescript-eslint/parser'
    parserOptions:
      project:
        - 'tsconfig.json'
    extends:
      - plugin:@typescript-eslint/recommended
      - plugin:@typescript-eslint/recommended-requiring-type-checking
    rules:
      # Checks members (classes, interfaces, types) and applies consistent ordering.
      # @see https://typescript-eslint.io/rules/member-ordering/
      '@typescript-eslint/member-ordering':
        - error
        - default:
            memberTypesPreset: default
            order: alphabetically-case-insensitive

Pass

---
# eslintrc.yaml
root: true # Disables inheritance from parent config.
overrides:
  # TypeScript configurations
  - files:
      - '*.ts'
      - '*.mts'
      - '*.cts'
      - '*.tsx'
    parser: '@typescript-eslint/parser'
    parserOptions:
      project:
        - 'tsconfig.json'
    extends:
      - plugin:@typescript-eslint/recommended
      - plugin:@typescript-eslint/recommended-requiring-type-checking
    rules:
      # Checks members (classes, interfaces, types) and applies consistent ordering.
      # @see https://typescript-eslint.io/rules/member-ordering/
      '@typescript-eslint/member-ordering':
        - error
        - default:
            memberTypes:
              - signature
              - public-static-field
              - protected-static-field
              - private-static-field
              - public-decorated-field
              - protected-decorated-field
              - private-decorated-field
              - public-instance-field
              - protected-instance-field
              - private-instance-field
              - public-abstract-field
              - protected-abstract-field
              - private-abstract-field
              - public-field
              - protected-field
              - private-field
              - static-field
              - instance-field
              - abstract-field
              - decorated-field
              - field
              - static-initialization
              - public-constructor
              - protected-constructor
              - private-constructor
              - constructor
              - public-static-get
              - protected-static-get
              - private-static-get
              - public-decorated-get
              - protected-decorated-get
              - private-decorated-get
              - public-instance-get
              - protected-instance-get
              - private-instance-get
              - public-abstract-get
              - protected-abstract-get
              - private-abstract-get
              - public-get
              - protected-get
              - private-get
              - static-get
              - instance-get
              - abstract-get
              - decorated-get
              - get
              - public-static-set
              - protected-static-set
              - private-static-set
              - public-decorated-set
              - protected-decorated-set
              - private-decorated-set
              - public-instance-set
              - protected-instance-set
              - private-instance-set
              - public-abstract-set
              - protected-abstract-set
              - private-abstract-set
              - public-set
              - protected-set
              - private-set
              - static-set
              - instance-set
              - abstract-set
              - decorated-set
              - set
              - public-static-method
              - protected-static-method
              - private-static-method
              - public-decorated-method
              - protected-decorated-method
              - private-decorated-method
              - public-instance-method
              - protected-instance-method
              - private-instance-method
              - public-abstract-method
              - protected-abstract-method
              - private-abstract-method
              - public-method
              - protected-method
              - private-method
              - static-method
              - instance-method
              - abstract-method
              - decorated-method
              - method
            order: alphabetically-case-insensitive

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulegood first issueGood for newcomerspackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions