less / less.js

Less. The dynamic stylesheet language.
http://lesscss.org
Apache License 2.0
17k stars 3.41k forks source link

Fix eslint warnimg #3709

Closed lumburr closed 1 year ago

lumburr commented 2 years ago

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:

matthew-dean commented 2 years ago

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.

lumburr commented 2 years ago
  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.
matthew-dean commented 2 years ago

Thanks for doing this research!