Skip to content

Fix wrap-multilines rule #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'}]
}
]
});