Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(always-return): add ignoreAssignmentVariable option #518

Merged
merged 7 commits into from
Oct 16, 2024

Conversation

gurgunday
Copy link
Contributor

@gurgunday gurgunday commented Jul 26, 2024

Adds ignoreAssignmentVariable as discussed in #518 (comment)

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

PR Compliance Checks Passed!

@gurgunday gurgunday changed the title turn ignorelastcallback to true chore: turn ignorelastcallback to true Jul 26, 2024
@gurgunday gurgunday changed the title chore: turn ignorelastcallback to true chore: always-return, enable ignoreLastCallback by default Jul 26, 2024
@brettz9
Copy link
Member

brettz9 commented Jul 28, 2024

I could still be persuaded (or overruled), but I'm personally a little wary of such a change as this.

I think it's safer for the default to annoy rather than accidentally avoid warnings. In the case of libraries at least, one typically does want to always return.

@gurgunday
Copy link
Contributor Author

I’d simply argue that, since this plugin is not eslint-plugin-n (and therefore not node specific), we should definitely take into account browser usage where these non blocking async globalThis assignments are common

I think the eslint-community plugins’ recommended presets should only error for usages that are incorrect ~100% of the time

For instance the chained .then usage where a .then in the middle does not return anything is most definitely not a correct usage, but for the last one we can argue cases like these, so it’d be more consistent to relax this to not fail here or maybe just warn

@aladdin-add
Copy link
Contributor

just want to point out: it should be a breaking change to change a rule's default option.

@gurgunday
Copy link
Contributor Author

Yeah I wish I'd opened the PR earlier to maybe target the v7 release

@scagood
Copy link
Contributor

scagood commented Jul 31, 2024

I am not sure I agree here, as enabling ignoreLastCallback will void the point of the check in a lot of cases. 🤔

In fact I would prefer to remove the rule from the recommended config, than making this change.


A different option could be allowing assignment to specific variables?
eg ignoreAssignmentVariable: ["global.window"]

Would this work for you?

@gurgunday
Copy link
Contributor Author

A different option could be allowing assignment to specific variables?

This makes a lot of sense and I didn’t know it was possible! Let me take a look

@gurgunday gurgunday marked this pull request as draft August 4, 2024 21:41
@gurgunday gurgunday changed the title chore: always-return, enable ignoreLastCallback by default feat: ignoreAssignmentVariable Aug 12, 2024
@gurgunday gurgunday marked this pull request as ready for review August 12, 2024 05:56
@gurgunday
Copy link
Contributor Author

gurgunday commented Aug 12, 2024

@scagood, @brettz9 @aladdin-add, can you take a look?

@aladdin-add aladdin-add requested review from brettz9 and scagood August 12, 2024 06:08
Copy link
Member

@brettz9 brettz9 left a comment

Choose a reason for hiding this comment

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

Besides the one suggestion, LGTM...

Copy link
Contributor

@scagood scagood left a comment

Choose a reason for hiding this comment

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

I generally prefer this strategy I think!

@gurgunday
Copy link
Contributor Author

Hey everyone, so I made the option recursive, which means it allows for assignments to nested properties like window.a.b or window["test"][0]

I had to use string manipulation since I'm not familiar with how else to achieve this, but it looks sound to me as a property can either be computed or not, and we take both into account

@gurgunday gurgunday requested review from brettz9 and scagood August 13, 2024 12:36
Copy link

codecov bot commented Aug 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (bbcfcbf) to head (064637a).
Report is 63 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #518   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        26    +1     
  Lines          649       719   +70     
  Branches       250       278   +28     
=========================================
+ Hits           649       719   +70     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@gurgunday
Copy link
Contributor Author

PTAL @brettz9 @scagood

Copy link
Contributor

@scagood scagood left a comment

Choose a reason for hiding this comment

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

I would love to see some more tests, other than that, I think this is starting to take shape 💪

Copy link
Member

@brettz9 brettz9 left a comment

Choose a reason for hiding this comment

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

LGTM...

Just as an idea for a future PR, it would seem to me a possibly even more common use browser case to allow node appending in the last promise, e.g.:

prom.then((newInfo) => {
  document.body.append(toDom(newInfo));
})

But regardless, this PR LGTM...

@gurgunday
Copy link
Contributor Author

gurgunday commented Sep 6, 2024

Okay, so #518 (review) made a good point - we need to take into account both variations (computed or not computed) for each level of the passed variable names

For instance, if ignoreAssignmentVar: ["window.a.b"] is passed, assignments to window.a.b window.['a']['b'] and window.a['b'] should all pass; and the passed variable name itself can have variations as well like ignoreAssignmentVar: ["window.['a']['b']", "window.a.b"]

It's not hard but it requires a little more complex logic or at least we need to determine how the config should behave

To keep the implementation correct, what I propose is that we start with 1 level of nesting in the config - e.g., just window or globalThis - and after discussing the details we make a follow-up PR to lift this restriction

@gurgunday gurgunday requested a review from scagood September 8, 2024 15:49
@gurgunday
Copy link
Contributor Author

gurgunday commented Sep 8, 2024

PTAL with the current setting that only allows for simple var names

Copy link
Contributor

@scagood scagood left a comment

Choose a reason for hiding this comment

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

To keep the implementation correct, what I propose is that we start with 1 level of nesting in the config - e.g., just window or globalThis - and after discussing the details we make a follow-up PR to lift this restriction

I agree, I have left comments inline with that 😄

@gurgunday gurgunday requested a review from scagood September 11, 2024 07:23
Copy link
Contributor

@scagood scagood left a comment

Choose a reason for hiding this comment

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

I like the shape of this now!
Thank you for the awesome docs too 😀

@scagood
Copy link
Contributor

scagood commented Sep 11, 2024

@brettz9 Do you want to take another look at this PR?

@brettz9
Copy link
Member

brettz9 commented Sep 11, 2024

Sorry, is anyone else available? I've come into other work which is keeping me busy...

@scagood scagood requested a review from a team September 11, 2024 08:09
@gurgunday
Copy link
Contributor Author

Hey everyone, just checking in to see if we can get this merged soon

Doing a lot of webdev these days and I keep bumping into this 🤣

@MichaelDeBoey MichaelDeBoey changed the title feat: ignoreAssignmentVariable feat(always-return): add ignoreAssignmentVariable option Oct 9, 2024
@brettz9 brettz9 merged commit 701279c into eslint-community:main Oct 16, 2024
11 checks passed
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Nov 25, 2024
##### [v7.2.0](https://github.com/eslint-community/eslint-plugin-promise/blob/HEAD/CHANGELOG.md#720-2024-11-25)

##### 🌟 Features

-   **`no-callback-in-promise`:** add `timeoutsErr` option ([#514](eslint-community/eslint-plugin-promise#514)) ([907753f](eslint-community/eslint-plugin-promise@907753f))
-   **`valid-params`:** add `exclude` option ([#515](eslint-community/eslint-plugin-promise#515)) ([7ff2cb9](eslint-community/eslint-plugin-promise@7ff2cb9))
-   **always-return:** add `ignoreAssignmentVariable` option ([#518](eslint-community/eslint-plugin-promise#518)) ([701279c](eslint-community/eslint-plugin-promise@701279c))
-   **catch-or-return:** add `allowThenStrict` option ([#522](eslint-community/eslint-plugin-promise#522)) ([53be970](eslint-community/eslint-plugin-promise@53be970))
-   new rule `prefer-catch` ([#525](eslint-community/eslint-plugin-promise#525)) ([05c8a93](eslint-community/eslint-plugin-promise@05c8a93))

##### 🩹 Fixes

-   permit appropriate computed member expressions and prototype access ([#535](eslint-community/eslint-plugin-promise#535)) ([4de9d43](eslint-community/eslint-plugin-promise@4de9d43))

##### 🧹 Chores

-   **deps-dev:** bump eslint-plugin-jest from 28.6.0 to 28.8.0 ([#536](eslint-community/eslint-plugin-promise#536)) ([80741f8](eslint-community/eslint-plugin-promise@80741f8))
-   **deps-dev:** bump eslint-plugin-n from 17.9.0 to 17.10.2 ([#529](eslint-community/eslint-plugin-promise#529)) ([a646010](eslint-community/eslint-plugin-promise@a646010))
-   **deps-dev:** bump globals from 15.8.0 to 15.9.0 ([#527](eslint-community/eslint-plugin-promise#527)) ([b8afe92](eslint-community/eslint-plugin-promise@b8afe92))
-   **deps-dev:** bump husky from 9.1.2 to 9.1.4 ([#524](eslint-community/eslint-plugin-promise#524)) ([b8fdb9f](eslint-community/eslint-plugin-promise@b8fdb9f))
-   **deps-dev:** bump lint-staged from 15.2.7 to 15.2.8 ([#539](eslint-community/eslint-plugin-promise#539)) ([9e2528f](eslint-community/eslint-plugin-promise@9e2528f))
-   **deps-dev:** update eslint-plugin-eslint-plugin to v6.3.0 ([#560](eslint-community/eslint-plugin-promise#560)) ([7459bd6](eslint-community/eslint-plugin-promise@7459bd6))
-   **deps-dev:** update eslint-plugin-eslint-plugin to v6.3.1 ([#561](eslint-community/eslint-plugin-promise#561)) ([434c6fa](eslint-community/eslint-plugin-promise@434c6fa))
-   **deps-dev:** update eslint-plugin-eslint-plugin to v6.3.2 ([#570](eslint-community/eslint-plugin-promise#570)) ([a849f64](eslint-community/eslint-plugin-promise@a849f64))
-   **deps-dev:** update eslint-plugin-jest to v28.9.0 ([#565](eslint-community/eslint-plugin-promise#565)) ([cf213fb](eslint-community/eslint-plugin-promise@cf213fb))
-   **deps-dev:** update eslint-plugin-n to v17.12.0 ([#563](eslint-community/eslint-plugin-promise#563)) ([d39e2f0](eslint-community/eslint-plugin-promise@d39e2f0))
-   **deps-dev:** update eslint-plugin-n to v17.13.0 ([#566](eslint-community/eslint-plugin-promise#566)) ([b62f234](eslint-community/eslint-plugin-promise@b62f234))
-   **deps-dev:** update eslint-plugin-n to v17.13.1 ([#567](eslint-community/eslint-plugin-promise#567)) ([266ddbb](eslint-community/eslint-plugin-promise@266ddbb))
-   **deps-dev:** update eslint-plugin-n to v17.13.2 ([#569](eslint-community/eslint-plugin-promise#569)) ([390f51f](eslint-community/eslint-plugin-promise@390f51f))
-   **deps-dev:** update npm-run-all2 to v6.2.4 ([#558](eslint-community/eslint-plugin-promise#558)) ([2cf1732](eslint-community/eslint-plugin-promise@2cf1732))
-   **deps-dev:** update npm-run-all2 to v6.2.6 ([#559](eslint-community/eslint-plugin-promise#559)) ([dc32933](eslint-community/eslint-plugin-promise@dc32933))
-   **deps:** switch from dependabot to renovate using shared eslint community configuration ([#537](eslint-community/eslint-plugin-promise#537)) ([30efed7](eslint-community/eslint-plugin-promise@30efed7))
-   **deps:** update [@eslint-community/eslint-utils](https://github.com/eslint-community/eslint-utils) to v4.4.1 ([#562](eslint-community/eslint-plugin-promise#562)) ([5c3628d](eslint-community/eslint-plugin-promise@5c3628d))
-   **deps:** update globals to v15.12.0 ([#564](eslint-community/eslint-plugin-promise#564)) ([c8632d1](eslint-community/eslint-plugin-promise@c8632d1))
-   update [@typescript-eslint/parser](https://github.com/typescript-eslint/parser) to v7.18.0 ([#545](eslint-community/eslint-plugin-promise#545)) ([5744e60](eslint-community/eslint-plugin-promise@5744e60))
-   update dependency eslint-plugin-n to v17.11.0 ([#556](eslint-community/eslint-plugin-promise#556)) ([bbd048b](eslint-community/eslint-plugin-promise@bbd048b))
-   update dependency eslint-plugin-n to v17.11.1 ([#557](eslint-community/eslint-plugin-promise#557)) ([e545254](eslint-community/eslint-plugin-promise@e545254))
-   update dependency globals to v15.11.0 ([#555](eslint-community/eslint-plugin-promise#555)) ([9151db8](eslint-community/eslint-plugin-promise@9151db8))
-   update dependency typescript to v5.6.3 ([#554](eslint-community/eslint-plugin-promise#554)) ([ab55120](eslint-community/eslint-plugin-promise@ab55120))
-   update eslint to v8.57.1 ([#551](eslint-community/eslint-plugin-promise#551)) ([38e2757](eslint-community/eslint-plugin-promise@38e2757))
-   update eslint-plugin-jest to v28.8.3 ([#548](eslint-community/eslint-plugin-promise#548)) ([89f2578](eslint-community/eslint-plugin-promise@89f2578))
-   update eslint-plugin-n to v17.10.3 ([#552](eslint-community/eslint-plugin-promise#552)) ([2d738fe](eslint-community/eslint-plugin-promise@2d738fe))
-   update globals to v15.10.0 ([#553](eslint-community/eslint-plugin-promise#553)) ([b871314](eslint-community/eslint-plugin-promise@b871314))
-   update husky to v9.1.6 ([#547](eslint-community/eslint-plugin-promise#547)) ([1e8d18f](eslint-community/eslint-plugin-promise@1e8d18f))
-   update lint-staged to v15.2.10 ([#544](eslint-community/eslint-plugin-promise#544)) ([7d46b3b](eslint-community/eslint-plugin-promise@7d46b3b))
-   update npm-run-all2 to v6.2.3 ([#550](eslint-community/eslint-plugin-promise#550)) ([14cd4c0](eslint-community/eslint-plugin-promise@14cd4c0))
-   update typescript to ~5.6.0 ([#549](eslint-community/eslint-plugin-promise#549)) ([ebcdd8b](eslint-community/eslint-plugin-promise@ebcdd8b))
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Nov 25, 2024
##### [v7.2.0](https://github.com/eslint-community/eslint-plugin-promise/blob/HEAD/CHANGELOG.md#720-2024-11-25)

##### 🌟 Features

-   **`no-callback-in-promise`:** add `timeoutsErr` option ([#514](eslint-community/eslint-plugin-promise#514)) ([907753f](eslint-community/eslint-plugin-promise@907753f))
-   **`valid-params`:** add `exclude` option ([#515](eslint-community/eslint-plugin-promise#515)) ([7ff2cb9](eslint-community/eslint-plugin-promise@7ff2cb9))
-   **always-return:** add `ignoreAssignmentVariable` option ([#518](eslint-community/eslint-plugin-promise#518)) ([701279c](eslint-community/eslint-plugin-promise@701279c))
-   **catch-or-return:** add `allowThenStrict` option ([#522](eslint-community/eslint-plugin-promise#522)) ([53be970](eslint-community/eslint-plugin-promise@53be970))
-   new rule `prefer-catch` ([#525](eslint-community/eslint-plugin-promise#525)) ([05c8a93](eslint-community/eslint-plugin-promise@05c8a93))

##### 🩹 Fixes

-   permit appropriate computed member expressions and prototype access ([#535](eslint-community/eslint-plugin-promise#535)) ([4de9d43](eslint-community/eslint-plugin-promise@4de9d43))

##### 🧹 Chores

-   **deps-dev:** bump eslint-plugin-jest from 28.6.0 to 28.8.0 ([#536](eslint-community/eslint-plugin-promise#536)) ([80741f8](eslint-community/eslint-plugin-promise@80741f8))
-   **deps-dev:** bump eslint-plugin-n from 17.9.0 to 17.10.2 ([#529](eslint-community/eslint-plugin-promise#529)) ([a646010](eslint-community/eslint-plugin-promise@a646010))
-   **deps-dev:** bump globals from 15.8.0 to 15.9.0 ([#527](eslint-community/eslint-plugin-promise#527)) ([b8afe92](eslint-community/eslint-plugin-promise@b8afe92))
-   **deps-dev:** bump husky from 9.1.2 to 9.1.4 ([#524](eslint-community/eslint-plugin-promise#524)) ([b8fdb9f](eslint-community/eslint-plugin-promise@b8fdb9f))
-   **deps-dev:** bump lint-staged from 15.2.7 to 15.2.8 ([#539](eslint-community/eslint-plugin-promise#539)) ([9e2528f](eslint-community/eslint-plugin-promise@9e2528f))
-   **deps-dev:** update eslint-plugin-eslint-plugin to v6.3.0 ([#560](eslint-community/eslint-plugin-promise#560)) ([7459bd6](eslint-community/eslint-plugin-promise@7459bd6))
-   **deps-dev:** update eslint-plugin-eslint-plugin to v6.3.1 ([#561](eslint-community/eslint-plugin-promise#561)) ([434c6fa](eslint-community/eslint-plugin-promise@434c6fa))
-   **deps-dev:** update eslint-plugin-eslint-plugin to v6.3.2 ([#570](eslint-community/eslint-plugin-promise#570)) ([a849f64](eslint-community/eslint-plugin-promise@a849f64))
-   **deps-dev:** update eslint-plugin-jest to v28.9.0 ([#565](eslint-community/eslint-plugin-promise#565)) ([cf213fb](eslint-community/eslint-plugin-promise@cf213fb))
-   **deps-dev:** update eslint-plugin-n to v17.12.0 ([#563](eslint-community/eslint-plugin-promise#563)) ([d39e2f0](eslint-community/eslint-plugin-promise@d39e2f0))
-   **deps-dev:** update eslint-plugin-n to v17.13.0 ([#566](eslint-community/eslint-plugin-promise#566)) ([b62f234](eslint-community/eslint-plugin-promise@b62f234))
-   **deps-dev:** update eslint-plugin-n to v17.13.1 ([#567](eslint-community/eslint-plugin-promise#567)) ([266ddbb](eslint-community/eslint-plugin-promise@266ddbb))
-   **deps-dev:** update eslint-plugin-n to v17.13.2 ([#569](eslint-community/eslint-plugin-promise#569)) ([390f51f](eslint-community/eslint-plugin-promise@390f51f))
-   **deps-dev:** update npm-run-all2 to v6.2.4 ([#558](eslint-community/eslint-plugin-promise#558)) ([2cf1732](eslint-community/eslint-plugin-promise@2cf1732))
-   **deps-dev:** update npm-run-all2 to v6.2.6 ([#559](eslint-community/eslint-plugin-promise#559)) ([dc32933](eslint-community/eslint-plugin-promise@dc32933))
-   **deps:** switch from dependabot to renovate using shared eslint community configuration ([#537](eslint-community/eslint-plugin-promise#537)) ([30efed7](eslint-community/eslint-plugin-promise@30efed7))
-   **deps:** update [@eslint-community/eslint-utils](https://github.com/eslint-community/eslint-utils) to v4.4.1 ([#562](eslint-community/eslint-plugin-promise#562)) ([5c3628d](eslint-community/eslint-plugin-promise@5c3628d))
-   **deps:** update globals to v15.12.0 ([#564](eslint-community/eslint-plugin-promise#564)) ([c8632d1](eslint-community/eslint-plugin-promise@c8632d1))
-   update [@typescript-eslint/parser](https://github.com/typescript-eslint/parser) to v7.18.0 ([#545](eslint-community/eslint-plugin-promise#545)) ([5744e60](eslint-community/eslint-plugin-promise@5744e60))
-   update dependency eslint-plugin-n to v17.11.0 ([#556](eslint-community/eslint-plugin-promise#556)) ([bbd048b](eslint-community/eslint-plugin-promise@bbd048b))
-   update dependency eslint-plugin-n to v17.11.1 ([#557](eslint-community/eslint-plugin-promise#557)) ([e545254](eslint-community/eslint-plugin-promise@e545254))
-   update dependency globals to v15.11.0 ([#555](eslint-community/eslint-plugin-promise#555)) ([9151db8](eslint-community/eslint-plugin-promise@9151db8))
-   update dependency typescript to v5.6.3 ([#554](eslint-community/eslint-plugin-promise#554)) ([ab55120](eslint-community/eslint-plugin-promise@ab55120))
-   update eslint to v8.57.1 ([#551](eslint-community/eslint-plugin-promise#551)) ([38e2757](eslint-community/eslint-plugin-promise@38e2757))
-   update eslint-plugin-jest to v28.8.3 ([#548](eslint-community/eslint-plugin-promise#548)) ([89f2578](eslint-community/eslint-plugin-promise@89f2578))
-   update eslint-plugin-n to v17.10.3 ([#552](eslint-community/eslint-plugin-promise#552)) ([2d738fe](eslint-community/eslint-plugin-promise@2d738fe))
-   update globals to v15.10.0 ([#553](eslint-community/eslint-plugin-promise#553)) ([b871314](eslint-community/eslint-plugin-promise@b871314))
-   update husky to v9.1.6 ([#547](eslint-community/eslint-plugin-promise#547)) ([1e8d18f](eslint-community/eslint-plugin-promise@1e8d18f))
-   update lint-staged to v15.2.10 ([#544](eslint-community/eslint-plugin-promise#544)) ([7d46b3b](eslint-community/eslint-plugin-promise@7d46b3b))
-   update npm-run-all2 to v6.2.3 ([#550](eslint-community/eslint-plugin-promise#550)) ([14cd4c0](eslint-community/eslint-plugin-promise@14cd4c0))
-   update typescript to ~5.6.0 ([#549](eslint-community/eslint-plugin-promise#549)) ([ebcdd8b](eslint-community/eslint-plugin-promise@ebcdd8b))
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants