CMU-17313Q / NodeBB

GNU General Public License v3.0
0 stars 50 forks source link

src/flags.js (Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.) #60

Open ssaigh opened 2 months ago

ssaigh commented 2 months ago

This pull request resolves issue #10 Resolves https://github.com/CMU-17313Q/NodeBB/issues/10

File name: src/flags.js

Refactoring the flag.validate function to reduce complexity by removing the nest if statements. This reduces the complexity from 18 to 15. Fix Cognitive Complexity in src/flags.js.

Changes to the original code to reduce complexity:

Removed unnecessary else if statement: I removed the else if conditions because each of the conditionals contained throws, which would automatically make you return and leave the function. Through doing this, I was able to remove deep nested if statements which reduced its complexity.

coveralls commented 2 months ago

Pull Request Test Coverage Report for Build 10719473390

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
src/flags.js 6 8 75.0%
<!-- Total: 6 8 75.0% -->
Files with Coverage Reduction New Missed Lines %
src/flags.js 2 78.96%
<!-- Total: 2 -->
Totals Coverage Status
Change from base Build 10550029021: 0.01%
Covered Lines: 22328
Relevant Lines: 25585

💛 - Coveralls
sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
1 New issue
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud