Skip to content

Commit 305100d

Browse files
fix(define-macros-order): skip enum declarations and statements with declare modifier (#2918)
Co-authored-by: Flo Edelmann <git@flo-edelmann.de>
1 parent 28facb7 commit 305100d

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

.changeset/five-roses-peel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-vue": patch
3+
---
4+
5+
Changed `vue/define-macros-order` to ignore enum declarations and `declare` statements

lib/rules/define-macros-order.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ function inScriptSetup(scriptSetup, node) {
3333
)
3434
}
3535

36+
/**
37+
* @param {ASTNode} node
38+
*/
39+
function isDeclareStatement(node) {
40+
return 'declare' in node && node.declare === true
41+
}
42+
3643
/**
3744
* @param {ASTNode} node
3845
*/
@@ -53,6 +60,7 @@ function isUseStrictStatement(node) {
5360
function getTargetStatementPosition(scriptSetup, program) {
5461
const skipStatements = new Set([
5562
'ImportDeclaration',
63+
'TSEnumDeclaration',
5664
'TSModuleDeclaration',
5765
'TSInterfaceDeclaration',
5866
'TSTypeAliasDeclaration',
@@ -65,6 +73,7 @@ function getTargetStatementPosition(scriptSetup, program) {
6573
if (
6674
inScriptSetup(scriptSetup, item) &&
6775
!skipStatements.has(item.type) &&
76+
!isDeclareStatement(item) &&
6877
!isUseStrictStatement(item)
6978
) {
7079
return index

tests/lib/rules/define-macros-order.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ tester.run('define-macros-order', rule, {
128128
import { bar } from 'foo'
129129
declare global {}
130130
declare namespace Namespace {}
131+
declare const foo: string
132+
declare function bar(): void
131133
export interface Props {
132134
msg?: string
133135
labels?: string[]

0 commit comments

Comments
 (0)