Skip to content

Commit

Permalink
Tighten no-named-export error message
Browse files Browse the repository at this point in the history
  • Loading branch information
fsmaia committed Aug 15, 2018
1 parent 900bd20 commit c506c5c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/rules/no-named-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ module.exports = {
return {}
}

const preferDefault = 'Prefer default export.'
const message = 'Named exports are not allowed.'

return {
ExportAllDeclaration(node) {
context.report({node, message: preferDefault})
context.report({node, message})
},

ExportNamedDeclaration(node) {
if (node.specifiers.length === 0) {
return context.report({node, message: preferDefault})
return context.report({node, message})
}

const someNamed = node.specifiers.some(specifier => specifier.exported.name !== 'default')
if (someNamed) {
context.report({node, message: preferDefault})
context.report({node, message})
}
},
}
Expand Down
40 changes: 20 additions & 20 deletions tests/src/rules/no-named-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ ruleTester.run('no-named-export', rule, {
`,
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}, {
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
Expand All @@ -48,7 +48,7 @@ ruleTester.run('no-named-export', rule, {
export default bar;`,
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
Expand All @@ -58,17 +58,17 @@ ruleTester.run('no-named-export', rule, {
`,
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}, {
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
code: `export const foo = 'foo';`,
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
Expand All @@ -78,35 +78,35 @@ ruleTester.run('no-named-export', rule, {
`,
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
code: `export { foo, bar }`,
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
code: `export const { foo, bar } = item;`,
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
code: `export const { foo, bar: baz } = item;`,
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
code: `export const { foo: { bar, baz } } = item;`,
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
Expand All @@ -116,63 +116,63 @@ ruleTester.run('no-named-export', rule, {
`,
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}, {
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
code: `export * from './foo';`,
errors: [{
ruleId: 'ExportAllDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
code: `export const { foo } = { foo: "bar" };`,
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
code: `export const { foo: { bar } } = { foo: { bar: "baz" } };`,
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
code: 'export { a, b } from "foo.js"',
parser: 'babel-eslint',
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
code: `export type UserId = number;`,
parser: 'babel-eslint',
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
code: 'export foo from "foo.js"',
parser: 'babel-eslint',
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
test({
code: `export Memory, { MemoryValue } from './Memory'`,
parser: 'babel-eslint',
errors: [{
ruleId: 'ExportNamedDeclaration',
message: 'Prefer default export.',
message: 'Named exports are not allowed.',
}],
}),
],
Expand Down

0 comments on commit c506c5c

Please sign in to comment.