willhoney7 / eslint-plugin-import-helpers

ESLint plugin to help enforce a configurable order for import statements
288 stars 17 forks source link

Different newline behaviour in 1.0 #10

Closed ai closed 5 years ago

ai commented 5 years ago

ESLint config:

    'import-helpers/order-imports': ['error', {
      groups: [
        ['absolute', 'module'],
        ['parent', 'sibling', 'index']
      ],
      newlinesBetween: 'always'
    }],

Expected code after --fix

let { addPrometheus, addScaling } = require('@evilmartians/logux-server-pro')
let { Server } = require('@logux/server')
let path = require('path')
let fs = require('fs')

Actual code after --fix (also ESLint show error on previous code)

let { addPrometheus, addScaling } = require('@evilmartians/logux-server-pro')

let { Server } = require('@logux/server')

let path = require('path')
let fs = require('fs')

How I can ask the plugin to not force me to insert a newline in this example?

ai commented 5 years ago

@Tibfib seems like plugin have some problem with modules started with @

var CrossTabClient = require('@logux/client/cross-tab-client')

var isFirstOlder = require('@logux/core/is-first-older')

var createStore = require('redux').createStore
var NanoEvents = require('nanoevents')

Here is the same issue. Plugin force me to put newline after @logux/… imports.

willhoney7 commented 5 years ago

Oh, you’re right!

I see the problem. It’s the regular expression here. It’s not recognizing the @ symbol and classifying it correctly. https://github.com/Tibfib/eslint-plugin-import-helpers/blob/80658479f8c0039a02f99a6c20fc4b5af6e7ffe5/src/util/import-type.ts#L5

I’m on my phone now, I’ll see if I can fix it and have a new release within the next couple of days.

Of course, PRs welcome if you have the chance.

ai commented 5 years ago

Sure, I will try to send PR in next 40 minutes

willhoney7 commented 5 years ago

Any other characters you would start an import path with? @ _ \w

I think the regex could either be: /^[_@\w]/ or validate anything not starting with . or / (on my phone and can’t remember the exact regex syntax)

ai commented 5 years ago

I sent PR

https://github.com/Tibfib/eslint-plugin-import-helpers/pull/11