Skip to content

Commit

Permalink
Deprecate jsx-quotes rule (fixes #217)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Sep 15, 2015
1 parent 5b1b562 commit f817e37
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).

## [Unreleased]
### Changed
* Deprecate `jsx-quotes` rule ([#217][])

[Unreleased]: https://github.com/yannickcr/eslint-plugin-react/compare/v3.3.2...HEAD
[#217]: https://github.com/yannickcr/eslint-plugin-react/issues/217

## [3.3.2] - 2015-09-10
### Changed
* Add `state` in lifecycle methods for `sort-comp` rule ([#197][] @mathieudutour)
Expand Down
2 changes: 2 additions & 0 deletions docs/rules/jsx-quotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Enforce quote style for JSX attributes (jsx-quotes)

**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`.

Enforces coding style that JSX attributes are delimited with single or double quotes.

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.
Expand Down
5 changes: 5 additions & 0 deletions lib/rules/jsx-quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ module.exports = function(context) {

return {

Program: function(node) {
context.report(node, 'The react/jsx-quotes rule is deprecated. Please use the jsx-quotes rule instead.');
},

Literal: function(node) {

if (node.parent.type !== 'JSXAttribute') {
return;
}
Expand Down
32 changes: 25 additions & 7 deletions tests/lib/rules/jsx-quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,41 @@
var rule = require('../../../lib/rules/jsx-quotes');
var RuleTester = require('eslint').RuleTester;

var DEPRECATION_WARNING = 'The react/jsx-quotes rule is deprecated. Please use the jsx-quotes rule instead.';
var SINGLEQUOTE_WARNING = 'JSX attributes must use singlequote.';
var DOUBLEQUOTE_WARNING = 'JSX attributes must use doublequote.';

// -----------------------------------------------------------------------------
// Tests
// -----------------------------------------------------------------------------

var ruleTester = new RuleTester();
ruleTester.run('jsx-quotes', rule, {
valid: [
{code: '<App foo=\'bar\' />;', options: ['single'], ecmaFeatures: {jsx: true}},
{code: '<App foo="bar" />;', options: ['double'], ecmaFeatures: {jsx: true}},
{code: '<App foo="ba\'r" />;', options: ['single', 'avoid-escape'], ecmaFeatures: {jsx: true}},
{code: '<App foo=\'ba"r\' />;', options: ['double', 'avoid-escape'], ecmaFeatures: {jsx: true}},
{code: '<App>foo</App>;', options: ['single'], ecmaFeatures: {jsx: true}}
// None, should always trigger at least the deprecation warning
],
invalid: [
{code: '<App />;',
errors: [{message: DEPRECATION_WARNING}], ecmaFeatures: {jsx: true}},
{code: '<App foo=\'bar\' />;',
errors: [{message: DEPRECATION_WARNING}], options: ['single'], ecmaFeatures: {jsx: true}},
{code: '<App foo="bar" />;',
errors: [{message: DEPRECATION_WARNING}], options: ['double'], ecmaFeatures: {jsx: true}},
{code: '<App foo="ba\'r" />;',
errors: [{message: DEPRECATION_WARNING}], options: ['single', 'avoid-escape'], ecmaFeatures: {jsx: true}},
{code: '<App foo=\'ba"r\' />;',
errors: [{message: DEPRECATION_WARNING}], options: ['double', 'avoid-escape'], ecmaFeatures: {jsx: true}},
{code: '<App>foo</App>;',
errors: [{message: DEPRECATION_WARNING}], options: ['single'], ecmaFeatures: {jsx: true}},
{code: '<App foo="bar" />;',
errors: [{message: 'JSX attributes must use singlequote.'}], options: ['single'], ecmaFeatures: {jsx: true}},
errors: [
{message: DEPRECATION_WARNING},
{message: SINGLEQUOTE_WARNING}
], options: ['single'], ecmaFeatures: {jsx: true}},
{code: '<App foo=\'bar\' />;',
errors: [{message: 'JSX attributes must use doublequote.'}], options: ['double'], ecmaFeatures: {jsx: true}}
errors: [
{message: DEPRECATION_WARNING},
{message: DOUBLEQUOTE_WARNING}
], options: ['double'], ecmaFeatures: {jsx: true}}
]
});

0 comments on commit f817e37

Please sign in to comment.