diff --git a/CHANGELOG.md b/CHANGELOG.md index fac340b296..29fa61276c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/docs/rules/jsx-quotes.md b/docs/rules/jsx-quotes.md index 3d6f2c9896..1864bde3ab 100644 --- a/docs/rules/jsx-quotes.md +++ b/docs/rules/jsx-quotes.md @@ -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. diff --git a/lib/rules/jsx-quotes.js b/lib/rules/jsx-quotes.js index d8276e3f8d..2a26bf78a8 100644 --- a/lib/rules/jsx-quotes.js +++ b/lib/rules/jsx-quotes.js @@ -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; } diff --git a/tests/lib/rules/jsx-quotes.js b/tests/lib/rules/jsx-quotes.js index fbad9040c6..198910f3d9 100644 --- a/tests/lib/rules/jsx-quotes.js +++ b/tests/lib/rules/jsx-quotes.js @@ -12,6 +12,10 @@ 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 // ----------------------------------------------------------------------------- @@ -19,16 +23,30 @@ var RuleTester = require('eslint').RuleTester; var ruleTester = new RuleTester(); ruleTester.run('jsx-quotes', rule, { valid: [ - {code: ';', options: ['single'], ecmaFeatures: {jsx: true}}, - {code: ';', options: ['double'], ecmaFeatures: {jsx: true}}, - {code: ';', options: ['single', 'avoid-escape'], ecmaFeatures: {jsx: true}}, - {code: ';', options: ['double', 'avoid-escape'], ecmaFeatures: {jsx: true}}, - {code: 'foo;', options: ['single'], ecmaFeatures: {jsx: true}} + // None, should always trigger at least the deprecation warning ], invalid: [ + {code: ';', + errors: [{message: DEPRECATION_WARNING}], ecmaFeatures: {jsx: true}}, + {code: ';', + errors: [{message: DEPRECATION_WARNING}], options: ['single'], ecmaFeatures: {jsx: true}}, + {code: ';', + errors: [{message: DEPRECATION_WARNING}], options: ['double'], ecmaFeatures: {jsx: true}}, + {code: ';', + errors: [{message: DEPRECATION_WARNING}], options: ['single', 'avoid-escape'], ecmaFeatures: {jsx: true}}, + {code: ';', + errors: [{message: DEPRECATION_WARNING}], options: ['double', 'avoid-escape'], ecmaFeatures: {jsx: true}}, + {code: 'foo;', + errors: [{message: DEPRECATION_WARNING}], options: ['single'], ecmaFeatures: {jsx: true}}, {code: ';', - 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: ';', - errors: [{message: 'JSX attributes must use doublequote.'}], options: ['double'], ecmaFeatures: {jsx: true}} + errors: [ + {message: DEPRECATION_WARNING}, + {message: DOUBLEQUOTE_WARNING} + ], options: ['double'], ecmaFeatures: {jsx: true}} ] });