Skip to content

Commit

Permalink
Change allowCallExpression to be true by default
Browse files Browse the repository at this point in the history
  • Loading branch information
fatfisz committed Nov 30, 2017
1 parent 6647f86 commit 5c72c73
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/rules/no-anonymous-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const defs = {
option: 'allowCallExpression',
description: 'If `false`, will report default export of a function call',
message: 'Assign call result to a variable before exporting as module default',
default: true,
},
ClassDeclaration: {
option: 'allowAnonymousClass',
Expand Down Expand Up @@ -54,12 +55,18 @@ const schemaProperties = Object.keys(defs).
acc[def.option] = {
description: def.description,
type: 'boolean',
default: false,
}

return acc
}, {})

const defaults = Object.keys(defs).
map((key) => defs[key]).
reduce((acc, def) => {
acc[def.option] = def.hasOwnProperty('default') ? def.default : false
return acc
}, {})

module.exports = {
meta: {
schema: [
Expand All @@ -72,7 +79,7 @@ module.exports = {
},

create: function (context) {
const options = Object.assign({}, context.options[0])
const options = Object.assign({}, defaults, context.options[0])

return {
'ExportDefaultDeclaration': (node) => {
Expand Down
5 changes: 4 additions & 1 deletion tests/src/rules/no-anonymous-default-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ ruleTester.run('no-anonymous-default-export', rule, {
test({ code: 'const foo = 123\nexport { foo }' }),
test({ code: 'const foo = 123\nexport { foo as default }' }),

// Allow call expressions by default for backwards compatibility
test({ code: 'export default foo(bar)' }),

...SYNTAX_CASES,
],

Expand All @@ -44,7 +47,7 @@ ruleTester.run('no-anonymous-default-export', rule, {
test({ code: 'export default \'foo\'', errors: [{ message: 'Assign literal to a variable before exporting as module default' }] }),
test({ code: 'export default `foo`', errors: [{ message: 'Assign literal to a variable before exporting as module default' }] }),
test({ code: 'export default {}', errors: [{ message: 'Assign object to a variable before exporting as module default' }] }),
test({ code: 'export default foo(bar)', errors: [{ message: 'Assign call result to a variable before exporting as module default' }] }),
test({ code: 'export default foo(bar)', options: [{ allowCallExpression: false }], errors: [{ message: 'Assign call result to a variable before exporting as module default' }] }),

// Test failure with non-covering exception
test({ code: 'export default 123', options: [{ allowObject: true }], errors: [{ message: 'Assign literal to a variable before exporting as module default' }] }),
Expand Down

0 comments on commit 5c72c73

Please sign in to comment.