-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 typescript flow rule #2614
base: main
Are you sure you want to change the base?
New typescript flow rule #2614
Conversation
added options, TS version check, and the logic for two simple cases where we prefer separate or type modifier import
…the namespace is exported as type= TsTypeAliasDefinition
The default rule had invalid test case where default import was tried, because I have added default export for typescript-flow cases, the test case broke. I have added new file with no default export and substituted it for ./typescript used in default rule
How do I make |
The new rule needs to be added to the shared configs in |
Not sure what is causing errors :/. I tried to replicate them on my local machine (node v10, eslint v6), but had many many test cases failing, and completely different error (mine was ELIFECYCLE error). Was wondering maybe you might have any thoughts? |
It seems like the tests that are failing are eslint 6 or 7, combined with node < 12. The new TS parser will only be installed on eslint >= 6, and will be v3 on node 10 and 11, and probably v2 on node < 10. On eslint 6, the old TS parser will be present on v20. On node < 8, eslint-import-resolver-typescript will be v1.0.2. The easiest way to replicate this locally is to run the |
I believe import type { T } from "./module"; // ok
import { type T } from "./module"; // error ts(1371) |
It'd be great to rebase this, so any remaining failing tests can be resolved. |
apologies this PR got abandoned... Would you say there is still a need for this rule? Suggestion for the rule came from here #2390. |
There's already a rule for whether you use |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2614 +/- ##
==========================================
+ Coverage 95.20% 95.48% +0.28%
==========================================
Files 82 83 +1
Lines 3565 3700 +135
Branches 1245 1269 +24
==========================================
+ Hits 3394 3533 +139
+ Misses 171 167 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Draft version of the new rule proposed at #2390.
This new rule allows for changing between inline type imports (type modifiers introduced in TS 4.5) and separate type import statements (introduced in TS 3.8). The rule also fixes imports to the preferred option. The rule assumes that user specifies himself which imports are type imports. For example, if there is
enum
that is used as a type, user should import the enum as type. This rule does not check the usage of imports, but rather helps to enforce consistent style for importing types.The rule has 2 strict options (inline and separate) and one preferred flow option. In preferred flow option, user passes array of inline and separate in the order of preference. Rule checks if inline is supported, if not, falls back to "separate" as an option. If separate comes first in the array, then resume as if there is strict "separate" option.
Strict option enforces either inline type imports with type modifiers, or separate type imports.
Rule schema for strict options: we pass single string to the rule
separate option
Definition: All type imports must be imported in a separate
import type
statement.The following patterns are not considered warnings:
The following patterns are considered warnings:
inline option
Definition: All type imports must be inline imported with type modifiers.
Patterns that do not raise the warning:
Patterns are considered warnings and fixed:
Questions:
P.S. Rule name can be changed. Changes to
ExportMap
to be removed