SublimeLinter-stylelint icon indicating copy to clipboard operation
SublimeLinter-stylelint copied to clipboard

Error column is off by one for each emoji earlier on the line (stylelint counts UTF-16 units)

Open dpc00 opened this issue 2 months ago • 1 comments

Error column is off by one for each emoji (non-BMP character) earlier on the line: stylelint counts UTF-16 units

Version: SublimeLinter-stylelint 3.x from Package Control, stylelint 17.15.0, SublimeLinter 4, Sublime Text 4215 on Windows. Reproduced in a clean install.

.stylelintrc.json:

{"rules": {"color-named": "never", "declaration-no-important": true}}

a.css (UTF-8):

a {
  content: "é😀"; color: red; margin: 0 !important
}

stylelint --formatter json --stdin-filename a.css < a.css reports (line, column, endColumn):

2 26 29 color-named
2 41 51 declaration-no-important

red starts at character 25 (1-based) of the line as Sublime counts, and !important at 40. stylelint's numbers are one higher because 😀 (U+1F600) is two UTF-16 code units in the JavaScript string, and Sublime counts characters. The plugin uses column and endColumn as they are, so in Sublime the highlights are shifted one character to the right (start offsets 0-based, as SublimeLinter reports them):

  • color-named: start 25 (expected 24), highlighting ed; instead of red;
  • declaration-no-important: start 40 (expected 39), highlighting important instead of !important.

é (one UTF-16 unit) causes no shift, and each additional emoji before the error moves it one more character.

Suggested fix: convert col and end_col in find_errors (or in reposition_match) using the source line, by walking the line and counting every character above U+FFFF twice, so that UTF-16 offsets become character offsets. The same problem is reported for SublimeLinter-tslint, -javac and -coffee (with PRs for the first two), and a fix was merged for SublimeLinter-xmllint (bytes). I can prepare a PR if you would like one.

dpc00 avatar Sep 30 '26 00:09 dpc00

Ack, you can try a fix.

kaste avatar Sep 30 '26 07:09 kaste