From 050508681a0a46d1e147e828c3debd04b9e81ef6 Mon Sep 17 00:00:00 2001 From: Andrew Fairbairn Date: Mon, 13 Feb 2017 17:26:41 +0000 Subject: [PATCH] Deprecate jsx-space-before-closing rule in favour of jsx-tag-spacing rule which offers a superset of it. jsx-space-before-closing still works but will trigger a warning. --- docs/rules/jsx-space-before-closing.md | 2 ++ lib/rules/jsx-space-before-closing.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/docs/rules/jsx-space-before-closing.md b/docs/rules/jsx-space-before-closing.md index 6d5cd640c1..d9d6b45d69 100644 --- a/docs/rules/jsx-space-before-closing.md +++ b/docs/rules/jsx-space-before-closing.md @@ -1,5 +1,7 @@ # Validate spacing before closing bracket in JSX (jsx-space-before-closing) +**Deprecation notice**: This rule is deprecated. Please use the `"beforeSelfClosing"` option of the [jsx-tag-spacing](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-tag-spacing.md) rule instead. + Enforce or forbid spaces before the closing bracket of self-closing JSX elements. **Fixable:** This rule is automatically fixable using the `--fix` flag on the command line. diff --git a/lib/rules/jsx-space-before-closing.js b/lib/rules/jsx-space-before-closing.js index 8557545ea9..21e480f7e7 100644 --- a/lib/rules/jsx-space-before-closing.js +++ b/lib/rules/jsx-space-before-closing.js @@ -1,10 +1,12 @@ /** * @fileoverview Validate spacing before closing bracket in JSX. * @author ryym + * @deprecated */ 'use strict'; var getTokenBeforeClosingBracket = require('../util/getTokenBeforeClosingBracket'); +var isWarnedForDeprecation = false; // ------------------------------------------------------------------------------ // Rule Definition @@ -12,6 +14,7 @@ var getTokenBeforeClosingBracket = require('../util/getTokenBeforeClosingBracket module.exports = { meta: { + deprecated: true, docs: { description: 'Validate spacing before closing bracket in JSX', category: 'Stylistic Issues', @@ -67,6 +70,19 @@ module.exports = { } }); } + }, + + Program: function() { + if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) { + return; + } + + /* eslint-disable no-console */ + console.log('The react/jsx-space-before-closing rule is deprecated. ' + + 'Please use the react/jsx-tag-spacing rule with the ' + + '"beforeSelfClosing" option instead.'); + /* eslint-enable no-console */ + isWarnedForDeprecation = true; } };