-
Notifications
You must be signed in to change notification settings - Fork 171
Description
Summary
The packages/jmespath
package contains 4 MAJOR severity code quality issues identified by SonarQube where private class members are never reassigned after initialization but are not marked as readonly
. These issues affect core JMESPath parsing and interpretation functionality:
- Parser.ts (2 issues):
#projectionStop
(line 51) and#maxCacheSize
(line 59) - TreeInterpreter.ts (1 issue):
#functions
(line 28) - Lexer.ts (1 issue):
#consumeComparatorSigns
(line 84)
All of these are private members that are initialized once and never modified, making them ideal candidates for the readonly
modifier.
Why is this needed?
- Code Quality: Improves code clarity by explicitly marking immutable members as readonly
- SonarQube Compliance: Resolves 4 MAJOR severity issues (typescript:S2933)
- Type Safety: Prevents accidental reassignment of these critical configuration members
- Developer Intent: Makes the immutable nature of these members explicit to future maintainers
- Best Practices: Follows TypeScript best practices for class member declarations
The JMESPath package is a core utility for JSON path expressions used throughout Powertools, so maintaining high code quality standards here is particularly important.
Solution
Important
The following changes are included as reference to help you understand the refactoring. Before implementing, please make sure to check the codebase and ensure that they make sense and they are exhaustive.
1. Fix Parser.ts (2 members)
Current code:
class Parser {
// ...
#projectionStop: Set<string>;
// ...
#maxCacheSize: number;
// ...
}
Improved code:
class Parser {
// ...
readonly #projectionStop: Set<string>;
// ...
readonly #maxCacheSize: number;
// ...
}
2. Fix TreeInterpreter.ts (1 member)
Current code:
class TreeInterpreter {
// ...
#functions: Functions;
// ...
}
Improved code:
class TreeInterpreter {
// ...
readonly #functions: Functions;
// ...
}
3. Fix Lexer.ts (1 member)
Current code:
class Lexer {
// ...
#consumeComparatorSigns: Set<string>;
// ...
}
Improved code:
class Lexer {
// ...
readonly #consumeComparatorSigns: Set<string>;
// ...
}
These changes:
- Make the immutable nature of these members explicit
- Prevent accidental reassignment in future code changes
- Follow TypeScript best practices for class design
- Improve code readability and maintainability
Implementation Details
-
Files to modify:
packages/jmespath/src/Parser.ts
(lines 51, 59)packages/jmespath/src/TreeInterpreter.ts
(line 28)packages/jmespath/src/Lexer.ts
(line 84)
-
Testing:
- Ensure all existing tests continue to pass
- Run type checking to verify no TypeScript errors are introduced
- Verify that the readonly modifier doesn't break any existing functionality
-
Validation:
- Run
npm run test:unit -w packages/jmespath
to ensure no regressions - Run
npm run lint -w packages/jmespath
to verify code style compliance - Run
npm run build -ws
to verify TypeScript compilation - Run SonarQube analysis to confirm issues are resolved
- Run
Additional Context
This issue was identified as part of a SonarQube code quality review. The JMESPath package is a foundational utility used for JSON path expressions throughout the Powertools ecosystem, making code quality improvements here particularly valuable.
These changes are purely declarative improvements that should not change any functionality or behavior.
SonarQube Issue Keys:
AZItlgXScEUs2753LD6S
- Parser.ts #projectionStopAZItlgXScEUs2753LD6T
- Parser.ts #maxCacheSizeAZItlgWzcEUs2753LD6R
- TreeInterpreter.ts #functionsAZItlgV9cEUs2753LD6Q
- Lexer.ts #consumeComparatorSigns
Acknowledgment
- This request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status