Javascript editor using tabs instead of spaces

IntelliJ 2016.2.4 (Windows) is behaving weirdly and inconsistently.

On some (but not all) existing Javascript sources, when using the tab key, it tends to insert tab characters despite whitespace settings (both project level and global) being to use spaces.

On new files, it does use spaces...

Same when using refactorings, the generated code blocks in some files are generated with tab characters, in other files with spaces.

While easily corrected (and not a personal problem for me), it is annoying because Sonar is set to report all such tabs as problems (not my decision).

8 comments
Comment actions Permalink

With 'Detect and use existing file indents for editing' option enabled in Settings | Editor | Code Style, Idea automatically checks existing file indents and starts using them instead of indents configured in code style preferences when you press Enter, tab, copy/paste code, etc.. So, if you have your file indented with spaces, they will still be used despite your preferences... I suspect that this might be the issue. Try disabling this option - does the problem persist?

1
Comment actions Permalink

Nope, makes no difference.
Files are indented with spaces, tabs are set to spaces, and still when pressing tab or doing refactorings tabs are inserted instead of spaces in some files.

Files it happens on tend to be files that used to have tabs in them but were refactored to replace tabs with spaces (edit->convert indents).
It's almost as if the editor has an evil memory ;)

0
Comment actions Permalink

With this option disabled, WebStorm should treat all files equally on pressing Tab, etc. Please try reformatting these files using Code | Reformat Code - does the problem persist?

0
Comment actions Permalink

Reformat code reformats the code back to using tabs, despite both options you mention being unchecked (and thus set to use spaces).

This doesn't affect just .js files I noticed yesterday, .java files are also hit by it.

And in the editor->code style->javascript options the preview window shows tab characters for whitespace (as do all the others).

All this on Windows only, on Mac it works as expected.

0
Comment actions Permalink

@Jeroen

Do you have EditorConfig Support plugin enabled and do you have .editorconfig files in your project? Settings from such file(s) will overwrite Code Style settings (the actual nature of such file/plugin).

Otherwise already mentioned 'Detect and use existing file indents for editing' option is the only thing I can think of that perfectly fits your description.

0
Comment actions Permalink

That was it. We have a code standard requiring spaces, and requiring the use of EditorConfig, and I'd (stupidly?) assumed that the EditorConfig configuration would enforce that.

Of course it didn't, it enforces tabs...

0
Comment actions Permalink

@Jeroen

Sorry, I personally did not get what you mean here...

Are you trying to say that your .editorconfig was setup incorrectly? Or it was setup correctly but did opposite job?

As far as I'm aware, settings from .editorconfig for whitespace characters are obeyed just fine in my 2 projects where they are used.

0
Comment actions Permalink

The editorconfig file was supposed to enforce spaces, as that's the policy enforced by sonar etc., but was instead written to enforce tabs.

0

Please sign in to leave a comment.