mirror of
https://github.com/hanzoai/eslint.git
synced 2026-10-30 19:38:10 +00:00
116 lines
2.3 KiB
JavaScript
116 lines
2.3 KiB
JavaScript
/**
|
|
* @fileoverview Tests for jsx-quotes rule.
|
|
* @author Mathias Schreck <https://github.com/lo1tuma>
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Requirements
|
|
//------------------------------------------------------------------------------
|
|
|
|
const rule = require("../../../lib/rules/jsx-quotes"),
|
|
RuleTester = require("../../../lib/rule-tester/rule-tester");
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Tests
|
|
//------------------------------------------------------------------------------
|
|
|
|
const ruleTester = new RuleTester({
|
|
languageOptions: {
|
|
ecmaVersion: 6,
|
|
parserOptions: {
|
|
ecmaFeatures: { jsx: true },
|
|
},
|
|
},
|
|
});
|
|
|
|
ruleTester.run("jsx-quotes", rule, {
|
|
valid: [
|
|
'<foo bar="baz" />',
|
|
"<foo bar='\"' />",
|
|
{
|
|
code: '<foo bar="\'" />',
|
|
options: ["prefer-single"],
|
|
},
|
|
{
|
|
code: "<foo bar='baz' />",
|
|
options: ["prefer-single"],
|
|
},
|
|
'<foo bar="baz">"</foo>',
|
|
{
|
|
code: "<foo bar='baz'>'</foo>",
|
|
options: ["prefer-single"],
|
|
},
|
|
"<foo bar={'baz'} />",
|
|
{
|
|
code: '<foo bar={"baz"} />',
|
|
options: ["prefer-single"],
|
|
},
|
|
"<foo bar={baz} />",
|
|
"<foo bar />",
|
|
{
|
|
code: "<foo bar='"' />",
|
|
options: ["prefer-single"],
|
|
},
|
|
'<foo bar=""" />',
|
|
{
|
|
code: "<foo bar=''' />",
|
|
options: ["prefer-single"],
|
|
},
|
|
'<foo bar="'" />',
|
|
],
|
|
invalid: [
|
|
{
|
|
code: "<foo bar='baz' />",
|
|
output: '<foo bar="baz" />',
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { description: "singlequote" },
|
|
line: 1,
|
|
column: 10,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: '<foo bar="baz" />',
|
|
output: "<foo bar='baz' />",
|
|
options: ["prefer-single"],
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { description: "doublequote" },
|
|
line: 1,
|
|
column: 10,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: '<foo bar=""" />',
|
|
output: "<foo bar='"' />",
|
|
options: ["prefer-single"],
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { description: "doublequote" },
|
|
line: 1,
|
|
column: 10,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
code: "<foo bar=''' />",
|
|
output: '<foo bar="'" />',
|
|
errors: [
|
|
{
|
|
messageId: "unexpected",
|
|
data: { description: "singlequote" },
|
|
line: 1,
|
|
column: 10,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|