Skip to content

Commit

Permalink
[Fix] newline-after-import: respect decorator annotations
Browse files Browse the repository at this point in the history
Fixes #1784.
  • Loading branch information
lilling authored and ljharb committed Feb 2, 2021
1 parent f2db74a commit 7df3335
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Expand Up @@ -25,6 +25,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`extensions`]/[`no-cycle`]/[`no-extraneous-dependencies`]: Correct module real path resolution ([#1696], thanks [@paztis])
- [`no-named-default`]: ignore Flow import type and typeof ([#1983], thanks [@christianvuerings])
- [`no-extraneous-dependencies`]: Exclude flow `typeof` imports ([#1534], thanks [@devongovett])
- [`newline-after-import`]: respect decorator annotations ([#1985], thanks [@lilling])

### Changed
- [Generic Import Callback] Make callback for all imports once in rules ([#1237], thanks [@ljqx])
Expand Down Expand Up @@ -759,6 +760,7 @@ for info on changes for earlier releases.

[`memo-parser`]: ./memo-parser/README.md

[#1985]: https://github.com/benmosher/eslint-plugin-import/pull/1985
[#1983]: https://github.com/benmosher/eslint-plugin-import/pull/1983
[#1974]: https://github.com/benmosher/eslint-plugin-import/pull/1974
[#1958]: https://github.com/benmosher/eslint-plugin-import/pull/1958
Expand Down Expand Up @@ -1340,4 +1342,5 @@ for info on changes for earlier releases.
[@panrafal]: https://github.com/panrafal
[@ttmarek]: https://github.com/ttmarek
[@christianvuerings]: https://github.com/christianvuerings
[@devongovett]: https://github.com/devongovett
[@devongovett]: https://github.com/devongovett
[@lilling]: https://github.com/lilling
6 changes: 5 additions & 1 deletion src/rules/newline-after-import.js
Expand Up @@ -47,6 +47,10 @@ function isExportDefaultClass(node) {
return node.type === 'ExportDefaultDeclaration' && node.declaration.type === 'ClassDeclaration';
}

function isExportNameClass(node) {
return node.type === 'ExportNamedDeclaration' && node.declaration.type === 'ClassDeclaration';
}

module.exports = {
meta: {
type: 'layout',
Expand All @@ -72,7 +76,7 @@ module.exports = {
const requireCalls = [];

function checkForNewLine(node, nextNode, type) {
if (isExportDefaultClass(nextNode)) {
if (isExportDefaultClass(nextNode) || isExportNameClass(nextNode)) {
const classNode = nextNode.declaration;

if (isClassWithDecorator(classNode)) {
Expand Down
24 changes: 24 additions & 0 deletions tests/src/rules/newline-after-import.js
Expand Up @@ -429,5 +429,29 @@ ruleTester.run('newline-after-import', require('rules/newline-after-import'), {
parserOptions: { sourceType: 'module' },
parser: require.resolve('babel-eslint'),
},
{
code: `
// issue 1784
import { map } from 'rxjs/operators';
@Component({})
export class Test {}
`,
output: `
// issue 1784
import { map } from 'rxjs/operators';
@Component({})
export class Test {}
`,
errors: [
{
line: 2,
column: 1,
message: IMPORT_ERROR_MESSAGE,
},
],
parserOptions: { sourceType: 'module' },
parser: require.resolve('babel-eslint'),
},
],
});

0 comments on commit 7df3335

Please sign in to comment.