-
-
Notifications
You must be signed in to change notification settings - Fork 696
Add extension rule vue/quotes
#2463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
+154
−0
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
docs/rules/quotes.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
pageClass: rule-details | ||
sidebarDepth: 0 | ||
title: vue/quotes | ||
description: Enforce the consistent use of either backticks, double, or single quotes in `<template>` | ||
--- | ||
|
||
# vue/quotes | ||
|
||
> Enforce the consistent use of either backticks, double, or single quotes in `<template>` | ||
|
||
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge> | ||
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule. | ||
|
||
This rule is the same rule as stylistic [quotes] rule but it applies to the expressions in `<template>`. | ||
|
||
## :book: Rule Details | ||
|
||
- [quotes] | ||
|
||
[quotes]: https://eslint.style/rules/js/quotes | ||
|
||
## :mag: Implementation | ||
|
||
- [Rule source](https://github.com/vuejs/eslint-plugin-vue/blob/master/lib/rules/quotes.js) | ||
- [Test source](https://github.com/vuejs/eslint-plugin-vue/blob/master/tests/lib/rules/quotes.js) | ||
|
||
<sup>Taken with ❤️ [from ESLint Stylistic](https://eslint.style/rules/ts/quotes)</sup> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
lib/rules/quotes.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* @author Nhan Nguyen | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
'use strict' | ||
|
||
const { wrapStylisticOrCoreRule } = require('../utils') | ||
|
||
// eslint-disable-next-line internal/no-invalid-meta | ||
module.exports = wrapStylisticOrCoreRule('quotes') |
113 changes: 113 additions & 0 deletions
tests/lib/rules/quotes.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/** | ||
* @author Nhan Nguyen | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
'use strict' | ||
|
||
const RuleTester = require('../../eslint-compat').RuleTester | ||
const rule = require('../../../lib/rules/quotes') | ||
|
||
const tester = new RuleTester({ | ||
languageOptions: { | ||
parser: require('vue-eslint-parser'), | ||
ecmaVersion: 2020, | ||
sourceType: 'module' | ||
} | ||
}) | ||
|
||
tester.run('quotes', rule, { | ||
valid: [ | ||
`<template> | ||
<div>{{ "hello" }}</div> | ||
</template>`, | ||
`<template> | ||
<div>'This string contains "single" quotes'</div> | ||
</template>`, | ||
{ | ||
code: ` | ||
<template> | ||
<div>{{ 'hello' }}</div> | ||
</template>`, | ||
options: ['single'] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div>{{ \`hello\` }}</div> | ||
</template>`, | ||
options: ['backtick'] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div>"This string contains 'single' quotes"</div> | ||
</template>`, | ||
options: ['single', { avoidEscape: true }] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div>'This string contains "double" quotes'</div> | ||
</template>`, | ||
options: ['double', { avoidEscape: true }] | ||
} | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
<template> | ||
<div>{{ 'hello' }}</div> | ||
</template> | ||
`, | ||
output: ` | ||
<template> | ||
<div>{{ "hello" }}</div> | ||
</template> | ||
`, | ||
errors: [ | ||
{ | ||
message: 'Strings must use doublequote.', | ||
line: 3 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div>{{ "hello" }}</div> | ||
</template> | ||
`, | ||
output: ` | ||
<template> | ||
<div>{{ 'hello' }}</div> | ||
</template> | ||
`, | ||
options: ['single'], | ||
errors: [ | ||
{ | ||
message: 'Strings must use singlequote.', | ||
line: 3 | ||
} | ||
] | ||
}, | ||
{ | ||
code: ` | ||
<template> | ||
<div>{{ 'hello' }}</div> | ||
</template> | ||
`, | ||
output: ` | ||
<template> | ||
<div>{{ \`hello\` }}</div> | ||
</template> | ||
`, | ||
options: ['backtick'], | ||
errors: [ | ||
{ | ||
message: 'Strings must use backtick.', | ||
line: 3 | ||
} | ||
] | ||
} | ||
] | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.