Skip to content

Commit

Permalink
Fix wrap-multilines rule
Browse files Browse the repository at this point in the history
Wrap multilines was broken after switching to new eslint rule format.
Also in this commit wrap-multilines was aligned with
jsx-wrap-multilines: "fixed: 'code'" was added to its meta.
  • Loading branch information
akozhemiakin committed Jul 31, 2016
1 parent 1a1dcdb commit 99f5eac
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/wrap-multilines.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
category: 'Stylistic Issues',
recommended: false
},
fixable: 'code',

schema: [{
type: 'object',
Expand All @@ -39,7 +40,7 @@ module.exports = {
},

create: function(context) {
return util._extend(jsxWrapMultilines(context), {
return util._extend(jsxWrapMultilines.create(context), {
Program: function() {
if (isWarnedForDeprecation || /\=-(f|-format)=/.test(process.argv.join('='))) {
return;
Expand Down
154 changes: 154 additions & 0 deletions tests/lib/rules/wrap-multilines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/**
* @fileoverview Prevent missing parentheses around multilines JSX
* @author Yannick Croissant
*/
'use strict';

// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------

var rule = require('../../../lib/rules/wrap-multilines');
var RuleTester = require('eslint').RuleTester;

var parserOptions = {
ecmaVersion: 6,
ecmaFeatures: {
jsx: true
}
};

// ------------------------------------------------------------------------------
// Code Snippets
// ------------------------------------------------------------------------------

var RETURN_SINGLE_LINE = '\
var Hello = React.createClass({\
render: function() {\
return <p>Hello {this.props.name}</p>;\
}\
});';

var RETURN_PAREN = '\
var Hello = React.createClass({\
render: function() {\
return (<div>\n\
<p>Hello {this.props.name}</p>\n\
</div>);\
}\
});';

var RETURN_NO_PAREN = '\
var Hello = React.createClass({\
render: function() {\
return <div>\n\
<p>Hello {this.props.name}</p>\n\
</div>;\
}\
});';

var DECLARATION_SINGLE_LINE = 'var hello = <p>Hello</p>;';

var DECLARATION_PAREN = '\
var hello = (<div>\n\
<p>Hello</p>\n\
</div>);';

var DECLARATION_NO_PAREN = '\
var hello = <div>\n\
<p>Hello</p>\n\
</div>;';

var ASSIGNMENT_SINGLE_LINE = 'var hello; hello = <p>Hello</p>;';

var ASSIGNMENT_PAREN = '\
var hello;\
hello = (<div>\n\
<p>Hello</p>\n\
</div>);';

var ASSIGNMENT_NO_PAREN = '\
var hello;\
hello = <div>\n\
<p>Hello</p>\n\
</div>;';

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

var ruleTester = new RuleTester();
ruleTester.run('wrap-multilines', rule, {

valid: [
{
code: RETURN_SINGLE_LINE,
parserOptions: parserOptions
}, {
code: RETURN_PAREN,
parserOptions: parserOptions
}, {
code: RETURN_NO_PAREN,
options: [{return: false}],
parserOptions: parserOptions
}, {
code: DECLARATION_SINGLE_LINE,
parserOptions: parserOptions
}, {
code: DECLARATION_PAREN,
parserOptions: parserOptions
}, {
code: DECLARATION_NO_PAREN,
options: [{declaration: false}],
parserOptions: parserOptions
}, {
code: ASSIGNMENT_SINGLE_LINE,
options: [{declaration: false}],
parserOptions: parserOptions
}, {
code: ASSIGNMENT_PAREN,
parserOptions: parserOptions
}, {
code: ASSIGNMENT_NO_PAREN,
options: [{assignment: false}],
parserOptions: parserOptions
}
],

invalid: [
{
code: RETURN_NO_PAREN,
output: RETURN_PAREN,
parserOptions: parserOptions,
errors: [{message: 'Missing parentheses around multilines JSX'}]
}, {
code: RETURN_NO_PAREN,
output: RETURN_PAREN,
parserOptions: parserOptions,
options: [{return: true}],
errors: [{message: 'Missing parentheses around multilines JSX'}]
}, {
code: DECLARATION_NO_PAREN,
output: DECLARATION_PAREN,
parserOptions: parserOptions,
errors: [{message: 'Missing parentheses around multilines JSX'}]
}, {
code: DECLARATION_NO_PAREN,
output: DECLARATION_PAREN,
parserOptions: parserOptions,
options: [{declaration: true}],
errors: [{message: 'Missing parentheses around multilines JSX'}]
}, {
code: ASSIGNMENT_NO_PAREN,
output: ASSIGNMENT_PAREN,
parserOptions: parserOptions,
errors: [{message: 'Missing parentheses around multilines JSX'}]
}, {
code: ASSIGNMENT_NO_PAREN,
output: ASSIGNMENT_PAREN,
parserOptions: parserOptions,
options: [{assignment: true}],
errors: [{message: 'Missing parentheses around multilines JSX'}]
}
]
});

0 comments on commit 99f5eac

Please sign in to comment.