Skip to content

Commit ee9f609

Browse files
authored
number-literal-case: Support Vue SFC (#1434)
1 parent 76e8027 commit ee9f609

File tree

4 files changed

+100
-2
lines changed

4 files changed

+100
-2
lines changed

rules/number-literal-case.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
const {checkVueTemplate} = require('./utils/rule.js');
23
const {isNumber, isBigInt} = require('./utils/numeric.js');
34

45
const MESSAGE_ID = 'number-literal-case';
@@ -39,7 +40,7 @@ const create = () => {
3940
};
4041

4142
module.exports = {
42-
create,
43+
create: checkVueTemplate(create),
4344
meta: {
4445
type: 'suggestion',
4546
docs: {

test/number-literal-case.mjs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import outdent from 'outdent';
2-
import {getTester, avoidTestTitleConflict} from './utils/test.mjs';
2+
import {getTester, avoidTestTitleConflict, parsers} from './utils/test.mjs';
33

44
const {test} = getTester(import.meta);
55

@@ -166,3 +166,20 @@ test.snapshot({
166166
'console.log(BigInt(0B10 + 1.2E+3) + 0XdeEd_Beefn)',
167167
],
168168
});
169+
170+
test.snapshot({
171+
testerOptions: {
172+
parser: parsers.vue,
173+
},
174+
valid: [
175+
'<template><input value="0XdeEd_Beef"></div></template>',
176+
'<template><div v-if="0xDEED_BEEF > 0"></div></template>',
177+
],
178+
invalid: [
179+
'<template><div v-if="0XdeEd_Beef > 0"></div></template>',
180+
'<template><div v-if="0XdeEd_Beefn > 0n"></div></template>',
181+
'<template><div>{{1.2E3}}</div></template>',
182+
'<template><div>{{0B1n}}</div></template>',
183+
'<script>export default {data() {return {n: 0XdeEd_Beefn}}}</script>',
184+
],
185+
});

test/snapshots/number-literal-case.mjs.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,83 @@ Generated by [AVA](https://avajs.dev).
3333
> 1 | console.log(BigInt(0B10 + 1.2E+3) + 0XdeEd_Beefn)␊
3434
| ^^^^^^^^^^^^ Invalid number literal casing.␊
3535
`
36+
37+
## Invalid #1
38+
1 | <template><div v-if="0XdeEd_Beef > 0"></div></template>
39+
40+
> Output
41+
42+
`␊
43+
1 | <template><div v-if="0xDEED_BEEF > 0"></div></template>␊
44+
`
45+
46+
> Error 1/1
47+
48+
`␊
49+
> 1 | <template><div v-if="0XdeEd_Beef > 0"></div></template>␊
50+
| ^^^^^^^^^^^ Invalid number literal casing.␊
51+
`
52+
53+
## Invalid #2
54+
1 | <template><div v-if="0XdeEd_Beefn > 0n"></div></template>
55+
56+
> Output
57+
58+
`␊
59+
1 | <template><div v-if="0xDEED_BEEFn > 0n"></div></template>␊
60+
`
61+
62+
> Error 1/1
63+
64+
`␊
65+
> 1 | <template><div v-if="0XdeEd_Beefn > 0n"></div></template>␊
66+
| ^^^^^^^^^^^^ Invalid number literal casing.␊
67+
`
68+
69+
## Invalid #3
70+
1 | <template><div>{{1.2E3}}</div></template>
71+
72+
> Output
73+
74+
`␊
75+
1 | <template><div>{{1.2e3}}</div></template>␊
76+
`
77+
78+
> Error 1/1
79+
80+
`␊
81+
> 1 | <template><div>{{1.2E3}}</div></template>␊
82+
| ^^^^^ Invalid number literal casing.␊
83+
`
84+
85+
## Invalid #4
86+
1 | <template><div>{{0B1n}}</div></template>
87+
88+
> Output
89+
90+
`␊
91+
1 | <template><div>{{0b1n}}</div></template>␊
92+
`
93+
94+
> Error 1/1
95+
96+
`␊
97+
> 1 | <template><div>{{0B1n}}</div></template>␊
98+
| ^^^^ Invalid number literal casing.␊
99+
`
100+
101+
## Invalid #5
102+
1 | <script>export default {data() {return {n: 0XdeEd_Beefn}}}</script>
103+
104+
> Output
105+
106+
`␊
107+
1 | <script>export default {data() {return {n: 0xDEED_BEEFn}}}</script>␊
108+
`
109+
110+
> Error 1/1
111+
112+
`␊
113+
> 1 | <script>export default {data() {return {n: 0XdeEd_Beefn}}}</script>␊
114+
| ^^^^^^^^^^^^ Invalid number literal casing.␊
115+
`
333 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)