🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@mgol
Copy link
Member

@mgol mgol commented Apr 30, 2019

Summary

This commit requires all function parameters to be used, not just the last one.
In cases where that's not possible as we need to match an external API, there's
an escape hatch of prefixing an unused argument with _.

This change makes it easier to catch unused AMD dependencies and unused
parameters in internal functions the API of which we may change at will, among
other things.

Unused AMD dependencies have been removed as part of this commit.

What do you think? If you agree this change is worthwhile, should we add that rule to eslint-config-jquery?

Checklist

Copy link
Member

@timmywil timmywil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use this in other projects.

Copy link
Member

@dmethvin dmethvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a good idea. This combined with the no-global-jQuery in testing should help eliminate errors.

@mgol
Copy link
Member Author

mgol commented May 8, 2019

@gibson042 Are you OK with this change?

@leobalter @trentmwillis @Krinkle From QUnit perspective, does that sound good to you (see the change in .eslintrc.json? If so, I'd submit a PR to eslint-config-jquery.

@Krinkle
Copy link
Member

Krinkle commented May 8, 2019

@mgol Disallowing unused earlier parameters I'm not sure is a good convention for code quality on its own merit.

I do agree it makes a lot of sense here for jquery wrt AMD closures and such. But for other projects, I think the regular ESLint detection is enough. It seems like that would only adds extra overhead and maintenance cost over time (as well as potential confusion for new developers), without offering any real benefit, right?

@timmywil
Copy link
Member

timmywil commented May 8, 2019

@Krinkle It depends. Where function parameters are not flexible, it doesn't do much besides force you to prefix the parameter name with underscore. But it does help clean up function signatures wherever they are flexible enough to be changed and the unused parameter can be removed. But I see your point that jQuery gets the most value from auditing the parameters for AMD loading and building.

@mgol
Copy link
Member Author

mgol commented May 8, 2019

@Krinkle jQuery's AMD is the biggest beneficent of this new rule but we'll most likely migrate to ES modules so it will stop being so in the future. I see other gains, though - while, as @timmywil noted, functions bound by external contracts need the _ prefixes, there are lots of internal ones and it's sometimes easy to miss a particular parameter may no longer be used & can be removed.

In my PR I only had to add the _ prefix in 15 places, 8 of which are jQuery.each & 1 jQuery.map, leaving 6 "regular" cases.

If you think this rule is not a good fit for QUnit, I may just leave an override here but we haven't been using overrides so far. I see QUnit is, though, and quite a lot at that; QUnit also uses the eslint:recommended config which we don't. I wonder how big a gain for QUnit is that it uses the jquery config; in the past we thought of it as a preset common for all jQuery Foundation projects but that hasn't materialized. At the moment, I think, it's mostly a few jQuery projects to which similar people contribute: Core, Migrate, Color, and QUnit.

@Krinkle
Copy link
Member

Krinkle commented May 8, 2019

@mgol Yeah, makes sense to share with e.g. jquery migrate. Using the preset for that makes sense.

I'd say don't worry about QUnit in that case, we can disable things as needed, no problem.

Off-topic for here, but it might make sense to expose two presets within the eslint-config-jquery package. One for style and for static analysis/quality. Then projects could adopt one without the other, for example. We have a similar setup for Wikimedia at https://github.com/wikimedia/eslint-config-wikimedia, which has worked well for us.

@mgol
Copy link
Member Author

mgol commented May 8, 2019

For anyone reading this, GitHub has messed the order of the comments and some older comments display below the newer ones.

@trentmwillis
Copy link
Member

My two cents: I don't think it would impact QUnit much, if it becomes a pain we can opt-out as @Krinkle mentions above.

mgol added a commit to mgol/eslint-config-jquery that referenced this pull request May 12, 2019
This rule requires all function parameters to be used, not just the last one.
In cases where that's not possible as we need to match an external API, there's
an escape hatch of prefixing an unused argument with _.

This change makes it easier to catch unused AMD dependencies and unused
parameters in internal functions the API of which we may change at will, among
other things.

Ref jquery/jquery#4381
@mgol
Copy link
Member Author

mgol commented May 12, 2019

I submitted jquery/eslint-config-jquery#14 for the config changes. Please review, after publishing an update I'll change this PR.

@timmywil timmywil added this to the 4.0.0 milestone May 13, 2019
mgol added a commit to jquery/eslint-config-jquery that referenced this pull request May 13, 2019
This rule requires all function parameters to be used, not just the last one.
In cases where that's not possible as we need to match an external API, there's
an escape hatch of prefixing an unused argument with _.

This change makes it easier to catch unused AMD dependencies and unused
parameters in internal functions the API of which we may change at will, among
other things.

Closes #14
Ref jquery/jquery#4381
This commit requires all function parameters to be used, not just the last one.
In cases where that's not possible as we need to match an external API, there's
an escape hatch of prefixing an unused argument with `_`.

This change makes it easier to catch unused AMD dependencies and unused
parameters in internal functions the API of which we may change at will, among
other things.

Unused AMD dependencies have been removed as part of this commit.
@mgol mgol force-pushed the eslint-no-unused-vars branch from 1f01f32 to 0745fac Compare May 13, 2019 20:04
@mgol mgol merged commit 438b1a3 into jquery:master May 13, 2019
@mgol mgol deleted the eslint-no-unused-vars branch May 13, 2019 20:25
mgol added a commit that referenced this pull request Sep 26, 2019
This commit requires all function parameters to be used, not just the last one.
In cases where that's not possible as we need to match an external API, there's
an escape hatch of prefixing an unused argument with `_`.

This change makes it easier to catch unused AMD dependencies and unused
parameters in internal functions the API of which we may change at will, among
other things.

Unused AMD dependencies have been removed as part of this commit.

Closes gh-4381

(cherry-picked from 438b1a3)
@mgol mgol modified the milestones: 4.0.0, 3.5.0 Sep 26, 2019
@mgol
Copy link
Member Author

mgol commented Sep 26, 2019

Cherry-picked to 3.x-stable in d7e13f1.

@lock lock bot locked as resolved and limited conversation to collaborators Mar 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Development

Successfully merging this pull request may close these issues.

6 participants