azat-io / eslint-plugin-perfectionist

🦄 ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
https://eslint-plugin-perfectionist.azat.io
MIT License
1.62k stars 28 forks source link

Feature: Support computed properties for sort-objects and sort-object-keys #132

Closed jaketodaro closed 3 weeks ago

jaketodaro commented 3 weeks ago

What rule do you want to change?

sort-objects/sort-object-keys

Describe the problem

Would it be possible to support sorting computed properties in objects and types?

Code example

enum SomeEnum {
    foo = 'foo',
    bar = 'bar'
}

const myMap: Record<SomeEnum, string> = {
    // sort these keys?
    [SomeEnum.foo]: 'foo thing',
    [SomeEnum.bar]: 'bar thing'
}

Additional comments

No response

Validations

azat-io commented 3 weeks ago
image

Can you tell me what your problem is? We currently have a rule that sorts objects by key.

Or are you proposing to sort by value? This is not currently implemented and is not planned.

jaketodaro commented 3 weeks ago

My mistake. After an eslint upgrade this works as expected for me. Previously I was getting an error running eslint withsort-object-types turned on and I assumed that the error was due to the fact that I was using computed properties for keys, but that doesn't seem to be the case.