Skip to content

Commit

Permalink
Merge pull request #22 from jwilsson/iife-arrow-functions
Browse files Browse the repository at this point in the history
Fix false positive for arrow function IIFEs
  • Loading branch information
MitMaro committed Aug 15, 2016
2 parents a7dc674 + b9a3cf4 commit a72d2b4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/rules/strict-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module.exports = function (context) {
if (node.body.length === 1
&& node.body[0].type === 'ExpressionStatement'
&& node.body[0].expression.type === 'CallExpression'
&& node.body[0].expression.callee.type === 'FunctionExpression'
&& (node.body[0].expression.callee.type === 'FunctionExpression'
|| node.body[0].expression.callee.type === 'ArrowFunctionExpression')
&& node.body[0].expression.callee.body.type === 'BlockStatement'
) {
bodyToCheck = node.body[0].expression.callee.body.body;
Expand Down
31 changes: 30 additions & 1 deletion test/lib/rules/strict-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
var rule = require('../../../lib/rules/strict-newline');
var RuleTester = require('eslint').RuleTester;

var parserOptions = {};
var parserOptions = {
ecmaVersion: 6
};

var ruleTester = new RuleTester();
ruleTester.run('strict-newline', rule, {
Expand Down Expand Up @@ -69,6 +71,15 @@ ruleTester.run('strict-newline', rule, {
'var a;})()'
].join('\n'),
parserOptions: parserOptions
},
{
code: [
'(()=>{',
'"use strict"',
'',
'var a;})()'
].join('\n'),
parserOptions: parserOptions
}
],

Expand Down Expand Up @@ -131,6 +142,24 @@ ruleTester.run('strict-newline', rule, {
].join('\n'),
parserOptions: parserOptions,
errors: [{message: 'Expected newline after \'use strict\''}]
},
{
code: [
'(()=>{',
'"use strict"',
'var a;})();'
].join('\n'),
parserOptions: parserOptions,
errors: [{message: 'Expected newline after \'use strict\''}]
},
{
code: [
'(()=>{',
'"use strict";var a;',
'})();'
].join('\n'),
parserOptions: parserOptions,
errors: [{message: 'Expected newline after \'use strict\''}]
}
]
});

0 comments on commit a72d2b4

Please sign in to comment.