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.

Mixing spaces and tabs—allowed?

See original GitHub issue

I’m opening this to better track thinking about how to (if at all) mix spaces and tabs.

The simplest case I can see is the following:

\tA
   B

The first is a tab indentation, and the second is three spaces. Is B a child of A or are they on the same indentation?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
xkortexcommented, May 14, 2020

Yeah, that could work, albeit at a bit of extra complexity. Each TLI (top level item, direct children of the document, regex ^\S.*$) would look for its first child and then set a flag for indentation type. To check for alternate-whitespace siblings, you could split the document up and process each TLI as a separate sub-document, and assert that you don’t mix them within each subdoc. This could potentially give you speed ups if you have a multithreaded implementation (e.g. golang/rust), even outside this issue.

OTOH, checking for mixed tabs and spaces is just a matter of two regexes.

You could possibly “cheat” by converting \t to 2 or 4 spaces iff there are no tabs and spaces in the same gutter, eg \t\t⎵⎵ ⎵\t etc would be forbidden. Though that gives unreliable behavior on siblings that alternate tabs/spaces.

My $0.02 is allow only one per document until you get more of the spec hammered out, then return to tackle it, if there’s demand for it. But since the behavior of most editors out there is to either alias the key as either \t OR insert N spaces, I really don’t see this use case showing up that frequently.

1reaction
xkortexcommented, May 11, 2020

IMHO, don’t let it be user-configurable. I’m not sure how you’d enable that, other than in-file #pragma style parser-directives, which is almost always the wrong choice.

Also purely opinion, do what YAML does and ban \t tabs.

Why does YAML forbid tabs?

Tabs have been outlawed since they are treated differently by different editors and tools. And since indentation is so critical to proper interpretation of YAML, this issue is just too tricky to even attempt. Indeed Guido van Rossum of Python has acknowledged that allowing TABs in Python source is a headache for many people and that were he to design Python again, he would forbid them.

If you do decide to allow tabs, I would just throw an exception if they are mixed. That’s the price one pays for such a habit :p.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to supress error: Mixed spaces and tabs? - Stack Overflow
It means that in your code indentation (which are invisible characters) you are using a mix of tabs and spaces. It should be...
Read more >
no-mixed-spaces-and-tabs - Pluggable JavaScript Linter
This rule disallows mixed spaces and tabs for indentation. ... "smart-tabs" allows mixed tabs and spaces when the spaces are used for alignment....
Read more >
Mixing Tabs & Spaces - Trey Hunner
Mixing Tabs & Spaces · Indentation · Some programmers just want to mix tabs and spaces · Indentation doesn't always matter · Same...
Read more >
what does the warning: mixed spaces and tabs mean?
The code runs fine but I get the warning message “mixed spaces and tabs” I've tried googling it but I can find a...
Read more >
What are the downsides of mixing tabs and spaces? [duplicate]
Yes, you can freely intermix tabs and spaces, and high-quality editors like EMACS handle it perfectly. EMACS properly has a hacking-backspace ...
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