-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enhancement: Improve lint error report location #8543
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
Comments
Some may be harder than others (for example, the |
related: #8597 |
I think // current report
let unusedVar: Really & Long & { Type: 'Annotation' };
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// proposed
let unusedVar: Really & Long & { Type: 'Annotation' };
^^^^^^^^^ More generally, this is probably a pattern that applies often (always?) if there are other cases when a (example for why the absence of /* eslint init-declarations: ["error", "never"] */
let unusedVar: Really & Long & { Type: 'Annotation' } = 'this configuration forbids initialization.';
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Note that we don't particularly want to break from eslint core too much in the case of extension rules. If eslint reports on the variable and the init - we should too. If they report on just the variable name - then sure it makes sense for us to limit it to reduce noise! |
Yeah, good point, agreed. We could posit a guiding principle for dealing with the base rules that "we will generally only modify the report loc if there are multiple ways that it could be mapped onto TS syntax". Examples being, as above, highlighting the name of a variable could be construed to include or not include the type annotation, whereas it's unambiguous when the |
Another one: /* eslint @typescript-eslint/no-non-null-assertion: "error" */
declare const long: any;
// current
long.long.nested.thing.that.ends.in.a.non.null.assertion!
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// proposed
long.long.nested.thing.that.ends.in.a.non.null.assertion!
^ |
The complicated thing with that one is that it means you have a single-character report range. That can sometimes be hard to spot as a user and thus can be frustrating. |
how about this one? // eslint @typescript-eslint/consistent-type-assertions: ['error', { assertionStyle: 'as' } ]
<T>x;
^^^
// eslint @typescript-eslint/consistent-type-assertions: ['error', { assertionStyle: 'angle-bracket' } ]
x as T;
^^^^
// or, another option
x as T;
^^
// (but no change to the report loc for the objectLiteralTypeAssertions reports, i.e. keep the following)
{} as T;
^^^^^^^ |
One thing I am personally a fan of is over-highlighting if it highlights the code that would be fixed by the rule. For example if you highlight
Then one might be fooled into thinking that the autofixer / suggestion fixers might solely act on the If you're ADDING code then the highlight doesn't matter - but if you're changing existing code then often times highlighting the fixable range can provide good signal to the user as to what the fixer acts on. There's the trade-off, of course, but I think that it can have value as long as there's not too much visual noise. |
Well, in this case there's no autofixer at all for the Also, while I was thinking about these, i realized that it doesn't really matter too too much what the report loc is for autofixable rules, or, more generally, reports that are likely to be short-lived, since they'll just be seen once and addressed. In my experience, just a small subset of rules end up being left around long-term as a warning that people are too afraid to fix or to ignore, and those are the ones that are probably the most impactful to refine. I'm thinking:
the promise ones specifically would probably be the most impactful i 8B0D n the codebases I've worked in, but, also, unfortunately, the least obvious IMO how to shorten 🤔 |
Before You File a Proposal Please Confirm You Have Done The Following...
Relevant Package
typescript-eslint
My proposal is suitable for this project
Description
Some rule's error report location seems too wide. I think it could be improved to report more accurate location where user should care about.For example,
no-unused-vars: fix(eslint-plugin): [no-unused-vars] clear error report range #8640
explicit-member-accessibility : fix(eslint-plugin): [explicit-member-accessibility] refine report locations #8869
no-for-in-array fix(eslint-plugin): [no-for-in-array] refine report location #8874
init-declarations fix(eslint-plugin): [init-declarations] refine report locations #8893
prefer-readonly fix(eslint-plugin): [prefer-readonly] refine report locations #8894
space-before-blocks(formatting/layout rule)... maybe more
Additional Info
No response
The text was updated successfully, but these errors were encountered: