victorporof / Sublime-JSHint

JSHint Gutter for Sublime Text 2 and 3 via node.js
https://github.com/victorporof/Sublime-JSHint
683 stars 71 forks source link

When indenting with tabs, wrong symbol gets squiggly underline #34

Open trevordixon opened 11 years ago

trevordixon commented 11 years ago

screen shot 2013-08-15 at 11 55 45 am

As you can see in the screenshot, the wrong symbol is underlined. The word "template" should be underlined.

The reason for this is that jshint considers tabs 4 columns wide (https://github.com/jshint/jshint/issues/805), but the col parameter in Sublime's text_point funtion "is interpreted as the number of characters to advance past the beginning of the row."

Setting "indent": 1 in .jshintrc fixes the problem for me, but it would be better if this worked by default.

victorporof commented 11 years ago

Ok, so jshint prefs like "indent" should depend on the current buffer's indentation settings.

trevordixon commented 11 years ago

Yes, I think that's a good solution. If there's no .jshintrc indent option set, set it based on the buffer's indentation settings (1 for tabs or as many spaces as constitute an indent).

zakdances commented 11 years ago

+1. Every line being pointed to by Sublime-JSHint was wrong until I switched to spaces. It shouldn't prefer one over the other because they're both valid. Can this be fixed to correctly and automatically detect tabs?

zakdances commented 11 years ago

Any progress on this?

albertosantini commented 10 years ago

To underline the correct word (in my context):

...
            regions = []

            for err in errs:
                line_begin = view.text_point(int(err[1]) - 1, 0)
                line_region = view.line(line_begin)
                buf = view.substr(line_region)
                tab_length = len(re.findall("\t", buf))
                isSpacesIndentation = view.settings().get("translate_tabs_to_spaces")
                tab_size = 1
                if (not isSpacesIndentation):
                    tab_size = view.settings().get("tab_size")
                line = int(err[1]) - 1
                col = int(err[2]) - 1 - (tab_size * tab_length) + tab_length

                text_point = view.text_point(line, col)
                region = view.word(text_point)
                regions.append(region)
...

If you go to the error point using the palette, the code above, modified to insert it in the plugin, should work.

Anyway I have a problem with F4, because Sublime does not make the correct calc when it needs to set the cursor; weirdly in the bottom left the column is displayed correctly.

kornelski commented 10 years ago

When Sublime uses tabs adding "indent": 1 to .jshintrc fixes alignment of errors indeed. It would be nice if the plugin did that automatically.

albertosantini commented 10 years ago

I am sorry for the self promotion: https://sublime.wbond.net/packages/Build%20Next After my previous comment I developed the above plugin.