oderwat / vscode-indent-rainbow

Extension which shows indentation with a faint rainbow colored background to make them more readable
MIT License
419 stars 58 forks source link

Treat a mixture of tabs and spaces as an error. #39

Closed wraith13 closed 5 years ago

wraith13 commented 5 years ago

I hate a mixture of tabs and spaces!

new screenshot: image

oderwat commented 5 years ago

I like it personally. But I fear that this is a feature which needs to be gated or even not implemented at all.

I ran into problems because this plugin was / is not meant to be a linter / checker tool. Basically I came to the conclusion that the plugin should not do any lint / checking and just colorise the indents.

See: Other people may not hate a mix between spaces and tabs. Or they can't avoid it. Even if gated behind a config setting, people may want it to be enabled for some but not all files.

So I would propose that one needs at least to define a non empty color setting for this to be enabled, similar to the now gated error for the even tab size. The setting needs to be documented and If could be on by default (because I like it.. haha).

wraith13 commented 5 years ago

Do you mean that there is a possibility of merge if I add setting items and document that enable this function?

Are that settings like this good?

  "indentRainbow.enabledMixBetweenSpacesAndTabsColor": true,
  "indentRainbow.mixBetweenSpacesAndTabsColor": "rgba(128,32,32,0.3)",
oderwat commented 5 years ago

Yes that what I meant. I think we only need the "mixBetweenSpacesAndTabsColor" and if thats the empty string the functionality should be inactivated. I am thinking about something similar for the errorColor. Maybe the mix could simply be named "indentRainbow.tabmixColor".

wraith13 commented 5 years ago

I got it! I will fix this code to like that, later!

wraith13 commented 5 years ago

I did it! But my English is very fxxking, please correct if there are strange English in README.md and package.json .

oderwat commented 5 years ago

Looks good. Give me some time to fix the english (slightly) and create a new release. And thank you for your contribution!

oderwat commented 5 years ago

This modification caused quite some problems because of your code to detect the "real" indentation character from the actual source code (See #52). I changed it and it will now not infer this anymore. Until there is a better way to check if there should be spaces or tabs it will only detect interline mixing of them.

wraith13 commented 5 years ago

I am very sorry.

I recently wrote the same kind of VS Code extension. We had to do something like this code.

let totalSpaces = 0;
let totalTabs = 0;
regExpExecToArray
(
    /^([ \t]+)([^\r\n]*)$/gm,
    text
)
.forEach
(
    match =>
    {
        indents.push
        (
            {
                index: match.index,
                text: match[1],
                body: match[2]
            }
        );
        const tabs = match[1].replace(/ /g, "").length;
        const spaces = match[1].length -tabs;
        totalSpaces += spaces;
        totalTabs += tabs;
    }
);
const isDefaultIndentCharactorSpace = totalTabs *tabSize <= totalSpaces;
oderwat commented 5 years ago

Yeah but this would still infer tabs when there are more of them than spaces even when I set the editor to spaces or the other way around. We need a way to read if from the editor what the user did choose for the particular file :(