Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Start linting for double spaces#20820

Merged
4 commits merged into
mastermicrosoft/TypeScript:masterfrom
no-double-spacemicrosoft/TypeScript:no-double-spaceCopy head branch name to clipboard
Jan 8, 2018
Merged

Start linting for double spaces#20820
4 commits merged into
mastermicrosoft/TypeScript:masterfrom
no-double-spacemicrosoft/TypeScript:no-double-spaceCopy head branch name to clipboard

Conversation

@ghost

@ghost ghost commented Dec 20, 2017

Copy link
Copy Markdown

I think @sandersn mentioned before that he expected the linter to catch double spaces in code. A rule outright banning that would result in a lot of lint failures, so I've added exceptions for our frequent alignment of = signs and other common uses of double spaces.

@weswigham weswigham left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems ok, some minor comments.

}
// Allow common uses of double spaces
// * To align `=` or `!=` signs
// * To alling comments at the end of lines

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Typo: alling -> align

}

function countDoubleSpaces(line: string): number {
let count = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not just (line.match(/\s\s+/g) || []).length?

@ghost ghost force-pushed the no-double-space branch from aeab99b to 1b43adf Compare December 21, 2017 20:16
idx++;
count++;
}
return (line.match(/\s\s/g) || []).length;

@weswigham weswigham Dec 21, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This matches on a b (4 spaces between the letters, since GH compacts it) twice. Is that intentional?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The goal of this function is to ignore the rule on uses of multiple spaces that are probably not just accidentally pressing the space bar twice -- we could eliminate this entirely in a followup PR, but if we change to /\s\s+/g we would get some new errors right now.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

There are multiple ways we might want to make this rule stricter, such as not allowing aligning = outside of enums (or even within them).

@weswigham weswigham Dec 21, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the heuristic here supposed to be the length of a run of whitespace (for marking that specific run as an error), or the number of individual >1 length whitespace runs on the line (for marking the all instances on the line as an error)? As is, it's half the total length of each >1 length run of whitespace on the line, which seems incorrect, since it's neither of those.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've fixed the remaining cases, so we don't need this function any more.

Comment thread src/compiler/parser.ts Outdated
// the original grammar) by making sure that if we see an ObjectCreationExpression
// we always consume arguments if they are there. So we treat "new Foo()" as an
// object creation only, and not at all as an invocation) Another way to think
// object creation only, and not at all as an invocation). Another way to think

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the intent was probably for the ) to be a . since the wordy author in the parser also seems to use double spaces after periods, and there's no open parenthesis.

@ghost ghost merged commit 6f2ba15 into master Jan 8, 2018
@ghost ghost deleted the no-double-space branch January 8, 2018 16:52
This was referenced Jan 8, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
This pull request was closed.
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.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.