-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: reduce nextToken() cognitive complexity from 17 to 15 #28
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
Open
Slashmsu
wants to merge
5
commits into
main
Choose a base branch
from
claude/reduce-nexttoken-complexity-01BLUw1YAYSXfMvDHoHbUXyK
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
refactor: reduce nextToken() cognitive complexity from 17 to 15 #28
Slashmsu
wants to merge
5
commits into
main
from
claude/reduce-nexttoken-complexity-01BLUw1YAYSXfMvDHoHbUXyK
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Refactored the nextToken() method in the Lexer class to reduce its cognitive complexity by extracting logic into three helper methods: - handleSwitchCharacters(): Handles basic punctuation and arithmetic operators - handleComparisonAndBitwiseOperators(): Handles comparison and bitwise operators - handleLiteralsAndIdentifiers(): Handles strings, numbers, and identifiers This refactoring reduces the cognitive complexity from 17 to below the SonarQube threshold of 15 while maintaining all existing functionality. All 58 lexer tests pass successfully. Fixes SonarQube cognitive complexity issue in src/lexer.ts:262
|
✅ Tests completed on Node.js 20.x: success |
- Use optional chain expressions for cleaner null checks (codegen.ts) - Mark never-reassigned class members as readonly (parser.ts, type-checker.ts, module-system files) - Use node: prefix for Node.js built-in imports (resource-limiter.ts, runtime-config.ts, structured-logger.ts, production-validator.ts) - Replace Array with Set for membership checks (config.ts, module-registry.ts, module-system.ts) - Refactor nested template literals for better readability (module-system.ts) These changes improve code maintainability, performance, and readability while adhering to modern TypeScript and Node.js best practices. Addresses SonarQube code smell issues
|
✅ Tests completed on Node.js 20.x: success |
- Replace nested ternary operations with if-else statements (type-checker.ts, prometheus-metrics.ts) - Use optional chain expressions for cleaner null checks (type-checker.ts: 7 instances) - Use String#startsWith instead of array indexing (modular-lexer-compatible.ts) - Remove useless assignment to unused variable (application-layer.ts) These changes improve code readability and maintainability while following JavaScript/TypeScript best practices. Addresses additional SonarQube code smell issues
|
✅ Tests completed on Node.js 20.x: success |
|
✅ Tests completed on Node.js 20.x: success |
|
|
✅ Tests completed on Node.js 20.x: success |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



Refactored the nextToken() method in the Lexer class to reduce its cognitive complexity by extracting logic into three helper methods:
This refactoring reduces the cognitive complexity from 17 to below the SonarQube threshold of 15 while maintaining all existing functionality. All 58 lexer tests pass successfully.
Fixes SonarQube cognitive complexity issue in src/lexer.ts:262
🎉 Pull Request
Description
Type of Change
to not work as expected)
Related Issue
Fixes #(issue number)
Changes Made
Testing
npm test)npm run lint)npm run type-check)Checklist
Additional Context
📋 License Information
SomonScript is open source software licensed under the MIT License.
By submitting this pull request, you agree that your contributions will be
licensed under the MIT License.
For contribution guidelines, please review:
guidelines
Thank you for contributing to SomonScript! 🚀