eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

[New] `consistent-type-specifier-style`: add rule

Open bradzacher opened this issue 3 years ago • 2 comments

Fixes #2469

Adds a new rule as specced in #2469 To test this I had to bump the TS version to 4.5, as that was the first version that supported inline type specifiers.

bradzacher avatar Jun 09 '22 18:06 bradzacher

image

big oof - testing against all of these old versions of things is really tough to get right

bradzacher avatar Jun 10 '22 05:06 bradzacher

Codecov Report

Base: 95.15% // Head: 95.14% // Decreases project coverage by -0.00% :warning:

Coverage data is based on head (ac4960c) compared to base (7f251b2). Patch coverage: 97.46% of modified lines in pull request are covered.

:exclamation: Current head ac4960c differs from pull request most recent head 2df9be6. Consider uploading reports for the commit 2df9be6 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2473      +/-   ##
==========================================
- Coverage   95.15%   95.14%   -0.01%     
==========================================
  Files          66       67       +1     
  Lines        2828     2907      +79     
  Branches      949      979      +30     
==========================================
+ Hits         2691     2766      +75     
- Misses        137      141       +4     
Impacted Files Coverage Δ
src/rules/consistent-type-specifier-style.js 97.46% <97.46%> (ø)
utils/module-require.js 85.71% <0.00%> (-14.29%) :arrow_down:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar Jun 10 '22 14:06 codecov[bot]

Now that the TS 4.8 release is done, I should be able to get back to this this week (hopefully).

bradzacher avatar Aug 30 '22 01:08 bradzacher

I'm holding off on the next release for this :-) looking forward to you getting back to it.

ljharb avatar Sep 02 '22 20:09 ljharb

assuming test pass - this should be good to go now. I updated the fixer to (a) cleanup unnecessary commas and (b) cleanup empty named blocks

bradzacher avatar Sep 03 '22 13:09 bradzacher

leave behind the empty braces

The fixer should no longer leave behind empty braces.

How does a Flow user who isn't using the inline typeof syntax already, autofix to import typeof?

If I'm understanding your question correctly:

  • If they don't want to use the inline specifiers at all, then they can use the prefer-top-level setting.
  • If they want to use inline type with top-level typeof, the rule does not currently have handling for this (could be a future enhancement if people want it!).

bradzacher avatar Sep 04 '22 08:09 bradzacher

Rebased; looks like this is good to go, pending any "uncovered line" annotations (https://github.com/import-js/eslint-plugin-import/pull/2473#discussion_r963255391 and https://github.com/import-js/eslint-plugin-import/pull/2473#discussion_r963255298)

ljharb avatar Sep 06 '22 05:09 ljharb

https://github.com/microsoft/TypeScript/issues/47118

import type { X } from "...";
import { type X } from "...";

These two lines of code behave differently. Perhaps we should add a special treatment for this.

latin-1 avatar Nov 10 '22 13:11 latin-1

It's not clear what the difference is from that issue. Can you elaborate?

ljharb avatar Nov 10 '22 15:11 ljharb

https://github.com/typescript-eslint/typescript-eslint/issues/6338 I posted more details at the link above. I'm not sure which plugin this should be handled in. It's a mess. We may need two or more passes of code fixes to make it work.

latin-1 avatar Jan 14 '23 11:01 latin-1

eslint on the CLI runs multiple passes, so it's only in an editor that you're likely to run into this problem.

ljharb avatar Jan 14 '23 21:01 ljharb