less.js icon indicating copy to clipboard operation
less.js copied to clipboard

Fix eslint warnimg

Open lumburr opened this issue 3 years ago • 3 comments

What: fix #3224

Why:

How:

Use a new utils function replace v == null to fix eslint warning. It's a code style issue. We also can chage ESlint config option "no-eq-null" to fix it. Which plan are we going to take? I will update my pr if it needs to change.

Checklist:

  • [ ] Documentation N/A
  • [ ] Added/updated unit tests N/A
  • [x] Code complete

lumburr avatar Apr 02 '22 03:04 lumburr

So, I don't agree with this approach. I think the better way is to figure out what foo == null was intended to check for. If it's just checking for a "falsey" value, it should just be !foo.

That is, someone should log all these cases of == null with a typeof during testing to see what exactly are the types of values getting loosely checked against null, and then re-write this in a way that is more clear. That's IMO a better approach rather than just adding a bunch of function wrappers, which possibly degrades performance.

matthew-dean avatar Apr 21 '22 20:04 matthew-dean

  1. Conclusion: currentDirectory---- is related to the file, there are only two possible undefined, normal value currentDirectory comes from the file information in the node and will be given a default value of {}. Path: packages/less/src/less/environment/environment.js 1 Path: packages/less/src/ess/tree/node.js 1-2
  2. Conclusion: v has three possible values null, undefined, normal. Path: packages/less/src/less/functions/default.js 2
  3. Conclusion: unit has only two possible values null, normal value. Path: packages/less/src/less/functions/math-helper.js 3 MathHelper is only used in two places. Path: packages/less/src/less/functions/math.js 3-2 It is normal. Path: packages/less/src/less/functions/number.js 3-3 It is normal or null.
  4. Conclusion: value.value has only two possible values undefined, normal value. Path: packages/less/src/less/parser/paser.js 4 Path: packages/less/src/less/parser/paser.js 4-1 It is normal or undefind. Path: packages/less/src/less/parser/paser.js 4-2 It is undefind. Path: packages/less/src/less/parser/paser.js 4-3 It is undefind. Path: packages/less/src/less/parser/paser.js 4-4 It is normal or undefind.
  5. Conclusion: this.visibilityBlocks has only two possible values undefined, normal value Path: packages/less/src/less/tree/node.js 5 Default value is undefind, Invalid information is filtered.
  6. Conclusion: escaped has two possible values, boolean value, default value undefined Path: packages/less/src/less/tree/quoted.js 6 Path: packages/less/src/less/parser/parser.js 6-1 It is undefind. Path: packages/less/src/less/parser/parser.js 6-2 It is undefind or boolean.
  7. Conclusion: nestedSelector has only two possible values null, normal value. Path: packages/less/src/less/tree/ruleset.js 7 Path: packages/less/src/less/tree/ruleset.js 7-1 nestedSelector instanceof Selector or return null.
  8. Conclusion: evaldCondition has three possible values null, undefined, normal. Path: packages/less/src/less/tree/selector.js 8 Path: packages/less/src/less/tree/ruleset.js 8-1 It is undefind. Path: packages/less/src/less/tree/atrule.js 8-2 It is null.

lumburr avatar Apr 27 '22 09:04 lumburr

Thanks for doing this research!

matthew-dean avatar May 04 '22 14:05 matthew-dean