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 3b1f29e
Show file tree
Hide file tree
Showing 4 changed files with 33 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
26 changes: 19 additions & 7 deletions tests/lib/rules/jsx-quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,35 @@
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}}
]
});

3 comments on commit 3b1f29e

@evansolomon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change ended up creating a bunch of false positive errors. My setting in eslintrc (yaml) was react/jsx-quotes: [2, single] and when I got version 3.4.0 I got an error for every file that was checked. Previous semver ranges were ^1.3.1 for eslint and ^3.3.2 for eslint-react-plugin. I realize this isn't really a big change, but that seems more backward incompatible than semver would suggest.

Not sure if (1) I was doing anything wrong or (2) this was intended behavior.

p.s. Also worth noting that eslint's syntax is different than the previous one used here (e.g. single is replaced by prefer-single).

@yannickcr
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. It was a mistake to display this as ESLint errors. I replaced it by a simple console.log, so it should solve the problem while keeping the warning.

Related issue #220

@evansolomon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry I missed that issue. Thanks.

Please sign in to comment.