Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 6 commits into
base: f24
Choose a base branch
from

Conversation

fdounis
Copy link

@fdounis fdounis commented Sep 2, 2024

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

Copy link

sonarcloud bot commented Sep 2, 2024

@coveralls
Copy link

Pull Request Test Coverage Report for Build 10674129981

Details

  • 20 of 21 (95.24%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 82.672%

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

💛 - Coveralls

@fdounis fdounis changed the title Refactor NodeBB/src/flags.js to fix linting errors Refactor NodeBB/src/flags.js to reduce Cognitive Complexity from 16 to 15 Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants