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

[Fix] no-duplicates: ensure autofix avoids excessive newlines #2028

Merged
merged 1 commit into from May 29, 2021

Conversation

ertrzyiks
Copy link
Contributor

@ertrzyiks ertrzyiks commented Apr 13, 2021

Fixes #2027

Each removed import can potentially leave an empty line character. When a module has multiple repeated imports, the output of the autofix includes a gap of empty lines. The number of empty lines are equal to the number of removed imports.

import { One } from '../fragments/one'
import { Two } from '../fragments/two'
import { Three } from '../fragments/three'
import { Four } from '../fragments/four'
import { Five } from '../fragments/five'
import { Six } from '../fragments/six'
import { Seven } from '../fragments/seven'
import { Eight } from '../fragments/eight'
import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'
import { OneDoc } from '../fragments/one'
import { TwoDoc } from '../fragments/two'
import { ThreeDoc } from '../fragments/three'
import { FourDoc } from '../fragments/four'
import { FiveDoc } from '../fragments/five'
import { SixDoc } from '../fragments/six'
import { SevenDoc } from '../fragments/seven'
import { EightDoc } from '../fragments/eight'
export const Vars = any

becomes

import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'

import { One , OneDoc } from '../fragments/one'
import { Two , TwoDoc } from '../fragments/two'
import { Three , ThreeDoc } from '../fragments/three'
import { Four , FourDoc } from '../fragments/four'
import { Five , FiveDoc } from '../fragments/five'
import { Six , SixDoc } from '../fragments/six'
import { Seven , SevenDoc } from '../fragments/seven'
import { Eight , EightDoc } from '../fragments/eight'








export const Vars = any

Remove a new line character if it's immediately after the removed import.

@ertrzyiks ertrzyiks changed the title Add regression test Add regression test for empty lines generated by no-duplicates rule Apr 13, 2021
@ertrzyiks ertrzyiks force-pushed the issue-2027-no-duplicates branch 2 times, most recently from 592a40c to ab5c36e Compare April 13, 2021 07:35
@coveralls
Copy link

coveralls commented Apr 13, 2021

Coverage Status

Coverage increased (+0.06%) to 82.607% when pulling 7aea664 on ertrzyiks:issue-2027-no-duplicates into 998c300 on benmosher:master.

@ertrzyiks ertrzyiks changed the title Add regression test for empty lines generated by no-duplicates rule Remove new line character after removed import during no-duplicates autofix Apr 15, 2021
@ertrzyiks ertrzyiks force-pushed the issue-2027-no-duplicates branch 2 times, most recently from ea2cab3 to d2a7722 Compare April 15, 2021 18:51
@ertrzyiks ertrzyiks marked this pull request as ready for review April 15, 2021 18:54
@ljharb ljharb changed the title Remove new line character after removed import during no-duplicates autofix [Fix] no-duplicates: ensure autofix avoids excessive newlines May 14, 2021
@ljharb ljharb force-pushed the issue-2027-no-duplicates branch 2 times, most recently from ebb3f91 to b48001b Compare May 14, 2021 04:20
@ljharb
Copy link
Member

ljharb commented May 14, 2021

@ertrzyiks looks like these are legit failures. Please mark the PR as "ready for review" when you've got them passing (or ping me if you're stuck)

@ljharb ljharb marked this pull request as draft May 14, 2021 05:01
@ertrzyiks
Copy link
Contributor Author

ertrzyiks commented May 14, 2021

@ljharb as I mentioned #2027 (comment) it seems to me that the auto-fix would need to be too smart to remove the import in a clean way. The failed examples highlighted issues with leading spaces

  import A from 'a'
  import A from 'a'
  import B from 'b'

Becomes

  import A from 'a'
    import B from 'b'

Because I removed only the new line characters. We could either rewrite tests to not have leading spaces and they will pass, or we can clean all spaces that occur before the import. WDYT?

@ljharb
Copy link
Member

ljharb commented May 14, 2021

hmm, that's a good question.

in this case, since import statements are always at the top level of the module, it doesn't make any sense to have leading spaces before import, so i'd say we can just remove them?

@ertrzyiks
Copy link
Contributor Author

Alright, I will update the tests and will mark the PR as ready for review once green. Thanks for the feedback @ljharb

@ertrzyiks ertrzyiks force-pushed the issue-2027-no-duplicates branch 2 times, most recently from 7297422 to b9de5e4 Compare May 16, 2021 11:12
@ertrzyiks ertrzyiks marked this pull request as ready for review May 16, 2021 12:31
@ljharb ljharb force-pushed the issue-2027-no-duplicates branch 2 times, most recently from 9c78340 to 7aea664 Compare May 29, 2021 20:43
@ljharb ljharb merged commit 7aea664 into import-js:master May 29, 2021
@ertrzyiks ertrzyiks deleted the issue-2027-no-duplicates branch May 31, 2021 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

[no-duplicates] additional new lines are generated when the list of imports to squash is long
3 participants