Skip to content

Commit

Permalink
number-literal-case: Support Vue SFC (#1434)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Jul 19, 2021
1 parent 76e8027 commit ee9f609
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 2 deletions.
3 changes: 2 additions & 1 deletion rules/number-literal-case.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
const {checkVueTemplate} = require('./utils/rule.js');
const {isNumber, isBigInt} = require('./utils/numeric.js');

const MESSAGE_ID = 'number-literal-case';
Expand Down Expand Up @@ -39,7 +40,7 @@ const create = () => {
};

module.exports = {
create,
create: checkVueTemplate(create),
meta: {
type: 'suggestion',
docs: {
Expand Down
19 changes: 18 additions & 1 deletion test/number-literal-case.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import outdent from 'outdent';
import {getTester, avoidTestTitleConflict} from './utils/test.mjs';
import {getTester, avoidTestTitleConflict, parsers} from './utils/test.mjs';

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

Expand Down Expand Up @@ -166,3 +166,20 @@ test.snapshot({
'console.log(BigInt(0B10 + 1.2E+3) + 0XdeEd_Beefn)',
],
});

test.snapshot({
testerOptions: {
parser: parsers.vue,
},
valid: [
'<template><input value="0XdeEd_Beef"></div></template>',
'<template><div v-if="0xDEED_BEEF > 0"></div></template>',
],
invalid: [
'<template><div v-if="0XdeEd_Beef > 0"></div></template>',
'<template><div v-if="0XdeEd_Beefn > 0n"></div></template>',
'<template><div>{{1.2E3}}</div></template>',
'<template><div>{{0B1n}}</div></template>',
'<script>export default {data() {return {n: 0XdeEd_Beefn}}}</script>',
],
});
80 changes: 80 additions & 0 deletions test/snapshots/number-literal-case.mjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,83 @@ Generated by [AVA](https://avajs.dev).
> 1 | console.log(BigInt(0B10 + 1.2E+3) + 0XdeEd_Beefn)␊
| ^^^^^^^^^^^^ Invalid number literal casing.␊
`

## Invalid #1
1 | <template><div v-if="0XdeEd_Beef > 0"></div></template>

> Output
`␊
1 | <template><div v-if="0xDEED_BEEF > 0"></div></template>␊
`

> Error 1/1
`␊
> 1 | <template><div v-if="0XdeEd_Beef > 0"></div></template>␊
| ^^^^^^^^^^^ Invalid number literal casing.␊
`

## Invalid #2
1 | <template><div v-if="0XdeEd_Beefn > 0n"></div></template>

> Output
`␊
1 | <template><div v-if="0xDEED_BEEFn > 0n"></div></template>␊
`

> Error 1/1
`␊
> 1 | <template><div v-if="0XdeEd_Beefn > 0n"></div></template>␊
| ^^^^^^^^^^^^ Invalid number literal casing.␊
`

## Invalid #3
1 | <template><div>{{1.2E3}}</div></template>

> Output
`␊
1 | <template><div>{{1.2e3}}</div></template>␊
`

> Error 1/1
`␊
> 1 | <template><div>{{1.2E3}}</div></template>␊
| ^^^^^ Invalid number literal casing.␊
`

## Invalid #4
1 | <template><div>{{0B1n}}</div></template>

> Output
`␊
1 | <template><div>{{0b1n}}</div></template>␊
`

> Error 1/1
`␊
> 1 | <template><div>{{0B1n}}</div></template>␊
| ^^^^ Invalid number literal casing.␊
`

## Invalid #5
1 | <script>export default {data() {return {n: 0XdeEd_Beefn}}}</script>

> Output
`␊
1 | <script>export default {data() {return {n: 0xDEED_BEEFn}}}</script>␊
`

> Error 1/1
`␊
> 1 | <script>export default {data() {return {n: 0XdeEd_Beefn}}}</script>␊
| ^^^^^^^^^^^^ Invalid number literal casing.␊
`
Binary file modified test/snapshots/number-literal-case.mjs.snap
Binary file not shown.

0 comments on commit ee9f609

Please sign in to comment.