Skip to content

Commit

Permalink
feat: improve group order error messages in sort-classes
Browse files Browse the repository at this point in the history
  • Loading branch information
hugop95 committed Aug 14, 2024
1 parent 105f096 commit b02d626
Show file tree
Hide file tree
Showing 2 changed files with 234 additions and 76 deletions.
11 changes: 9 additions & 2 deletions rules/sort-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { complete } from '../utils/complete'
import { pairwise } from '../utils/pairwise'
import { compare } from '../utils/compare'

type MESSAGE_ID = 'unexpectedClassesOrder'
type MESSAGE_ID = 'unexpectedClassesGroupOrder' | 'unexpectedClassesOrder'

type ProtectedModifier = 'protected'
type PrivateModifier = 'private'
Expand Down Expand Up @@ -207,6 +207,8 @@ export default createEslintRule<Options, MESSAGE_ID>({
},
],
messages: {
unexpectedClassesGroupOrder:
'Expected "{{right}}" ({{rightGroup}}) to come before "{{left}}" ({{leftGroup}}).',
unexpectedClassesOrder: 'Expected "{{right}}" to come before "{{left}}".',
},
},
Expand Down Expand Up @@ -512,10 +514,15 @@ export default createEslintRule<Options, MESSAGE_ID>({
isPositive(compare(left, right, options))))
) {
context.report({
messageId: 'unexpectedClassesOrder',
messageId:
leftNum !== rightNum
? 'unexpectedClassesGroupOrder'
: 'unexpectedClassesOrder',
data: {
left: toSingleLine(left.name),
leftGroup: left.group,
right: toSingleLine(right.name),
rightGroup: right.group,
},
node: right.node,
fix: (fixer: TSESLint.RuleFixer) => {
Expand Down
Loading

0 comments on commit b02d626

Please sign in to comment.