Skip to content

Commit

Permalink
properly handle callee of type member expression
Browse files Browse the repository at this point in the history
  • Loading branch information
titarenko committed Sep 21, 2016
1 parent 66f4fd0 commit d74fe81
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-func-call",
"version": "1.0.2",
"version": "1.0.3",
"description": "Eslint plugin to control function call code style",
"keywords": [
"eslint",
Expand Down
4 changes: 3 additions & 1 deletion rules/opening-newline.js
Expand Up @@ -8,7 +8,9 @@ module.exports = {
CallExpression: function (node) {
var curArgs = node.arguments.length
var minArgs = context.options[0] || 1
var referenceLine = node.loc.start.line
var referenceLine = node.callee.type == 'MemberExpression'
? node.callee.property.loc.start.line
: node.loc.start.line
var lineToCompare = curArgs > 0
? node.arguments[0].loc.start.line
: node.loc.end.line
Expand Down
16 changes: 15 additions & 1 deletion tests/opening-newline.js
Expand Up @@ -9,7 +9,11 @@ ruleTester.run('opening-newline', rule, {
'call(\targ)',
'call(arg)',
'call(\n\targ1,\n\targ2)',
'call()'
'call()',
'call("\\\nasdasd\\\nasdasd\\\n")',
'obj\n\t.method()',
'obj\n\t.method(\na,\nb)',
'obj\n\t.method(\ta)'
],
invalid: [
{
Expand All @@ -21,6 +25,16 @@ ruleTester.run('opening-newline', rule, {
code: 'call(\n)',
options: [3],
errors: [ { message: 'Newline after opening brace is not allowed for function calls with 3 or less arguments!' } ]
},
{
code: 'obj.call(\n)',
options: [3],
errors: [ { message: 'Newline after opening brace is not allowed for function calls with 3 or less arguments!' } ]
},
{
code: 'obj.call(\na)',
options: [2],
errors: [ { message: 'Newline after opening brace is not allowed for function calls with 2 or less arguments!' } ]
}
]
})

0 comments on commit d74fe81

Please sign in to comment.