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

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

Open dpc00 opened this issue 2 months ago • 2 comments

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

Version: SublimeLinter-tslint 3.x from Package Control, tslint 6.1.3 (typescript 5), SublimeLinter 4, Sublime Text 4215. Reproduced in a clean install. (I know TSLint is deprecated; the plugin is still on Package Control and the problem is easy to reproduce, so I am reporting it.)

tslint.json:

{"rules": {"quotemark": [true, "double"], "semicolon": [true, "always"], "no-var-keyword": true}}

a.ts (UTF-8):

const a: string = "é😀"; var x = 'q'
const b = '😀' + 'z';

tslint --format verbose a.ts:

ERROR: (no-var-keyword) a.ts[1, 26]: Forbidden 'var' keyword, use 'let' or 'const' instead
ERROR: (quotemark) a.ts[1, 34]: ' should be "
ERROR: (semicolon) a.ts[1, 37]: Missing semicolon
ERROR: (quotemark) a.ts[2, 11]: ' should be "
ERROR: (quotemark) a.ts[2, 18]: ' should be "

In line 1, var starts at character 25 (1-based) as Sublime counts, but TSLint says 26, because 😀 (U+1F600) is two UTF-16 code units in TypeScript's positions and one character in Sublime. The plugin uses the column as it is, so the highlights on lines 1 and 2 after the emoji land one column too far right. As shown by the plugin (0-based start offsets):

  • line 1, var is highlighted as ar (start 25, expected 24);
  • line 1, the ' of 'q' is highlighted as q (start 33, expected 32) and the missing semicolon after the last character (start 35, expected 34);
  • line 2, the second quote is highlighted as z (start 17, expected 16).

The first quote on line 2 comes before the emoji and is right, and é (one UTF-16 unit) causes no shift. Each additional emoji adds one more column.

Suggested fix: override reposition_match(self, line, col, m, vv), take the line via vv.select_line(line), and convert the UTF-16 offset to a character offset by walking the line and counting every character above U+FFFF as two units. The same issue exists in other linters that use TypeScript or JavaScript positions. I can prepare a PR if you would like one.

dpc00 avatar Sep 29 '26 21:09 dpc00

Ack, you can send a PR

kaste avatar Sep 29 '26 22:09 kaste

Claude reports: no PR needed, 1.7.0 already fixes this. Thank you for the fix.

Sublime Text build 4215 (Windows), SublimeLinter 4.30.1, tslint 6.1.3 with typescript 5.9.3, installed locally next to the files. I installed SublimeLinter-tslint 1.7.0 from Package Control (its linter.py has column_unit = 'utf16') and opened the a.ts and tslint.json from the report. On line 1 var is now highlighted whole (before it showed as ar), the opening quote of 'q' and the missing semicolon after it are on the right characters, and on line 2 both quotes are highlighted (before the second showed as z). The status bar shows tslint(e:5), the five errors tslint reports on the command line.

I did not run 1.6.4 here for comparison; the earlier behaviour is from the original report. This issue can be closed.

dpc00 avatar Oct 29 '26 20:10 dpc00