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.

Enforce the amount of whitespace surrounding keywords.

See original GitHub issue

Given the following tab-indented source code:

function foo() {
	if (true) {
		try {
			bar();
		}
		catch (err)
		{
			baz();
		}
	}
}

Using brace-style to use "1tbs", we end up with tabs around the catch keyword.

function foo() {
	if (true) {
		try {
			bar();
		}		catch (err)		{
			baz();
		}
	}
}

It doesn’t seem possible to fix this with the existing eslint rules:

  • keyword-spacing only asserts that there’s a non-zero amount of whitespace around keywords
  • no-multi-spaces ignore tabs
  • no-tabs isn’t useful because we’re using tabs for indentation too

Possible solutions:

  • add an option to keyword-spacing to enforce exactly one space (my suggestion)
  • add an option to no-tabs to only flag tabs that aren’t at the beginning of the line (suggested by @platinumazure)
  • generalise no-multi-spaces to work for arbitrary whitespace, not just spaces

Tested on eslint 3.10.2.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, May 4, 2017

Hi @bardware, the changes should be in this week’s release.

0reactions
bardwarecommented, May 8, 2017

Seen it working in Alpha.2. Very nice, thanks alot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

keyword-spacing - ESLint - Pluggable JavaScript Linter
This rule enforces consistent spacing around keywords and keyword-like tokens: as (in module declarations), async (of async functions), await (of await ...
Read more >
Rules Reference — SQLFluff 1.4.5 documentation
Operators should be surrounded by a single whitespace. This rule is sqlfluff fix compatible. Groups: all , core. Anti ...
Read more >
Adding White Space in Microsoft Word to Improve PDF ...
To add white space around an image using Paragraph Styles: In the Ribbon, select the Home tab, then in the Styles section select...
Read more >
Search keywords in ElasticSearch 7.6 with whitespace
I am trying to implement in ElasticSearch 7.6 a search based on city names but I have a problem with those words containing...
Read more >
Whitespace · Styleguide JavaScript
Indentation Character · Before Blocks · Around Keywords · Infix Operator Spacing · Newline · Chains · After Blocks · Padded Blocks.
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