diff --git a/lib/rules/wrap-multilines.js b/lib/rules/wrap-multilines.js index 44b8b83c45..193060087c 100644 --- a/lib/rules/wrap-multilines.js +++ b/lib/rules/wrap-multilines.js @@ -4,6 +4,16 @@ */ 'use strict'; +// ------------------------------------------------------------------------------ +// Constants +// ------------------------------------------------------------------------------ + +var DEFAULTS = { + declaration: true, + assignment: true, + return: true +}; + // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ @@ -33,6 +43,14 @@ module.exports = function(context) { } } + function isEnabled(type) { + var userOptions = context.options[0] || {}; + if (({}).hasOwnProperty.call(userOptions, type)) { + return userOptions[type]; + } + return DEFAULTS[type]; + } + // -------------------------------------------------------------------------- // Public // -------------------------------------------------------------------------- @@ -40,16 +58,31 @@ module.exports = function(context) { return { VariableDeclarator: function(node) { - check(node.init); + if (isEnabled('declaration')) { + check(node.init); + } }, AssignmentExpression: function(node) { - check(node.right); + if (isEnabled('assignment')) { + check(node.right); + } }, ReturnStatement: function(node) { - check(node.argument); + if (isEnabled('return')) { + check(node.argument); + } } }; }; + +module.exports.schema = [{ + type: 'object', + properties: { + declaration: {type: 'boolean'}, + assignment: {type: 'boolean'}, + return: {type: 'boolean'} + } +}]; diff --git a/tests/lib/rules/wrap-multilines.js b/tests/lib/rules/wrap-multilines.js index f6da85bcb5..aa32d87769 100644 --- a/tests/lib/rules/wrap-multilines.js +++ b/tests/lib/rules/wrap-multilines.js @@ -11,6 +11,67 @@ var eslint = require('eslint').linter; var ESLintTester = require('eslint-tester'); +// ------------------------------------------------------------------------------ +// Code Snippets +// ------------------------------------------------------------------------------ + +var RETURN_SINGLE_LINE = '\ + var Hello = React.createClass({\ + render: function() {\ + return
Hello {this.props.name}
;\ + }\ + });'; + +var RETURN_PAREN = '\ + var Hello = React.createClass({\ + render: function() {\ + return (\n\ +Hello {this.props.name}
\n\ +Hello {this.props.name}
\n\ +Hello
;'; + +var DECLARATION_PAREN = '\ + var hello = (\n\ +Hello
\n\ +Hello
\n\ +Hello
;'; + +var ASSIGNMENT_PAREN = '\ + var hello;\ + hello = (\n\ +Hello
\n\ +Hello
\n\ +Hello {this.props.name}
;\ - }\ - });', - ecmaFeatures: { - jsx: true - } + code: RETURN_SINGLE_LINE, + ecmaFeatures: {jsx: true} + }, { + code: RETURN_PAREN, + ecmaFeatures: {jsx: true} + }, { + code: RETURN_NO_PAREN, + args: [1, {return: false}], + ecmaFeatures: {jsx: true} + }, { + code: DECLARATION_SINGLE_LINE, + ecmaFeatures: {jsx: true} }, { - code: '\ - var Hello = React.createClass({\ - render: function() {\ - return (\n\ -Hello {this.props.name}
\n\ -Hello
;', - ecmaFeatures: { - jsx: true - } + code: DECLARATION_NO_PAREN, + args: [1, {declaration: false}], + ecmaFeatures: {jsx: true} }, { - code: '\ - var hello = (\n\ -Hello
\n\ -Hello
\n\ -Hello {this.props.name}
\n\ -Hello
\n\ -Hello
\n\ -