Skip to content

Commit

Permalink
fix: disable sorting enums with implicit values
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Jul 28, 2023
1 parent dbfd97b commit f4a0e25
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 110 deletions.
2 changes: 1 addition & 1 deletion rules/sort-enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default createEslintRule<Options, MESSAGE_ID>({
TSEnumDeclaration: node => {
if (
node.members.length > 1 &&
node.members.some(({ initializer }) => initializer)
node.members.every(({ initializer }) => initializer)
) {
let options = complete(context.options.at(0), {
type: SortType.alphabetical,
Expand Down
115 changes: 6 additions & 109 deletions test/sort-enums.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe(RULE_NAME, () => {
})
})

it(`${RULE_NAME}(${type}): sorts enum members without initializer`, () => {
it(`${RULE_NAME}(${type}): doesn't sorts enum members without initializer`, () => {
ruleTester.run(RULE_NAME, rule, {
valid: [
{
Expand All @@ -148,39 +148,7 @@ describe(RULE_NAME, () => {
],
},
],
invalid: [
{
code: dedent`
enum TokyoGodfathers {
Gin,
Miyuki,
Hana = 'Hana',
}
`,
output: dedent`
enum TokyoGodfathers {
Gin,
Hana = 'Hana',
Miyuki,
}
`,
options: [
{
type: SortType.alphabetical,
order: SortOrder.asc,
},
],
errors: [
{
messageId: 'unexpectedEnumsOrder',
data: {
left: 'Miyuki',
right: 'Hana',
},
},
],
},
],
invalid: [],
})
})

Expand Down Expand Up @@ -429,7 +397,7 @@ describe(RULE_NAME, () => {
})
})

it(`${RULE_NAME}(${type}): sorts enum members without initializer`, () => {
it(`${RULE_NAME}(${type}): doesn't sorts enum members without initializer`, () => {
ruleTester.run(RULE_NAME, rule, {
valid: [
{
Expand All @@ -448,39 +416,7 @@ describe(RULE_NAME, () => {
],
},
],
invalid: [
{
code: dedent`
enum TokyoGodfathers {
Gin,
Miyuki,
Hana = 'Hana',
}
`,
output: dedent`
enum TokyoGodfathers {
Gin,
Hana = 'Hana',
Miyuki,
}
`,
options: [
{
type: SortType.natural,
order: SortOrder.asc,
},
],
errors: [
{
messageId: 'unexpectedEnumsOrder',
data: {
left: 'Miyuki',
right: 'Hana',
},
},
],
},
],
invalid: [],
})
})

Expand Down Expand Up @@ -736,7 +672,7 @@ describe(RULE_NAME, () => {
})
})

it(`${RULE_NAME}(${type}): sorts enum members without initializer`, () => {
it(`${RULE_NAME}(${type}): doesn't sorts enum members without initializer`, () => {
ruleTester.run(RULE_NAME, rule, {
valid: [
{
Expand All @@ -755,46 +691,7 @@ describe(RULE_NAME, () => {
],
},
],
invalid: [
{
code: dedent`
enum TokyoGodfathers {
Gin,
Miyuki,
Hana = 'Hana',
}
`,
output: dedent`
enum TokyoGodfathers {
Hana = 'Hana',
Miyuki,
Gin,
}
`,
options: [
{
type: SortType['line-length'],
order: SortOrder.desc,
},
],
errors: [
{
messageId: 'unexpectedEnumsOrder',
data: {
left: 'Gin',
right: 'Miyuki',
},
},
{
messageId: 'unexpectedEnumsOrder',
data: {
left: 'Miyuki',
right: 'Hana',
},
},
],
},
],
invalid: [],
})
})

Expand Down

0 comments on commit f4a0e25

Please sign in to comment.