Removing unused imported name leaves double space inside braces
See original GitHub issueUsing the unused-imports/no-unused-imports-ts
rule, plugin version 0.1.2. Please let me know if I need to provide full config or some other data.
This happens if the removed item is the first or the middle one. If the last item is unused, it’s removed correctly (trailing comma removed and no double space) – but maybe that’s the result of my other rules fixing the trailing comma?
Example 1:
// file:
import { IsInt, IsOptional, IsString } from 'class-validator';
IsOptional; IsString;
// is fixed to this (note double space after brace):
import { IsOptional, IsString } from 'class-validator';
IsOptional; IsString;
Example 2:
// file:
import { IsInt, IsOptional, IsString } from 'class-validator';
IsInt; IsString;
// is fixed to this (note double space after IsInt):
import { IsInt, IsString } from 'class-validator';
IsInt; IsString;
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Unnecessary imports should be removed - SonarSource Rules
Unused and useless imports should not occur if that is the case. Leaving them in reduces the code's readability, since their presence can...
Read more >Standard rules - Ktlint
Enum entry names should be uppercase underscore-separated names. ... Imports ordered consistently (see Custom ktlint EditorConfig properties for more).
Read more >Google Sheets: remove the same text or certain characters ...
Trim whitespaces, remove other characters and text in Google Sheets from different positions of multiple cells at once.
Read more >Eslint adds unnecessary space between braces, Prettier ...
I've had very similar error, but in my case default VSCode TypeScript formatter was messing with braces. In .vscode/settings.json add:
Read more >RFC 6020: YANG - A Data Modeling Language for the ...
YANG Example: leaf host-name { type string; description "Hostname for this ... If the double-quoted string contains a line break followed by space...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have fixed this, but decided that it should just remove the whitespace before the unused import. That means it wont fix if there is multiple spaces after the comma. Also it wont add in spaces if there is no space after the comma.
@sweepline which sorting rule are you using?
A workaround for this issue with spaces is the
no-multi-spaces
rule autofixer, but it’s not so simple for #7 with newlines. I’m using theimport/order
rule from eslint-plugin-import, with import grouping configured. It does fix undeleted empty lines within an import group, but it doesn’t fix empty lines on the top of the file or double empty lines between groups (I haveno-multiple-empty-lines
andimport/newline-after-import
set to 2, an old Python habit 😃 ); it also doesn’t help for the empty lines inside braces, after removing items from multi-item imports (btw, what’s the correct wording for these “items” here?)