Eslint-plugin-import: newline-after-import not recognizing decorator

Created on 19 Jan 2018  路  7Comments  路  Source: benmosher/eslint-plugin-import

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 {}
bug help wanted

Most helpful comment

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

All 7 comments

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.

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.

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

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

@ljharb, yes, no problem

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 {
.....
.....
}

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

Was this page helpful?
0 / 5 - 0 ratings