Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

newline-after-import not recognizing decorator #1004

Closed
hannahjin opened this issue Jan 19, 2018 · 7 comments
Closed

newline-after-import not recognizing decorator #1004

hannahjin opened this issue Jan 19, 2018 · 7 comments

Comments

@hannahjin
Copy link

I set my eslint config to have 2 new lines after imports using newline-after-import plugin. We are also allowing decorator syntax with @.
Currently, it is not counting decorator as a line of code. Only one new line appears after import group if the code block starts with a decorator.

Currently

import pick from 'ramda'

@withRouter
export default class MyComponent extends React.Component {}

Want

import pick from 'ramda'


@withRouter
export default class MyComponent extends React.Component {}
@ljharb
Copy link
Member

ljharb commented Jan 19, 2018

Presumably:

import pick from 'ramda'
export default class MyComponent extends React.Component {}

autofixes to:

import pick from 'ramda'


export default class MyComponent extends React.Component {}

?

If so, this seems like a bug.

@hannahjin
Copy link
Author

In the above case, it works as expected and autofixes to 2 new lines after import. However, when there's a decorator before the export, there is only one blank line between the import and the decorator.

@atos1990
Copy link

atos1990 commented Jul 17, 2018

I have the same problem. In the source code of this rule I found this code

function checkForNewLine(node, nextNode, type) {
      if (isClassWithDecorator(nextNode)) {
        nextNode = nextNode.decorators[0];
      }
function isClassWithDecorator(node) {
  return node.type === 'ClassDeclaration' && node.decorators && node.decorators.length;
}

In the case with default export class node has type "ExportDefaultDeclaration". So, function isClassWithDecorator returned false

@ljharb
Copy link
Member

ljharb commented Jul 17, 2018

@atos1990 that seems like a good test case and fix - want to submit a PR?

@atos1990
Copy link

@ljharb, yes, no problem

atos1990 pushed a commit to atos1990/eslint-plugin-import that referenced this issue Jul 17, 2018
atos1990 pushed a commit to atos1990/eslint-plugin-import that referenced this issue Jul 18, 2018
atos1990 pushed a commit to atos1990/eslint-plugin-import that referenced this issue Jul 19, 2018
atos1990 pushed a commit to atos1990/eslint-plugin-import that referenced this issue Jul 25, 2018
@waitingsong
Copy link

I have the same problem with options

  import/newline-after-import: [2, { "count": 2 } ]

code:

import { Context, config, controller, get, provide } from 'mymodule'
@provide()
@controller('/')
export class HomeController {
.....
.....
}

@TrejGun
Copy link

TrejGun commented Nov 3, 2019

hey guys, this is still an issue! can we have this fixed?

ljharb pushed a commit to atos1990/eslint-plugin-import that referenced this issue Apr 24, 2020
@ljharb ljharb closed this as completed in b307c7c Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants