Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Don't leave blank lines when no-unused-variable autofix removes whole import #2901

Merged
merged 3 commits into from Jun 15, 2017

Conversation

pablonete
Copy link
Contributor

PR checklist

Overview of change:

When an unused import is deleted, the line break is removed too.
Unless there are more sentences in the same line, so the break is preserved.

Is there anything you'd like reviewers to focus on?

  • Can you think on other scenarios we need to cover?
  • This is my first time contributing to TSLint and consuming TS compiler API. Let me know if there's something that can be improved.

CHANGELOG.md entry:

"[enhancement] no-unused-variable: Don't leave empty lines when import is removed"

@palantirtech
Copy link
Member

Thanks for your interest in palantir/tslint, @pablonete! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

let end = importNode.getEnd();
if (ctx.sourceFile.getLineAndCharacterOfPosition(start).character === 0 &&
ctx.sourceFile.getLineEndOfPosition(end) === end) {
end++;
Copy link
Contributor

Choose a reason for hiding this comment

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

that will only work if you're using \n. if there's \r\n, it will only remove \r

alternative to end++:

const nextLine = ctx.sourceFile.getLineAndCharacterOfPosition(end).line + 1;
const lineStarts = ctx.sourceFile.getLineStarts();
if (lineStarts.length !== nextLine) {
    end = lineStarts[nextLine];
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice suggestion, done!

Copy link
Contributor

@adidahiya adidahiya left a comment

Choose a reason for hiding this comment

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

thanks @pablonete!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants