diff --git a/CHANGELOG.md b/CHANGELOG.md index bb38ab5ab7..1013a155c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]) @@ -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 @@ -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 \ No newline at end of file +[@devongovett]: https://github.com/devongovett +[@lilling]: https://github.com/lilling diff --git a/src/rules/newline-after-import.js b/src/rules/newline-after-import.js index 1e698f13e5..935572aa47 100644 --- a/src/rules/newline-after-import.js +++ b/src/rules/newline-after-import.js @@ -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', @@ -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)) { diff --git a/tests/src/rules/newline-after-import.js b/tests/src/rules/newline-after-import.js index 58f5ef1dd8..44e08cd5dd 100644 --- a/tests/src/rules/newline-after-import.js +++ b/tests/src/rules/newline-after-import.js @@ -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'), + }, ], });