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

Fixes whitespace check-module to properly lint and fix errors #2825

Merged
merged 4 commits into from Jun 10, 2017

Conversation

canufeel
Copy link
Contributor

@canufeel canufeel commented May 25, 2017

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:

import {A} from './B';
import { A} from './B';
import {A } from './B';
import {A,B} from './B';

and fix those to the following form respectively:

import {A} from './B'; //-> import { A } from './B';
import { A} from './B'; //-> import { A } from './B';
import {A } from './B'; // -> import { A } from './B';
import {A,B} from './B'; // -> import { A, B } from './B';

This PR addresses the issue described above.

CHANGELOG.md entry:

[bugfix] whitespace fix whitespace "check-module" to properly lint and fix errors (#2401)

@palantirtech
Copy link
Member

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
Copy link
Contributor

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.

Copy link
Contributor Author

@canufeel canufeel May 26, 2017

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.

Copy link
Contributor

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.

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.

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
Copy link
Contributor

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.

@adidahiya
Copy link
Contributor

friendly ping @canufeel

@canufeel
Copy link
Contributor Author

canufeel commented Jun 3, 2017

@adidahiya Hey hi! Would try to find some time and work on it tomorrow.

Petr Kosikhin and others added 2 commits June 10, 2017 15:13
…whitespace import rule based on token and not on node itself for the last node in import
@canufeel
Copy link
Contributor Author

@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 😉

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.

nice, thanks @canufeel!

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