From 5c72c7386c417869b913bcb3aa6d6fd93cacefaa Mon Sep 17 00:00:00 2001 From: fatfisz Date: Thu, 30 Nov 2017 01:22:59 +0100 Subject: [PATCH] Change allowCallExpression to be true by default --- src/rules/no-anonymous-default-export.js | 11 +++++++++-- tests/src/rules/no-anonymous-default-export.js | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/rules/no-anonymous-default-export.js b/src/rules/no-anonymous-default-export.js index 8428688b9d..4e257fbf06 100644 --- a/src/rules/no-anonymous-default-export.js +++ b/src/rules/no-anonymous-default-export.js @@ -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', @@ -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: [ @@ -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) => { diff --git a/tests/src/rules/no-anonymous-default-export.js b/tests/src/rules/no-anonymous-default-export.js index e8d13936aa..c872cf4d09 100644 --- a/tests/src/rules/no-anonymous-default-export.js +++ b/tests/src/rules/no-anonymous-default-export.js @@ -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, ], @@ -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' }] }),