eslint-plugin-promise icon indicating copy to clipboard operation
eslint-plugin-promise copied to clipboard

feat(always-return): add `ignoreAssignmentVariable` option

Open gurgunday opened this issue 1 year ago • 15 comments
trafficstars

Adds ignoreAssignmentVariable as discussed in https://github.com/eslint-community/eslint-plugin-promise/pull/518#issuecomment-2260068048

gurgunday avatar Jul 26 '24 12:07 gurgunday

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.

brettz9 avatar Jul 28 '24 06:07 brettz9

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

gurgunday avatar Jul 30 '24 09:07 gurgunday

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

aladdin-add avatar Jul 31 '24 09:07 aladdin-add

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

gurgunday avatar Jul 31 '24 09:07 gurgunday

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

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?

scagood avatar Jul 31 '24 09:07 scagood

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 avatar Jul 31 '24 09:07 gurgunday

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

gurgunday avatar Aug 12 '24 05:08 gurgunday

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 avatar Aug 13 '24 12:08 gurgunday

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Aug 14 '24 05:08 codecov[bot]

PTAL @brettz9 @scagood

gurgunday avatar Aug 25 '24 12:08 gurgunday

Okay, so https://github.com/eslint-community/eslint-plugin-promise/pull/518#pullrequestreview-2235490839 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 avatar Sep 06 '24 19:09 gurgunday

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

gurgunday avatar Sep 08 '24 15:09 gurgunday

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

scagood avatar Sep 11 '24 07:09 scagood

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

brettz9 avatar Sep 11 '24 07:09 brettz9

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 🤣

gurgunday avatar Oct 08 '24 19:10 gurgunday