Mixing spaces and tabs—allowed?
See original GitHub issueI’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:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.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.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.