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

Added support for correctly ordering unknown types e.g. custom aliases #1375

Merged
merged 3 commits into from Jun 11, 2019

Conversation

Projects
None yet
3 participants
@swernerx
Copy link
Contributor

commented Jun 6, 2019

We figured out that the auto-fix feature of the "order" rule destroyed our custom imports which are using a custom babel-module resolver. Settings for the resolver:

'import/resolver': {
  'babel-module': {
    extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
    alias: {
      '-': './src/',
    },
  },
},

Until now, unknown import types were sorted problematically by the "order" feature. These were not assigned to a common group but loosely added or kept between the other imports. This was especially problematic when using the 'newlines-between'-feature. In this case there was an additional line feed after each unknown import. See examples below.

Example:

import { get } from 'lodash'
import { FormError } from '-/components/Product/Configuration/FormError'
import React, { PureComponent } from 'react'
import { ModalContainer } from '../../../Modal/ModalContainer'
import { addEvent, removeEvent } from '-/common/tracking/basket'
import { ChangeItem } from '-/components/Basket/ChangeItem'
import getBasketProduct from './BasketProduct.gql'
import UpdateItemInBasket from './UpdateItemInBasket.gql'

Previous version output:

import { get } from 'lodash'

import { FormError } from '-/components/Product/Configuration/FormError'

import React, { PureComponent } from 'react'

import { ModalContainer } from '../../../Modal/ModalContainer'

import { addEvent, removeEvent } from '-/common/tracking/basket'

import { ChangeItem } from '-/components/Basket/ChangeItem'

import getBasketProduct from './BasketProduct.gql'
import UpdateItemInBasket from './UpdateItemInBasket.gql'

New version output:

import { get } from 'lodash'
import React, { PureComponent } from 'react'

import { FormError } from '-/components/Product/Configuration/FormError'
import { addEvent, removeEvent } from '-/common/tracking/basket'
import { ChangeItem } from '-/components/Basket/ChangeItem'

import { ModalContainer } from '../../../Modal/ModalContainer'

import getBasketProduct from './BasketProduct.gql'
import UpdateItemInBasket from './UpdateItemInBasket.gql'

I updated the docs accordingly, added new tests and made sure that nothing else broke. The change itself is pretty small but it dramatically changes the result for these situations.

swernerx added some commits Jun 6, 2019

@coveralls

This comment has been minimized.

Copy link

commented Jun 6, 2019

Coverage Status

Coverage remained the same at 97.803% when pulling 4827e72 on swernerx:fix/order-unknown-types into 15e5c61 on benmosher:master.

1 similar comment
@coveralls

This comment has been minimized.

Copy link

commented Jun 6, 2019

Coverage Status

Coverage remained the same at 97.803% when pulling 4827e72 on swernerx:fix/order-unknown-types into 15e5c61 on benmosher:master.

@coveralls

This comment has been minimized.

Copy link

commented Jun 6, 2019

Coverage Status

Coverage remained the same at 97.803% when pulling d81a5c8 on swernerx:fix/order-unknown-types into 15e5c61 on benmosher:master.

Show resolved Hide resolved docs/rules/order.md Outdated
@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Jun 11, 2019

I’m a bit confused - what code is generating “unknown”? Is this a type that we’ve always generated but simply not allowed to be in the config list?

@swernerx

This comment has been minimized.

Copy link
Contributor Author

commented Jun 11, 2019

Yes, it seems like this is exactly the case.

@swernerx

This comment has been minimized.

Copy link
Contributor Author

commented Jun 11, 2019

@ljharb

ljharb approved these changes Jun 11, 2019

Copy link
Collaborator

left a comment

Simple semver-minor, thanks

@ljharb ljharb added the semver-minor label Jun 11, 2019

@ljharb ljharb merged commit 45bfe47 into benmosher:master Jun 11, 2019

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage remained the same at 97.803%
Details
@swernerx

This comment has been minimized.

Copy link
Contributor Author

commented Jun 12, 2019

Thanks! Can you tell when the new version will be released?

@swernerx swernerx deleted the swernerx:fix/order-unknown-types branch Jun 12, 2019

@ljharb

This comment has been minimized.

Copy link
Collaborator

commented Jun 12, 2019

i can't, no, but this PR will be in the next one, whenever that is :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.