-
Notifications
You must be signed in to change notification settings - Fork 889
Fixes whitespace check-module to properly lint and fix errors #2825
Fixes whitespace check-module to properly lint and fix errors #2825
Conversation
…t statements with curlies
Thanks for your interest in palantir/tslint, @canufeel! 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. |
tslint.json
Outdated
"check-branch", | ||
"check-decl", | ||
"check-operator", | ||
// "check-module", <- this rule is not compatible with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it should be. If you have:
import {
a,
b,
} from "foo";
I would expect the newline between b,
and }
to count as whitespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄 Let's face the facts. Newline is newline. Whitespace is whitespace. If newline counts as a whitespace should we treat it as a trailing whitespace as well and trigger the error here?
I think there is a room for new rule here - something like treat-newline-as-whitespace
but otherwise i would really think twice by making newline to be treated as whitespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline is newline. Whitespace is whitespace.
I don't think it's so black and white. For the purposes of the whitespace rule where you want to see a space after {
and before }
in a single-line import statement, the rule should consider newlines in multiline import statements as whitespace. I still expect the following to produce failures:
import {a,
~
b} from "foo";
~
but @andy-hanson's example should be valid.
Being pedantic about the semantics of what a "whitespace" is vs. what a "newline" is doesn't help us here; what matters most is the intent of the lint rule and the formatting or style consistency it helps us achieve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly looks good! I have the same concerns as andy though.
tslint.json
Outdated
"check-branch", | ||
"check-decl", | ||
"check-operator", | ||
// "check-module", <- this rule is not compatible with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline is newline. Whitespace is whitespace.
I don't think it's so black and white. For the purposes of the whitespace rule where you want to see a space after {
and before }
in a single-line import statement, the rule should consider newlines in multiline import statements as whitespace. I still expect the following to produce failures:
import {a,
~
b} from "foo";
~
but @andy-hanson's example should be valid.
Being pedantic about the semantics of what a "whitespace" is vs. what a "newline" is doesn't help us here; what matters most is the intent of the lint rule and the formatting or style consistency it helps us achieve.
friendly ping @canufeel |
@adidahiya Hey hi! Would try to find some time and work on it tomorrow. |
…whitespace import rule based on token and not on node itself for the last node in import
@adidahiya @andy-hanson Hey hi! You might want to have a look at it now. Described concerns seems to have been addressed. Let me know 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, thanks @canufeel!
Fixes whitespace check-module to properly lint and fix errors for import statements with curlies
PR checklist
Overview of change:
With
"whitespace": [true, "check-module"]
we should treat the following as errors:and fix those to the following form respectively:
This PR addresses the issue described above.
CHANGELOG.md entry:
[bugfix]
whitespace
fix whitespace"check-module"
to properly lint and fix errors (#2401)