Skip to content

Commit 1b27a24

Browse files
committed
add rule quote from eslint stylistic
1 parent cfad3ee commit 1b27a24

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-0
lines changed

docs/rules/quotes.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
pageClass: rule-details
3+
sidebarDepth: 0
4+
title: vue/quotes
5+
description: Enforce the consistent use of either backticks, double, or single quotes in `<template>`
6+
---
7+
# vue/quotes
8+
9+
> Enforce the consistent use of either backticks, double, or single quotes in `<template>`
10+
11+
This rule is the same rule as stylistic [quotes] rule but it applies to the expressions in `<template>`.
12+
13+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
14+
15+
## :book: Further Reading
16+
17+
- [quotes]
18+
19+
[quotes]: https://eslint.style/rules/js/quotes
20+
21+
22+
## :mag: Implementation
23+
24+
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/quotes.js)
25+
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/quotes.js)
26+
27+
<sup>Taken with ❤️ [from ESLint Stylistic](https://eslint.style/rules/js/quotes)</sup>
28+

lib/rules/quotes.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @author Nhan Nguyen
3+
* See LICENSE file in root directory for full license.
4+
*/
5+
'use strict'
6+
7+
const { wrapStylisticOrCoreRule } = require('../utils')
8+
9+
// eslint-disable-next-line internal/no-invalid-meta
10+
module.exports = wrapStylisticOrCoreRule('quotes')

tests/lib/rules/quotes.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/**
2+
* @author Nhan Nguyen
3+
* See LICENSE file in root directory for full license.
4+
*/
5+
'use strict'
6+
7+
const RuleTester = require('../../eslint-compat').RuleTester
8+
const rule = require('../../../lib/rules/quotes')
9+
10+
const tester = new RuleTester({
11+
languageOptions: {
12+
parser: require('vue-eslint-parser'),
13+
ecmaVersion: 2020,
14+
sourceType: 'module'
15+
}
16+
})
17+
18+
tester.run('quotes', rule, {
19+
valid: [
20+
`<template>
21+
<div>{{ "hello" }}</div>
22+
</template>`,
23+
`<template>
24+
<div>'This string contains "single" quotes'</div>
25+
</template>`,
26+
{
27+
code: `
28+
<template>
29+
<div>{{ 'hello' }}</div>
30+
</template>`,
31+
options: ['single']
32+
},
33+
{
34+
code: `
35+
<template>
36+
<div>{{ \`hello\` }}</div>
37+
</template>`,
38+
options: ['backtick']
39+
},
40+
{
41+
code: `
42+
<template>
43+
<div>"This string contains 'single' quotes"</div>
44+
</template>`,
45+
options: ['single', { avoidEscape: true }]
46+
},
47+
{
48+
code: `
49+
<template>
50+
<div>'This string contains "double" quotes'</div>
51+
</template>`,
52+
options: ['double', { avoidEscape: true }]
53+
}
54+
],
55+
invalid: [
56+
{
57+
code: `
58+
<template>
59+
<div>{{ 'hello' }}</div>
60+
</template>
61+
`,
62+
output: `
63+
<template>
64+
<div>{{ "hello" }}</div>
65+
</template>
66+
`,
67+
errors: [
68+
{
69+
message: 'Strings must use doublequote.',
70+
line: 3
71+
}
72+
]
73+
},
74+
{
75+
code: `
76+
<template>
77+
<div>{{ "hello" }}</div>
78+
</template>
79+
`,
80+
output: `
81+
<template>
82+
<div>{{ 'hello' }}</div>
83+
</template>
84+
`,
85+
options: ['single'],
86+
errors: [
87+
{
88+
message: 'Strings must use singlequote.',
89+
line: 3
90+
}
91+
]
92+
},
93+
{
94+
code: `
95+
<template>
96+
<div>{{ 'hello' }}</div>
97+
</template>
98+
`,
99+
output: `
100+
<template>
101+
<div>{{ \`hello\` }}</div>
102+
</template>
103+
`,
104+
options: ['backtick'],
105+
errors: [
106+
{
107+
message: 'Strings must use backtick.',
108+
line: 3
109+
}
110+
]
111+
}
112+
]
113+
})

0 commit comments

Comments
 (0)