dxp/issues#872: Update the code with maximum 6 level of cognitive complexity...
Changes:
I added two new ESLint rules:
- Max 6 cognitive complexity
- Mandatory curly brackets for blocks These rules help us to write more readable code. These rules are not enough though as ESLint can't understand the logic of the code and decide about the complexity of the code. It just checks the cognitive complexity. It's the developer's responsibility to write readable code and add comments when needed. And we must always keep this quote in mind:
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live
_(Obviously joking, if it's not clear already
Other than that, I found and fixed an endless rendering issue in a separate commit.
Test steps:
- Check out the new ESLint rules
- Run
npm run lint
and make sure there is no error like the below:
- Run the project and check out the developer tools' console and make sure there is no new error there.
- Make sure the app work as expected.
Concern:
I made the code simpler and more readable but we still need to add more comments to explain different parts of the code. For example, in the searchResultsLocal.tsx
file, there is a logic for finding the right fields name that I can't explain (because I was not involved in the decision-making part). Someone familiar with the project must write comments there and explain the code so other devs can also understand them.