CMU-17313Q / NodeBB

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

Refactor NodeBB/src/flags.js to reduce Cognitive Complexity from 16 to 15 #65

Open fdounis opened 2 months ago

fdounis commented 2 months ago

This pull request refactors the getFlagIdsWithFilters function in flags.js to address multiple concerns, including reducing Cognitive Complexity and fixing various linting errors. The following changes were made:

  1. Reduced Cognitive Complexity:

    • Extracted filter initialization logic into a new initializeFilters function to separate concerns.
    • Created a buildSets function to encapsulate the logic for constructing sets and orSets, improving the readability of the main function.
    • Extracted the logic for fetching flag IDs based on sets into a new getFlagIdsFromSets function.
    • Separated the processing of orSets into two functions: getFlagIdsFromOrSets to handle retrieval and mergeFlagIds to handle the merging logic, reducing nested conditions and overall complexity.
  2. Fixed Linting Errors:

    • Removed unnecessary parentheses around single arguments in arrow functions (specifically in the getFlagIdsFromOrSets function).
    • Adjusted line breaks to eliminate unexpected line breaks before expressions and to comply with style rules.
    • Corrected unexpected newlines before closing parentheses in function calls, ensuring proper formatting and adherence to style guidelines.
    • Eliminated an unnecessary else statement after a return, as the else was redundant and removed to streamline the code.

This pull request resolves Issue #53

sonarcloud[bot] commented 2 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

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

See analysis details on SonarCloud

coveralls commented 2 months ago

Pull Request Test Coverage Report for Build 10674129981

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
src/flags.js 20 21 95.24%
<!-- Total: 20 21 95.24% -->
Totals Coverage Status
Change from base Build 10550029021: 0.001%
Covered Lines: 22330
Relevant Lines: 25589

💛 - Coveralls