Skip to content

Commit f817e37

Browse files
committed
Deprecate jsx-quotes rule (fixes jsx-eslint#217)
1 parent 5b1b562 commit f817e37

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).
55

6+
## [Unreleased]
7+
### Changed
8+
* Deprecate `jsx-quotes` rule ([#217][])
9+
10+
[Unreleased]: https://github.com/yannickcr/eslint-plugin-react/compare/v3.3.2...HEAD
11+
[#217]: https://github.com/yannickcr/eslint-plugin-react/issues/217
12+
613
## [3.3.2] - 2015-09-10
714
### Changed
815
* Add `state` in lifecycle methods for `sort-comp` rule ([#197][] @mathieudutour)

docs/rules/jsx-quotes.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Enforce quote style for JSX attributes (jsx-quotes)
22

3+
**Deprecation notice**: This rule is deprecated and has been replaced by the ESLint [jsx-quotes](http://eslint.org/docs/rules/jsx-quotes) rule added in ESLint `v1.4.0`.
4+
35
Enforces coding style that JSX attributes are delimited with single or double quotes.
46

57
It takes an option as the second parameter which can be `"double"` or `"single"` for double-quotes or single-quotes respectively. There is no default.

lib/rules/jsx-quotes.js

+5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ module.exports = function(context) {
4242

4343
return {
4444

45+
Program: function(node) {
46+
context.report(node, 'The react/jsx-quotes rule is deprecated. Please use the jsx-quotes rule instead.');
47+
},
48+
4549
Literal: function(node) {
50+
4651
if (node.parent.type !== 'JSXAttribute') {
4752
return;
4853
}

tests/lib/rules/jsx-quotes.js

+25-7
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,41 @@
1212
var rule = require('../../../lib/rules/jsx-quotes');
1313
var RuleTester = require('eslint').RuleTester;
1414

15+
var DEPRECATION_WARNING = 'The react/jsx-quotes rule is deprecated. Please use the jsx-quotes rule instead.';
16+
var SINGLEQUOTE_WARNING = 'JSX attributes must use singlequote.';
17+
var DOUBLEQUOTE_WARNING = 'JSX attributes must use doublequote.';
18+
1519
// -----------------------------------------------------------------------------
1620
// Tests
1721
// -----------------------------------------------------------------------------
1822

1923
var ruleTester = new RuleTester();
2024
ruleTester.run('jsx-quotes', rule, {
2125
valid: [
22-
{code: '<App foo=\'bar\' />;', options: ['single'], ecmaFeatures: {jsx: true}},
23-
{code: '<App foo="bar" />;', options: ['double'], ecmaFeatures: {jsx: true}},
24-
{code: '<App foo="ba\'r" />;', options: ['single', 'avoid-escape'], ecmaFeatures: {jsx: true}},
25-
{code: '<App foo=\'ba"r\' />;', options: ['double', 'avoid-escape'], ecmaFeatures: {jsx: true}},
26-
{code: '<App>foo</App>;', options: ['single'], ecmaFeatures: {jsx: true}}
26+
// None, should always trigger at least the deprecation warning
2727
],
2828
invalid: [
29+
{code: '<App />;',
30+
errors: [{message: DEPRECATION_WARNING}], ecmaFeatures: {jsx: true}},
31+
{code: '<App foo=\'bar\' />;',
32+
errors: [{message: DEPRECATION_WARNING}], options: ['single'], ecmaFeatures: {jsx: true}},
33+
{code: '<App foo="bar" />;',
34+
errors: [{message: DEPRECATION_WARNING}], options: ['double'], ecmaFeatures: {jsx: true}},
35+
{code: '<App foo="ba\'r" />;',
36+
errors: [{message: DEPRECATION_WARNING}], options: ['single', 'avoid-escape'], ecmaFeatures: {jsx: true}},
37+
{code: '<App foo=\'ba"r\' />;',
38+
errors: [{message: DEPRECATION_WARNING}], options: ['double', 'avoid-escape'], ecmaFeatures: {jsx: true}},
39+
{code: '<App>foo</App>;',
40+
errors: [{message: DEPRECATION_WARNING}], options: ['single'], ecmaFeatures: {jsx: true}},
2941
{code: '<App foo="bar" />;',
30-
errors: [{message: 'JSX attributes must use singlequote.'}], options: ['single'], ecmaFeatures: {jsx: true}},
42+
errors: [
43+
{message: DEPRECATION_WARNING},
44+
{message: SINGLEQUOTE_WARNING}
45+
], options: ['single'], ecmaFeatures: {jsx: true}},
3146
{code: '<App foo=\'bar\' />;',
32-
errors: [{message: 'JSX attributes must use doublequote.'}], options: ['double'], ecmaFeatures: {jsx: true}}
47+
errors: [
48+
{message: DEPRECATION_WARNING},
49+
{message: DOUBLEQUOTE_WARNING}
50+
], options: ['double'], ecmaFeatures: {jsx: true}}
3351
]
3452
});

0 commit comments

Comments
 (0)