question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Removing unused imported name leaves double space inside braces

See original GitHub issue

Using 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:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sweeplinecommented, Oct 23, 2020

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.

1reaction
quezakcommented, Apr 1, 2020

@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 the import/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 have no-multiple-empty-lines and import/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?)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found