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

[New] no-duplicates: add combineTypeImports option to de-duplicate flow type imports #2229

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

christianvuerings
Copy link
Contributor

Description

#334 always duplicated flow type imports. In this diff we add the combineTypeImports option to be able to de-duplicate flow type imports.

TypeScript support can be added later, for now we only support combining regular & flow type imports.

Fixes: #909

Related PRs / Issues

@codecov
Copy link

codecov bot commented Sep 17, 2021

Codecov Report

Merging #2229 (806a09b) into main (7c382f0) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2229      +/-   ##
==========================================
+ Coverage   84.02%   84.03%   +0.01%     
==========================================
  Files          94       94              
  Lines        3017     3020       +3     
  Branches      898      900       +2     
==========================================
+ Hits         2535     2538       +3     
  Misses        482      482              
Impacted Files Coverage Δ
src/rules/no-duplicates.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7c382f0...806a09b. Read the comment docs.

@@ -61,6 +61,25 @@ import SomeDefaultClass from './mod?minify'
import * from './mod.js?minify'
```

### combineTypeImports

By default, this rule ignores flow & typescript type imports. However you can use the option `combineTypeImports` to combine type imports with regular imports.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain why this is a good thing, or how it would apply to TS? In TS, it's preferred to use import type for all type imports, and import only for value imports.

Does Flow not have a separate import type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain why this is a good thing, or how it would apply to TS? In TS, it's preferred to use import type for all type imports, and import only for value imports.

TypeScript allows to not use import type for type imports. typescript-eslint has a rule to specify the syntax: typescript-eslint/consistent-type-imports. As you are saying it's not the preferred way, so it shouldn't be the default, but it is something users might want to set.

The main reason we would like to combine type and regular imports in our flow code is to make it easy for developers to see what the dependencies on a certain file. Some of our files have both regular and type exports so when they are imported, it's confusing to not see them combined:

Before

// @flow
import { type I18nContext } from 'app/packages/i18n/useI18n';
// Other imports
import useI18n, { I18nContextProvider } from 'app/packages/i18n/useI18n';

After

// @flow
import useI18n, { I18nContextProvider, type I18nContext } from 'app/packages/i18n/useI18n';

Does Flow not have a separate import type?

Flow supports both import type Foo and import { type Foo } syntax.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can’t imagine why you’d prefer the combined form over the separate import vs import type statements, but at least i understand what the option would do.

Since they can’t be combined in TS, this option would only ever be useful for Flow. I’m not sure supporting only flow is worth the complexity at this time due to the current state of Flow usage in the ecosystem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb understood, closing this PR for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like in TS 4.5+, they can be combined. I'll reopen.

@christianvuerings
Copy link
Contributor Author

Closing since I no longer plan to work on this. Anyone should feel free to open a new PR and can use this PR as inspiration.

@ljharb
Copy link
Member

ljharb commented Jan 22, 2024

That’s fine, but let’s leave it open so this PR can be updated later :-)

@ljharb ljharb reopened this Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Request: option to let no-duplicates force type & normal imports to be de-duplicated
2 participants