-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vscode and atom highlight locations are unexpected when end location is not provided #12334
Comments
Maybe we can modify rules, because this can benefit formatters as well. However, I"m not sure how formatters behave when reporting those rules. |
I think one of the tricky things with some rules like semi is that there might not be a character to highlight if it"s at the end of the line. Example from above: /* eslint semi: [2, "always"] */
const a = Math.random
// ^ If there"s no whitespace after the last character (and many editors can be configured
// to do this automatically), will VS Code be able to highlight it? |
I have tested that case, report the location of the linefeed (with the end location at the next line) will do well in vscode. |
Unfortunately, it looks like there wasn"t enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
Reopening this because this is actively being worked on. |
Leaving the "evaluating" label on here because we haven"t officially accepted this, but have been evaluating and accepting smaller individual PRs that solve this. |
@eslint/eslint-team, it seems an useful enhancement, can we get one more 👍 to accept this issue? |
Is the decision here to accept this issue as blanket acceptance for PRs to individual rules that add end locations to reports (option 1 in the original issue description) so we don"t have to evaluate them individually? I"ve added my 👍 under that understanding, and if that is indeed the case, then this can be marked as accepted. |
@btmills I think that makes the most sense? Ideally, it would be nice to audit the rules and make a list we can keep track of here. |
Any interest to implement a visualize tester like this to test locations? Or even better add to |
Do you mean snapshot testing ? |
I mean this code frame `␊
1 | function foo() {␊
> 2 | function bar() {}␊
| ^^^^^^^^^^^^ Move function "bar" to the outer scope.␊
3 | }␊
` Easier to test. |
I meant, how would we assert that ? I can think of snapshot testing only other than any hacky approach. |
Yes, snapshot should be the easiest way. |
@fisker I’d suggest opening a separate issue to discuss your idea. |
Taking this up. |
… (#14798) * Update: add end location to report in `consistent-return` * Update: report end location for `function` keyword
…4809) * Update: add end location to report in `unicode-bom` * Update: report start location only
* master: Chore: Adopt `eslint-plugin/require-meta-docs-url` rule internally (eslint#14823) Docs: New syntax issue template (eslint#14826) Chore: assertions on reporting loc in `unicode-bom` (refs eslint#12334) (eslint#14809) Docs: fix multiple broken links (eslint#14833) Chore: use `actions/setup-node@v2` (eslint#14816) Docs: Update README team and sponsors 7.31.0 Build: changelog update for 7.31.0 Upgrade: @eslint/eslintrc to v0.4.3 (eslint#14808) Update: add end location to report in `consistent-return` (refs eslint#12334) (eslint#14798) Docs: update BUG_REPORT template (eslint#14787) Docs: provide more context to no-eq-null (eslint#14801)
This is all done 🎉 . |
Awesome! Thanks to everyone who helped push through this. 🙏 |
Summary
Many rules reports only start location and no end location. For these rules, editors often renders tildes in unexpected places.
Examples
In these examples, the rules only reports start location but no end locations. Instead of highlighting tokens like
\n
,(
, or{
, the token before the said token is highlighted.There are many other rules suffering from this problem, most of them are named
*space*
or*spacing*
.How to fix
The problem disappear if the both start location and end location are reported and start location is different to end location. That is, the location range is not zero-width-ed.
There are several places this can be done:
Modify each rules to report end location. Pros: explicit. Cons: lots of place needs change.
Modify ESLint core, automatically add end location when end location is missing. Cons: not explicit.
Modify vscode-eslint plugin to automatically add end location when end location is missing.
The text was updated successfully, but these errors were encountered: