-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[Question] why the redundant rules? #122
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
I think the reasoning was that these rules can be enabled without breaking your build. |
If that's the case, fair enough, but i'll raise another issue for the unused-vars bug if I can reproduce again. |
Have you tried the canary version? The issue should’ve been fixed by #102. |
Hi. I'm not sure if How about the follwoing setting in the recommended preset, instead of a substitute rule for both JS and TS? {
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"rules": { "no-unused-vars": "off" }
}
]
} |
I personally strongly agree, but I was not involved in the setting up of the recommended rules. I will let those folks comment who were, but I’m happy for us to consider changing this. IMO the bar to be recommended should be exceptionally high (in all tools) |
Indeed, it definitely should not be recommended IMO. It will always do a worse job than the compiler as it has less context around the type system and inference. By having it in the recommended set, we are covering up or clashing with the compiler features which will lead to confusion. |
i can see only one use case, vue class components in |
I personally turn rules that the compiler catches off for my TypeScript projects. Would be in favor of not recommending and possibly deprecating |
i have small idea, but i'm don't know if ts provides api for that: retrieve errors about used vars and map them to eslintUsed, this will allow us to delegate detection to tsc and give plugins way to extend functionality |
These are not the same and serve completely different purposes. The former is ensuring you haven't forgotten a return, the latter is ensuring you're writing strictly typed function contracts.
I brought this up when I took over the plugin for the exact reason that it's got a non-zero maintenance cost and is flakey, and the response from the community was this: The rule gives a developer the ability to have non-dev-build blocking warning of unused code.
The use case is that I see the local builds are done with |
What I was hoping, was that we could leverage the TS parser services for this, so that we don't have to worry about manually supporting every use case, and then there would be a near zero maintenance cost due to reusing the tsc logic. |
Yup i'm aware, my mistake. This means there's yet another bug since the monorepo and/or last version then as inherited types were taken into account before. Either that or another tsc option was handling those checks.
I really don't think it is worth it. The cost of maintenance of an already flaky rule outweighs the need for someone to change a compilation option into a warning. Such people should be fixing their builds rather than placing a burden on this repo's maintainers for a very redundant feature. The fact that we're trying to do something which the compiler will always do better is questionable by its self. |
in vue class component projects we can't use those options <template>
<div>{{ bar }}</div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
@Component
export default class Foo extends Vue {
get bar() : string { return 'example' }
}
</script> in this case typescript is going to warn me that bar is not used, but i'm using it in |
If you can get a solid repro case, log it and we'll gladly look into it!
Hence my second comment - we're hoping that we can at some point leverage the TS compiler/parser.
I don't use the rule myself, but many, many users have asked for this. There's a reason this rule was implemented almost 3 years ago, and there's a reason that it's still here 3 years later - users have asked for this, users want this. I can understand why - it's a very nice workflow when rapidly prototyping code. It's very simple to delete a reference to something with the intention of cleaning it up before pushing/releasing. Also there are cases (like @armano2 mentioned), that users cannot use the default TS compiler options. The problem here is that you're blaming the users for wanting this rule and reporting issues on this rule, when in actuality the problem is more with us (the package maintainers); we have implemented the rule, and we have missed cases. The maintenance burden exists because of how the rule has been written/implemented, and how we missed cases in our tests. As an aside, at this point in time I think we've gotten the majority of cases. Now we are getting into mainly weird edge cases where there's deeply nested type usages that require special handling.
|
I think the problem is more that you're going to be forever playing catch up if you keep this rule implemented yourself. If it can't make use of the compiler's implementation, it'll never be in sync and will essentially be a reinvention of the wheel (which is why it has bugs and "missing cases"). |
Also regarding the original issue overall, i think we should at least move to get them out of the recommended rule set as they definitely don't belong there IMO. |
I got it.
Since 2.9, I believe that rule is completely duplicated and we can deprecate that rule in favor of |
I didn't know that @mysticatea! Do you know what this looks like in the console? If it doesn't play nice with webpack/etc, then there is still a valid case for the rule.
We turned it on in recommended because 2/4 config sets we looked at had it turned on (bradzacher/eslint-plugin-typescript#144), and nobody replied saying they were against it being turned on. We're more than happy to change anything in the recommended set - if there is the community engagement to do so. |
Me too :) |
One big benefit of having the rules is that linting runs live in the editor, while |
@sindresorhus TypeScript's type checking is also running in editors real-time. For example, vscode colors the unused variables gray. I guess that other editors have similar feature because TypeScript has the language server. |
Unfortunately function test(arg1: number, arg2: number) {
console.log(arg2);
}
And will only ignore it if prefixed with an underscore, which you may or may not like: function test(_arg1: number, arg2: number) {
console.log(arg2);
} So I like that |
The two rules should be removed from the recommended set either way, as we all seem to have agreed. Keeping them around is no loss to any of us as long as they're disabled by default. It is more a question of if the maintainers want to maintain them (and if so, they should definitely use the typescript api instead of always playing catch up). |
i was looking for this, we can use diagnostics to change logic of this rule to report suggestions even if user does not provide i did tests with |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
We've had this debate play out a few times in TSLint. In the latest TSLint, |
Even if it had no bugs and was flawless, it doesn't belong in the recommended config. We should begin by removing it from there and suggesting to users that they enable the |
a lot of eslint rules relies on scope analysis and if we are going to support any of them we can support all of them if we will decide to drop support for no-unused-vars it will means that its going to be hard to make sure that all of rules are going to work correctly. scope analysis is used in:
most of them will work if we will use default scope analysis from eslint, but support for additional syntax will not be added, example modules. for sure there is going some setback and issues, but if its going to work for one rule its will be reused in others |
I am currently using the These options absolutely suck! They generate hard failures during development simply because you haven't used a variable yet. Which is 100% reasonable during development, you regularly setup a partially implemented function and want to confirm the partial behaviour before implementing the rest of it. In the last few work days I have regularly dropped or commented out something unfinished, waited for my app to compile, then had to go and comment out an import that is no longer used simply because the incomplete code using it was commented out. All this does is make development slower without providing me any benefit during development. But having no-unused-vars at lint time is very useful. You get good warnings about clutter you need to cleanup, and you can use commit hooks to make sure you don't commit partial code forgetting you removed something or didn't finish something.
|
I am not saying remove the rule, it just does not belong in the recommended rule set. We are currently misleading people by recommending a rule rather than the compilation options. This is the wrong thing to do as they should be exposed to the compilation options and make their own choice. Keep the rule, remove it from the recommended config. |
I know. I'm saying that these options are so bad that the compiler options should not be "recommended" to anyone. If we give the user a choice between the two and the rule comes with a "there are some bugs we're working on fixing" asterisk, then the compiler options should come with a huge "these compiler options will introduce a hard failure on perfectly functional code and actively impede your work during development" warning and shouldn't be a "recommended" option for anyone. |
This is a pretty aggressive stance IMO. TS compiler errors do not prohibit JS emit, so you should still be able to easily run your code in development even when the |
You'd better tell that to ts-node then, because ts-node throws a fatal error and exits when you enable
|
I mean I have strict compilation options on and have done for as long as they've existed, with a workflow im happy with. It really depends on your own personal use case, setup and what not. Keeping this rule definitely is fine because some people want a "soft" error rather than the hard compilation error. However, by recommending it we are covering up the fact that such a compilation option exists and potentially misleading consumers by doing so (especially since the implementations will always differ). |
@dantman without getting too much into the defaults enforced by various tooling in the JS ecosystem right here in this thread (of which |
Do you have a citation for this stance I can quote to those downstream tools? Besides your experience and the default of one compiler option? Because I doubt I can convince any widely used tooling that is the case and get them to change their default based on just that. |
Today I updated to the newly scoped package as opposed to the old unscoped/non-monorepo one, and I also inherited the recommended config.
First thing I noticed by enabling all your recommended rules is that you have some redundant ones:
@typescript-eslint/explicit-function-return-type
@typescript-eslint/no-unused-vars
Why do these rules exist? There are already compiler options for them:
noImplicitReturns
noUnusedLocals
noUnusedParameters
In fact, the rules do a much worse job and seem to be very flaky. Why would we recommend these instead of built-in compiler features?
For example, the unused-vars rule doesn't detect the usage of types in interface generics:
SomeType
is marked as unused.Another example, the return type rule has no clue about inheritance. It will error if you don't specify the return type of a method even if the method it overrides has a return type on it. TypeScript allows this.
Are these rules just here for legacy reasons or is there a reason to prefer them?
I would ask you at least remove them from the recommended config and start recommending the much more stable, much stronger compiler features.
The text was updated successfully, but these errors were encountered: