Skip to content

Commit 7ddd014

Browse files
committed
fix(eslint/jsx-sort-props): correct sort for reservedProps
1 parent a691149 commit 7ddd014

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

docs/introduction/eslint.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const After = <App v-if={list} v-for={i in list} a b />
7171

7272
### `reservedLast`
7373

74-
Defaults to `['v-text', 'v-html', 'v-slots', 'v-slot']`
74+
Defaults to `['v-slot', 'v-slots', 'v-text', 'v-html']`
7575

7676
This can be an array option. These props must be listed after all other props.
7777
These will respect the order specified in the array:

packages/eslint/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default ({ rules = {}, ...options }: Linter.Config<Rules> = {}) => ({
2929
'ref',
3030
'v-model',
3131
],
32-
reservedLast: ['v-text', 'v-html', 'v-slots', 'v-slot'],
32+
reservedLast: ['v-slot', 'v-slots', 'v-text', 'v-html'],
3333
},
3434
],
3535
'vue-jsx-vapor/define-style': rules['vue-jsx-vapor/define-style'] || 'warn',

packages/eslint/src/rules/jsx-sort-props/index.ts

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ function contextCompare(
143143
) {
144144
let aProp = getPropName(a)
145145
let bProp = getPropName(b)
146-
const aPropWithoutNamespace = aProp.split(':')[0]
147-
const bPropWithoutNamespace = bProp.split(':')[0]
146+
const aPropNamespace = aProp.split(':')[0]
147+
const bPropNamespace = bProp.split(':')[0]
148148

149149
const aSortToEnd = shouldSortToEnd(a)
150150
const bSortToEnd = shouldSortToEnd(b)
@@ -159,11 +159,7 @@ function contextCompare(
159159

160160
if (aIndex === -1 && bIndex > -1) return 1
161161

162-
if (
163-
aIndex > -1 &&
164-
bIndex > -1 &&
165-
aPropWithoutNamespace !== bPropWithoutNamespace
166-
)
162+
if (aIndex > -1 && bIndex > -1 && aPropNamespace !== bPropNamespace)
167163
return aIndex > bIndex ? 1 : -1
168164
}
169165

@@ -174,12 +170,8 @@ function contextCompare(
174170

175171
if (aLastIndex === -1 && bLastIndex > -1) return -1
176172

177-
if (
178-
aLastIndex > -1 &&
179-
bLastIndex > -1 &&
180-
aPropWithoutNamespace !== bPropWithoutNamespace
181-
)
182-
return aLastIndex > bLastIndex ? 1 : -1
173+
if (aLastIndex > -1 && bLastIndex > -1 && aPropNamespace !== bPropNamespace)
174+
return aLastIndex > bLastIndex ? -1 : 1
183175
}
184176

185177
if (options.callbacksLast) {
@@ -566,6 +558,8 @@ const rule: RuleModule<MessageIds, RuleOptions> = {
566558

567559
let previousPropName = getPropName(memo)
568560
let currentPropName = getPropName(decl)
561+
const previousReservedNamespace = previousPropName.split(':')[0]
562+
const currentReservedNamespace = currentPropName.split(':')[0]
569563
const previousValue = (memo as Tree.JSXAttribute).value
570564
const currentValue = decl.value
571565
const previousIsCallback = isCallbackPropName(previousPropName)
@@ -609,6 +603,14 @@ const rule: RuleModule<MessageIds, RuleOptions> = {
609603

610604
return memo
611605
}
606+
607+
if (
608+
previousReservedIndex > -1 &&
609+
currentReservedIndex > -1 &&
610+
currentReservedIndex > previousReservedIndex &&
611+
previousReservedNamespace !== currentReservedNamespace
612+
)
613+
return decl
612614
}
613615

614616
if (reservedLastList.length > 0) {
@@ -638,6 +640,14 @@ const rule: RuleModule<MessageIds, RuleOptions> = {
638640

639641
return memo
640642
}
643+
644+
if (
645+
previousReservedIndex > -1 &&
646+
currentReservedIndex > -1 &&
647+
currentReservedIndex > previousReservedIndex &&
648+
previousReservedNamespace !== currentReservedNamespace
649+
)
650+
return decl
641651
}
642652

643653
if (callbacksLast) {

0 commit comments

Comments
 (0)