Skip to content

Conversation

@Slashmsu
Copy link
Collaborator

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

🎉 Pull Request

Description

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality
    to not work as expected)
  • 📚 Documentation update
  • 🔧 Configuration/build changes
  • ✅ Test improvements
  • ♻️ Code refactoring (no functional changes)

Related Issue

Fixes #(issue number)

Changes Made

Testing

  • All existing tests pass (npm test)
  • Added new tests for the changes
  • Tested manually with examples
  • Linting passes (npm run lint)
  • Type checking passes (npm run type-check)

Checklist

  • My code follows the project's code style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

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:


Thank you for contributing to SomonScript! 🚀

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
@github-actions
Copy link

✅ 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
@github-actions
Copy link

✅ 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
@github-actions
Copy link

✅ Tests completed on Node.js 20.x: success

@github-actions
Copy link

✅ Tests completed on Node.js 20.x: success

@sonarqubecloud
Copy link

@github-actions
Copy link

✅ 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants