Skip to content

Commit 7cb7df9

Browse files
committed
[Changed]: no-default-import - limit highlight to the word "default"
1 parent 7c239fe commit 7cb7df9

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
55
This change log adheres to standards from [Keep a CHANGELOG](https://keepachangelog.com).
66

77
## [Unreleased]
8+
- [`no-default-import`]: report on the token "default" instead of the entire node ([@pmcelhaney])
89

910
## [2.25.3] - 2021-11-09
1011

src/rules/no-default-export.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@ module.exports = {
2020
`Do not alias \`${local.name}\` as \`default\`. Just export ` +
2121
`\`${local.name}\` itself instead.`;
2222

23+
2324
return {
2425
ExportDefaultDeclaration(node) {
25-
context.report({ node, message: preferNamed });
26+
context.report({ node, message: preferNamed, loc: context.getSourceCode().getFirstTokens(node)[1].loc });
2627
},
2728

2829
ExportNamedDeclaration(node) {
2930
node.specifiers.forEach(specifier => {
3031
if (specifier.type === 'ExportDefaultSpecifier' &&
3132
specifier.exported.name === 'default') {
32-
context.report({ node, message: preferNamed });
33+
context.report({ node, message: preferNamed, loc: context.getSourceCode().getFirstTokens(node)[1].loc });
3334
} else if (specifier.type === 'ExportSpecifier' &&
3435
specifier.exported.name === 'default') {
35-
context.report({ node, message: noAliasDefault(specifier) });
36+
context.report({ node, message: noAliasDefault(specifier), loc: context.getSourceCode().getFirstTokens(node)[1].loc });
3637
}
3738
});
3839
},

tests/src/rules/no-default-export.js

+31
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ ruleTester.run('no-default-export', rule, {
9191
errors: [{
9292
type: 'ExportDefaultDeclaration',
9393
message: 'Prefer named exports.',
94+
line: 1,
95+
column: 8,
9496
}],
9597
}),
9698
test({
@@ -100,6 +102,35 @@ ruleTester.run('no-default-export', rule, {
100102
errors: [{
101103
type: 'ExportDefaultDeclaration',
102104
message: 'Prefer named exports.',
105+
line: 3,
106+
column: 16,
107+
}],
108+
}),
109+
test({
110+
code: 'export default class Bar {};',
111+
errors: [{
112+
type: 'ExportDefaultDeclaration',
113+
message: 'Prefer named exports.',
114+
line: 1,
115+
column: 8,
116+
}],
117+
}),
118+
test({
119+
code: 'export default function() {};',
120+
errors: [{
121+
type: 'ExportDefaultDeclaration',
122+
message: 'Prefer named exports.',
123+
line: 1,
124+
column: 8,
125+
}],
126+
}),
127+
test({
128+
code: 'export default class {};',
129+
errors: [{
130+
type: 'ExportDefaultDeclaration',
131+
message: 'Prefer named exports.',
132+
line: 1,
133+
column: 8,
103134
}],
104135
}),
105136
test({

0 commit comments

Comments
 (0)