|
1 | 1 | /**
|
2 | 2 | * @fileoverview Prevent missing parentheses around multilines JSX
|
3 | 3 | * @author Yannick Croissant
|
| 4 | + * @deprecated |
4 | 5 | */
|
5 | 6 | 'use strict';
|
6 | 7 |
|
7 |
| -// ------------------------------------------------------------------------------ |
8 |
| -// Constants |
9 |
| -// ------------------------------------------------------------------------------ |
10 |
| - |
11 |
| -var DEFAULTS = { |
12 |
| - declaration: true, |
13 |
| - assignment: true, |
14 |
| - return: true |
15 |
| -}; |
16 |
| - |
17 | 8 | // ------------------------------------------------------------------------------
|
18 | 9 | // Rule Definition
|
19 | 10 | // ------------------------------------------------------------------------------
|
20 | 11 |
|
21 |
| -module.exports = function(context) { |
22 |
| - |
23 |
| - var sourceCode = context.getSourceCode(); |
| 12 | +var util = require('util'); |
| 13 | +var jsxWrapMultilines = require('./jsx-wrap-multilines'); |
| 14 | +var isWarnedForDeprecation = false; |
24 | 15 |
|
25 |
| - function isParenthesised(node) { |
26 |
| - var previousToken = sourceCode.getTokenBefore(node); |
27 |
| - var nextToken = sourceCode.getTokenAfter(node); |
28 |
| - |
29 |
| - return previousToken && nextToken && |
30 |
| - previousToken.value === '(' && previousToken.range[1] <= node.range[0] && |
31 |
| - nextToken.value === ')' && nextToken.range[0] >= node.range[1]; |
32 |
| - } |
33 |
| - |
34 |
| - function isMultilines(node) { |
35 |
| - return node.loc.start.line !== node.loc.end.line; |
36 |
| - } |
37 |
| - |
38 |
| - function check(node) { |
39 |
| - if (!node || node.type !== 'JSXElement') { |
40 |
| - return; |
41 |
| - } |
42 |
| - |
43 |
| - if (!isParenthesised(node) && isMultilines(node)) { |
44 |
| - context.report({ |
45 |
| - node: node, |
46 |
| - message: 'Missing parentheses around multilines JSX', |
47 |
| - fix: function(fixer) { |
48 |
| - return fixer.replaceText(node, '(' + sourceCode.getText(node) + ')'); |
49 |
| - } |
50 |
| - }); |
51 |
| - } |
52 |
| - } |
53 |
| - |
54 |
| - function isEnabled(type) { |
55 |
| - var userOptions = context.options[0] || {}; |
56 |
| - if (({}).hasOwnProperty.call(userOptions, type)) { |
57 |
| - return userOptions[type]; |
58 |
| - } |
59 |
| - return DEFAULTS[type]; |
60 |
| - } |
61 |
| - |
62 |
| - // -------------------------------------------------------------------------- |
63 |
| - // Public |
64 |
| - // -------------------------------------------------------------------------- |
65 |
| - |
66 |
| - return { |
67 |
| - |
68 |
| - VariableDeclarator: function(node) { |
69 |
| - if (isEnabled('declaration')) { |
70 |
| - check(node.init); |
71 |
| - } |
72 |
| - }, |
73 |
| - |
74 |
| - AssignmentExpression: function(node) { |
75 |
| - if (isEnabled('assignment')) { |
76 |
| - check(node.right); |
| 16 | +module.exports = function(context) { |
| 17 | + return util._extend(jsxWrapMultilines(context), { |
| 18 | + Program: function() { |
| 19 | + if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) { |
| 20 | + return; |
77 | 21 | }
|
78 |
| - }, |
79 | 22 |
|
80 |
| - ReturnStatement: function(node) { |
81 |
| - if (isEnabled('return')) { |
82 |
| - check(node.argument); |
83 |
| - } |
| 23 | + /* eslint-disable no-console */ |
| 24 | + console.log('The react/wrap-multilines rule is deprecated. Please ' + |
| 25 | + 'use the react/jsx-wrap-multilines rule instead.'); |
| 26 | + /* eslint-enable no-console */ |
| 27 | + isWarnedForDeprecation = true; |
84 | 28 | }
|
85 |
| - }; |
86 |
| - |
| 29 | + }); |
87 | 30 | };
|
88 | 31 |
|
89 | 32 | module.exports.schema = [{
|
|
0 commit comments