Closed Bug 1262769 Opened 8 years ago Closed 3 years ago

Reduce the eslint cyclomatic complexity threshold to 20

Categories

(DevTools :: General, defect, P3)

defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: pbro, Unassigned)

References

Details

(Whiteboard: [btpp-backlog])

When bug 1257246 lands, we will have eslint 2 running on our code. We have eslint 1.10.7 running right now.

eslint 2 comes with many changes, one of which is a change in the complexity rule.
This rule used to require a threshold to be passed. Passing a threshold would make the rule count the number of branches in a function and report an error if this number was higher than the threshold.

We have this rule configured in devtools/.eslintrc
However, we forgot to configure a threshold.
So, essentially, this rule was useless.

Now, with eslint 2, the rule defaults to 20. And that means that a few of our functions now produce errors because they are too complex.

In bug 1257246, we are temporarily configuring a threshold of 35, just for the sake of passing eslint and landing the bug.
Therefore, in this bug here, the goal is to go back to a threshold of 20 (or maybe investigate if we can go lower), and fix the functions that are higher than that. 
At the time of writing, these are the incriminated functions:

\devtools\client\inspector\markup\markup.js
  606:15  error  Function '_onKeyDown' has a complexity of 32   complexity

\devtools\client\netmonitor\netmonitor-view.js
  1112:11  error  Function 'sortBy' has a complexity of 21          complexity
  1498:19  error  Function '_flushRequests' has a complexity of 35  complexity
  1781:30  error  Function 'anonymous' has a complexity of 26       complexity

So, here's what to do:
1 - wait for bug 1257246 to land
2 - change 35 to 20 in devtools/.eslintrc in the complexity rule
3 - run eslint on devtools (./mach eslint devtools)
4 - notice the failures
5 - fix the failures
(6 - optionally repeat steps 2 to 5 by changing 20 to something even lower. Note that we don't necessarily want to have a number too low, but 20 represents a pretty complex function already, so if we can easily go down to, say, 15, that'd be great).
Priority: -- → P3
Whiteboard: [btpp-backlog]
Product: Firefox → DevTools
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.