-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: add validator utils #107
Conversation
WalkthroughThe recent updates primarily enhance the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Coverage report
Show new covered files 🐣
Show files with reduced coverage 🔻
Test suite run success198 tests passing in 6 suites. Report generated by 🧪jest coverage report action from 6103188 |
6d452fb
to
277c593
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #107 +/- ##
===========================================
- Coverage 100.00% 91.78% -8.22%
===========================================
Files 14 18 +4
Lines 4565 4818 +253
Branches 1082 1055 -27
===========================================
- Hits 4565 4422 -143
- Misses 0 389 +389
- Partials 0 7 +7 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Outside diff range and nitpick comments (8)
src/engine.ts (1)
Line range hint
19-19
: Avoid Using 'Function' as a TypeThe use of 'Function' as a type should be avoided due to its broad acceptance of any function-like value, which can lead to subtle bugs. It's recommended to explicitly define the function shape to ensure type safety and clarity.
- private readonly fn: Function; + private readonly fn: (data: unknown, bindings: Record<string, unknown>) => unknown; - private static compileAsSync(template: TemplateInput, options?: EngineOptions): Function { + private static compileAsSync(template: Template Input, options?: EngineOptions): (data: unknown, bindings: Record<string, unknown>) => unknown; - private static compileAsAsync(templateOrExpr: TemplateInput, options?: EngineOptions): Function { + private static compileAsAsync(templateOrExpr: TemplateInput, options?: EngineOptions): (data: unknown, bindings: Record<string, unknown>) => unknown; - static create(templateOrExpr: TemplateInput, options?: EngineOptions): JsonTemplateEngine { + static create(templateOrExpr: TemplateInput, options?: Engine Options): (data: unknown, bindings: Record<string, unknown>) => unknown;Also applies to: 21-21, 25-25, 34-34
src/lexer.ts (1)
Line range hint
370-370
: Avoid Usingthis
in Static ContextThe use of
this
in a static context can be confusing as it refers to the class itself rather than an instance. It's recommended to use the class name instead to avoid confusion and maintain clarity in the code.- this.isValidRegExp(regexp, modifiers) + JsonTemplateLexer.isValidRegExp(regexp, modifiers)src/translator.ts (2)
Line range hint
900-900
: Static context usage ofthis
is confusing.The static analysis tool flagged the use of
this
in a static context. This is generally a bad practice as it can lead to confusion about whatthis
refers to. It's recommended to use the class name instead ofthis
when referring to static methods or properties.- this.getPathOptions + JsonTemplateTranslator.getPathOptions - this.isArrayFilterExpr + JsonTemplateTranslator.isArrayFilterExpr - this.returnIsEmpty + JsonTemplateTranslator.returnIsEmpty - this.returnIsNotEmpty + JsonTemplateTranslator.returnIsNotEmpty - this.returnObjectValues + JsonTemplateTranslator.returnObjectValues - this.convertToSingleValueIfSafe + JsonTemplateTranslator.convertToSingleValueIfSafe - this.covertToArrayValue + JsonTemplateTranslator.covertToArrayValue
Line range hint
900-900
: Consider optimizing the initialization of variables.In the
translate
method, every call re-initializes thevars
,lastVarId
, andunusedVars
. If this method is called frequently, consider optimizing how these variables are reset to avoid potential performance bottlenecks.- this.vars = []; - this.lastVarId = 0; - this.unusedVars = []; + this.resetVars();And then implement a
resetVars
method that handles these operations.src/parser.ts (4)
Line range hint
1519-1519
: Clarify usage ofthis
in static context.The static method
ignoreEmptySelectors
usesthis
which can be confusing as it suggests that the method might be using instance-specific data, which it should not. Consider refactoring to use the class nameJsonTemplateParser
instead ofthis
to access static methods or properties.- return parts.filter(this.isValidPathPart); + return parts.filter(JsonTemplateParser.isValidPathPart);
Line range hint
1525-1525
: Clarify usage ofthis
in static context.Similar to the previous comment, the static method
combinePathOptionParts
usesthis
which can be misleading. Use the class name instead.- return newParts.push(this.createPathOptionPart(currPart, nextPart)); + return newParts.push(JsonTemplateParser.createPathOptionPart(currPart, nextPart));
Line range hint
1532-1532
: Clarify usage ofthis
in static context.Again in
convertToFunctionCallExpr
, replacethis
withJsonTemplateParser
to access static methods.- if (lastPart?.type === SyntaxType.SELECTOR && this.isSimpleSelector(lastPart)) { + if (lastPart?.type === SyntaxType.SELECTOR && JsonTemplateParser.isSimpleSelector(lastPart)) {
Line range hint
1574-1574
: Clarify usage ofthis
in static context.In the static method
updatePathExpr
, useJsonTemplateParser
instead ofthis
to call static methods.- if (shouldConvertAsBlock) this.convertToBlockExpr(expr); + if (shouldConvertAsBlock) JsonTemplateParser.convertToBlockExpr(expr);
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (12)
- src/engine.test.ts (1 hunks)
- src/engine.ts (2 hunks)
- src/errors/index.ts (1 hunks)
- src/errors/lexer.ts (1 hunks)
- src/errors/mapping.ts (1 hunks)
- src/errors/parser.ts (1 hunks)
- src/errors/translator.ts (1 hunks)
- src/lexer.ts (1 hunks)
- src/parser.ts (1 hunks)
- src/translator.ts (1 hunks)
- src/utils/converter.ts (4 hunks)
- test/scenarios/mappings/data.ts (1 hunks)
Files skipped from review due to trivial changes (2)
- src/errors/index.ts
- test/scenarios/mappings/data.ts
Additional context used
Biome
src/engine.ts
[error] 19-19: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
[error] 21-21: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
[error] 25-25: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
[error] 34-34: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
src/lexer.ts
[error] 370-370: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)
this refers to the class.
Unsafe fix: Use the class name instead.src/translator.ts
[error] 900-900: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)
this refers to the class.
Unsafe fix: Use the class name instead.src/parser.ts
[error] 1519-1519: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)
this refers to the class.
Unsafe fix: Use the class name instead.
[error] 1525-1525: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)
this refers to the class.
Unsafe fix: Use the class name instead.
[error] 1532-1532: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)
this refers to the class.
Unsafe fix: Use the class name instead.
[error] 1574-1574: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)
this refers to the class.
Unsafe fix: Use the class name instead.
[error] 562-562: Do not add then to an object. (lint/suspicious/noThenProperty)
GitHub Check: Coverage annotations (🧪 jest-coverage-report-action)
src/engine.ts
[warning] 64-64: 🌿 Branch is not covered
Warning! Not covered branch
[warning] 65-65: 🌿 Branch is not covered
Warning! Not covered branchsrc/utils/converter.ts
[warning] 262-262: 🧾 Statement is not covered
Warning! Not covered statement
[warning] 263-263: 🧾 Statement is not covered
Warning! Not covered statement
[warning] 264-264: 🧾 Statement is not covered
Warning! Not covered statement
[warning] 265-265: 🧾 Statement is not covered
Warning! Not covered statement
[warning] 261-267: 🌿 Branch is not covered
Warning! Not covered branch
GitHub Check: codecov/patch
src/utils/converter.ts
[warning] 262-265: src/utils/converter.ts#L262-L265
Added lines #L262 - L265 were not covered by tests
Additional comments not posted (11)
src/errors/lexer.ts (1)
1-1
: Class Declaration: JsonTemplateLexerErrorThe class
JsonTemplateLexerError
is correctly extending the baseError
class. This is a straightforward and clean implementation for custom error handling specific to the lexer component.src/errors/parser.ts (1)
1-1
: Class Declaration: JsonTemplateParserErrorSimilar to
JsonTemplateLexerError
, theJsonTemplateParserError
extends the baseError
class appropriately. This maintains consistency across custom error classes for different components, aiding in clear and specific error reporting.src/errors/translator.ts (1)
1-1
: Class Declaration: JsonTemplateTranslatorErrorThe
JsonTemplateTranslatorError
also extends theError
class, which is consistent with the other custom error classes introduced in this PR. This consistency is beneficial for maintaining a uniform approach to error handling across different modules.src/engine.test.ts (1)
3-69
: Comprehensive Test Suite forJsonTemplateEngine
The test suite thoroughly covers the new functionality introduced in
JsonTemplateEngine
. It includes tests for valid and invalid JSON paths and mappings, which is essential for ensuring the robustness of the validation logic. The tests are well-structured and cover a variety of cases, which is great for catching edge cases early in development.src/engine.ts (2)
47-59
: Efficient JSON Path Validation MethodThe
isValidJSONPath
method efficiently checks the validity of JSON paths using structured parsing and error handling. This method is crucial for ensuring that only valid paths are processed, thus preventing potential runtime errors and ensuring data integrity.
61-83
: Mapping Validation and Preparation LogicThe methods
prepareMappings
andvalidateMappings
are well-implemented, with clear logic separation and error handling. They ensure that the mappings are correctly formatted before being processed, which is essential for the stability and reliability of the mapping functionality.Tools
GitHub Check: Coverage annotations (🧪 jest-coverage-report-action)
[warning] 64-64: 🌿 Branch is not covered
Warning! Not covered branch
[warning] 65-65: 🌿 Branch is not covered
Warning! Not covered branchsrc/utils/converter.ts (1)
96-100
: Enhanced Error Specificity in Conversion UtilitiesThe use of
JsonTemplateMappingError
in various conversion utility functions enhances the specificity and traceability of errors, which is crucial for debugging and maintaining the code. The custom error messages provide clear context about the issue, making it easier to diagnose and fix problems.Also applies to: 118-121, 262-265
src/translator.ts (2)
9-9
: Update the import statement for JsonTemplateTranslatorError.The import path for
JsonTemplateTranslatorError
has been updated to reference the specific file instead of a general directory, which is a good practice for maintainability and clarity.
Line range hint
900-900
: Add a default case in the switch statement oftranslateExpr
.It's good practice to have a default case in switch statements to handle unexpected values gracefully.
[REFACTOR_Suggestion]
switch (expr.type) { ... + default: + throw new Error("Unsupported expression type: " + expr.type); }src/parser.ts (2)
4-5
: Update import paths to specific error modules.The import paths for
JsonTemplateParserError
andJsonTemplateLexerError
have been updated to point directly to their respective modules. This change is good as it avoids potential circular dependencies and makes the import paths clearer.
Line range hint
562-562
: Check the use of 'then' in object properties.The static analysis tool flagged the use of 'then' as a property in an object which might be a typo or incorrect property name. Please verify if this is intentional or needs correction.
Verification successful
No instances of the 'then' property were found in
src/parser.ts
, confirming that it is not used inappropriately within object definitions.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Search for 'then' property within object definitions. # Test: Search for 'then' property. Expect: No occurrences unless explicitly justified. rg --type typescript $'.then' src/parser.tsLength of output: 77
Script:
#!/bin/bash # Description: Search for 'then' property within object definitions in src/parser.ts # Test: Search for 'then' property. Expect: No occurrences unless explicitly justified. rg '\.then' src/parser.tsLength of output: 27
277c593
to
a6fc5d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
Outside diff range and nitpick comments (7)
src/engine.ts (1)
Line range hint
19-19
: Replace genericFunction
type with specific function signaturesThe use of the
Function
type is discouraged due to its broad acceptance of any function-like values, which can lead to bugs. Consider specifying more detailed function signatures for clarity and type safety.- private readonly fn: Function; + private readonly fn: (data: any, bindings: any) => any;Also applies to: 21-21, 25-25, 34-34
test/scenarios/mappings/data.ts (1)
155-163
: Standardized error messages across different scenariosThe error message 'Invalid mapping' is used consistently across various scenarios. This is good for consistency, but consider providing more specific error messages to help diagnose issues more effectively.
src/lexer.ts (1)
Line range hint
370-370
: Avoid usingthis
in static contextThe use of
this
in a static method can lead to confusion and bugs. Consider using the class name instead to access static members or methods.- this.isValidRegExp(regexp, modifiers); + JsonTemplateLexer.isValidRegExp(regexp, modifiers);src/translator.ts (3)
Line range hint
900-900
: Clarify usage ofthis
in static context.The use of
this
in a static context can be confusing as it suggests an instance-specific operation, which is not the case in static methods. Consider using the class nameJsonTemplateTranslator
instead to clarify that these operations are class-specific.- this.translateExpr(expr.update, update, ctx); + JsonTemplateTranslator.translateExpr(expr.update, update, ctx);
Line range hint
900-900
: Ensure correct use of class name in static context.The use of
this
in a static method can lead to confusion or errors in some languages or environments, asthis
typically refers to an instance of the class, not the class itself. To ensure clarity and correctness, replacethis
withJsonTemplateTranslator
when calling static methods or accessing static properties.- this.generateAssignmentCode(dest, incrementCode); + JsonTemplateTranslator.generateAssignmentCode(dest, incrementCode);
Line range hint
900-900
: Clarification on static method calls within the class.Static methods should be called with the class name rather than
this
to avoid confusion and to make the code more readable and maintainable, especially in a static context wherethis
does not refer to an instance of the class.- this.acquireVar(); + JsonTemplateTranslator.acquireVar();src/parser.ts (1)
Line range hint
1519-1519
: Clarification on usingthis
in static methods.The static analysis tool flagged the use of
this
in static methods as potentially confusing. In static methods,this
refers to the class itself, not an instance. If these methods are intended to be static, consider using the class name (JsonTemplateParser
) instead ofthis
to access static properties or methods, which could improve the clarity of the code.- this.someStaticMethod(); + JsonTemplateParser.someStaticMethod();Also applies to: 1525-1525, 1532-1532, 1574-1574
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (14)
- src/engine.test.ts (1 hunks)
- src/engine.ts (2 hunks)
- src/errors/index.ts (1 hunks)
- src/errors/lexer.ts (1 hunks)
- src/errors/mapping.ts (1 hunks)
- src/errors/parser.ts (1 hunks)
- src/errors/translator.ts (1 hunks)
- src/lexer.ts (1 hunks)
- src/parser.ts (1 hunks)
- src/translator.ts (1 hunks)
- src/utils/converter.ts (5 hunks)
- test/scenarios/mappings/all_features.json (1 hunks)
- test/scenarios/mappings/data.ts (4 hunks)
- test/scenarios/mappings/simple_array_mappings.json (1 hunks)
Files skipped from review due to trivial changes (4)
- src/errors/index.ts
- src/errors/lexer.ts
- src/errors/translator.ts
- test/scenarios/mappings/simple_array_mappings.json
Additional context used
Learnings (1)
src/utils/converter.ts (1)
User: koladilip PR: rudderlabs/rudder-json-template-engine#97 File: src/utils/converter.ts:169-184 Timestamp: 2024-06-15T03:36:36.164Z Learning: Validations for `flatMapping` and `currentOutputPropAST` are performed before they are passed to the `handleNextParts` function in `src/utils/converter.ts`.
Biome
src/engine.ts
[error] 19-19: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
[error] 21-21: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
[error] 25-25: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
[error] 34-34: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
src/lexer.ts
[error] 370-370: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)
this refers to the class.
Unsafe fix: Use the class name instead.src/translator.ts
[error] 900-900: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)
this refers to the class.
Unsafe fix: Use the class name instead.src/parser.ts
[error] 1519-1519: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)
this refers to the class.
Unsafe fix: Use the class name instead.
[error] 1525-1525: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)
this refers to the class.
Unsafe fix: Use the class name instead.
[error] 1532-1532: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)
this refers to the class.
Unsafe fix: Use the class name instead.
[error] 1574-1574: Using this in a static context can be confusing. (lint/complexity/noThisInStatic)
this refers to the class.
Unsafe fix: Use the class name instead.
[error] 562-562: Do not add then to an object. (lint/suspicious/noThenProperty)
GitHub Check: Coverage annotations (🧪 jest-coverage-report-action)
src/engine.ts
[warning] 64-64: 🌿 Branch is not covered
Warning! Not covered branch
[warning] 65-65: 🌿 Branch is not covered
Warning! Not covered branchsrc/utils/converter.ts
[warning] 87-87: 🧾 Statement is not covered
Warning! Not covered statement
[warning] 286-286: 🧾 Statement is not covered
Warning! Not covered statement
[warning] 287-287: 🧾 Statement is not covered
Warning! Not covered statement
[warning] 288-288: 🧾 Statement is not covered
Warning! Not covered statement
[warning] 289-289: 🧾 Statement is not covered
Warning! Not covered statement
[warning] 86-88: 🌿 Branch is not covered
Warning! Not covered branch
[warning] 285-291: 🌿 Branch is not covered
Warning! Not covered branch
Additional comments not posted (10)
src/errors/mapping.ts (1)
1-11
: Class implementation looks solid!The
JsonTemplateMappingError
class is well-implemented with appropriate TypeScript annotations and a detailed constructor that enhances error messages. Good job on addressing the previous feedback.test/scenarios/mappings/all_features.json (1)
14-17
: New mapping for coupons is correctly implemented.The mapping from
$.coupon
to$.events[0].items[*].coupon_code
is well-formed and follows JSONPath syntax. This should work as intended in the engine.src/engine.test.ts (2)
3-25
: Comprehensive testing of JSON path validation.The test cases for
isValidJSONPath
are comprehensive, covering both valid and invalid scenarios effectively. This ensures robust validation within the engine.
27-67
: Robust testing for mappings validation.The test cases for
validateMappings
effectively check for compatibility and correctness of mappings. The scenarios include both valid mappings and expected failures, which is crucial for ensuring the engine's reliability in handling mappings.src/engine.ts (2)
47-59
: Ensure robustness in JSON path validation methodThe
isValidJSONPath
method uses a try-catch block to handle exceptions which is good for robustness. However, consider logging the error or providing more detailed feedback when the path validation fails, as this could aid in debugging and provide clearer error messages to the users.
[REFACTOR_SUGGESTion]
61-67
: Refactor suggestion forprepareMappings
methodThe method
prepareMappings
efficiently maps input and output by providing defaults. However, it's crucial to ensure that the propertiesfrom
andto
are always expected to be optionally present in the mappings, as this code assumes their existence.Tools
GitHub Check: Coverage annotations (🧪 jest-coverage-report-action)
[warning] 64-64: 🌿 Branch is not covered
Warning! Not covered branch
[warning] 65-65: 🌿 Branch is not covered
Warning! Not covered branchtest/scenarios/mappings/data.ts (1)
Line range hint
79-96
: Addition ofcoupon_code
in the output scenariosThe addition of
coupon_code
to the scenarios is consistent with the new mappings added. Ensure that all related mappings and transformations are correctly implemented and covered by unit tests to avoid issues in production.src/translator.ts (1)
9-9
: Update import path forJsonTemplateTranslatorError
.The import path for
JsonTemplateTranslatorError
has been updated to reflect its new location under theerrors/translator
directory. This is consistent with the restructuring of error classes as mentioned in the PR summary and ensures that imports remain accurate and maintainable.src/parser.ts (2)
4-5
: Update import paths to reflect new error class locations.The import statements for
JsonTemplateParserError
andJsonTemplateLexerError
have been updated to reflect their new locations in theerrors/parser
anderrors/lexer
directories. This change aligns with the PR's objective to refactor error handling by organizing error classes into specific files.
Line range hint
562-562
: Verify the use of a property namedthen
.The static analysis tool flagged the use of a property named
then
as potentially suspicious. This might be a false positive, but it's important to ensure that this property is not unintentionally making an object look like a Promise, which could lead to unexpected behavior.Verification successful
No issue with the
then
property usage.The
then
property is used within the context of translating conditional expressions in bothsrc/reverse_translator.ts
andsrc/translator.ts
. This usage does not mimic Promises and should not cause any confusion.
src/reverse_translator.ts
:translateConditionalExpressionBody(expr.then)
src/translator.ts
:translateExpr(expr.then, dest, ctx)
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Search for the usage of the 'then' property in the project. rg --type typescript $'.then'Length of output: 63
Script:
#!/bin/bash # Description: Search for the usage of the 'then' property in TypeScript files. rg '\.then' --glob '*.ts'Length of output: 195
Script:
#!/bin/bash # Extract the context where `then` is used in `src/reverse_translator.ts`. rg --context 5 'then' src/reverse_translator.ts # Extract the context where `then` is used in `src/translator.ts`. rg --context 5 'then' src/translator.tsLength of output: 951
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/utils/converter.ts (5 hunks)
Additional context used
Learnings (1)
src/utils/converter.ts (1)
User: koladilip PR: rudderlabs/rudder-json-template-engine#97 File: src/utils/converter.ts:169-184 Timestamp: 2024-06-15T03:36:36.164Z Learning: Validations for `flatMapping` and `currentOutputPropAST` are performed before they are passed to the `handleNextParts` function in `src/utils/converter.ts`.
GitHub Check: codecov/patch
src/utils/converter.ts
[warning] 86-86: src/utils/converter.ts#L86
Added line #L86 was not covered by tests
[warning] 88-88: src/utils/converter.ts#L88
Added line #L88 was not covered by tests
[warning] 287-290: src/utils/converter.ts#L287-L290
Added lines #L287 - L290 were not covered by tests
GitHub Check: Coverage annotations (🧪 jest-coverage-report-action)
src/utils/converter.ts
[warning] 85-86: 🌿 Branch is not covered
Warning! Not covered branch
Additional comments not posted (1)
src/utils/converter.ts (1)
2-2
: Imports and Constants:The import of
JsonTemplateMappingError
from the new errors directory is correct and aligns with the PR's purpose of enhancing error handling. The use ofEMPTY_EXPR
from constants ensures consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Outside diff range and nitpick comments (1)
src/reverse_translator.ts (1)
Line range hint
3-3
: Ensure consistent use of destructuring in imports.For consistency and to reduce the length of the import lines, consider using destructuring for all imports from the same module.
- import { ArrayExpression, ArrayFilterExpression, AssignmentExpression, BinaryExpression, BlockExpression, ConditionalExpression, DefinitionExpression, EngineOptions, Expression, FunctionCallExpression, FunctionExpression, IncrementExpression, IndexFilterExpression, LambdaArgExpression, LiteralExpression, LoopControlExpression, LoopExpression, ObjectExpression, ObjectFilterExpression, ObjectPropExpression, PathExpression, PathOptions, PathType, RangeFilterExpression, ReturnExpression, SelectorExpression, SpreadExpression, StatementsExpression, SyntaxType, ThrowExpression, TokenType, UnaryExpression } from './types'; + import * as Types from './types';
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- src/engine.ts (2 hunks)
- src/reverse_translator.ts (1 hunks)
Additional context used
Biome
src/engine.ts
[error] 19-19: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
[error] 21-21: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
[error] 25-25: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
[error] 34-34: Don't use 'Function' as a type. (lint/complexity/noBannedTypes)
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
Additional comments not posted (2)
src/engine.ts (1)
3-3
: Refactor the import ofJsonTemplateMappingError
to use destructuring.To maintain consistency with other import statements in this file, consider using destructuring for importing
JsonTemplateMappingError
.- import { JsonTemplateMappingError } from './errors/mapping'; + import { JsonTemplateMappingError, JsonTemplateLexer, JsonTemplateParser, JsonTemplateReverseTranslator, JsonTemplateTranslator } from './errors';Likely invalid or redundant comment.
src/reverse_translator.ts (1)
Line range hint
5-5
: Optimize string operations in translation methods.Using template literals or array joins for string operations in the
translate
method can enhance performance and readability, especially when manipulating strings based on conditional logic.
[PERFORMANCE]let code: string = this.translateExpression(expr); - code = code.replace(/\.\s+\./g, '.'); + code = code.replaceAll(/\.\s+\./g, '.'); if (this.options?.defaultPathType === PathType.JSON) { - code = code.replace(/\^/g, '$'); + code = code.replaceAll(/\^/g, '$'); }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/utils/converter.ts (5 hunks)
Additional context used
Learnings (1)
src/utils/converter.ts (1)
User: koladilip PR: rudderlabs/rudder-json-template-engine#97 File: src/utils/converter.ts:169-184 Timestamp: 2024-06-15T03:36:36.164Z Learning: Validations for `flatMapping` and `currentOutputPropAST` are performed before they are passed to the `handleNextParts` function in `src/utils/converter.ts`.
GitHub Check: codecov/patch
src/utils/converter.ts
[warning] 86-86: src/utils/converter.ts#L86
Added line #L86 was not covered by tests
[warning] 88-88: src/utils/converter.ts#L88
Added line #L88 was not covered by tests
[warning] 287-290: src/utils/converter.ts#L287-L290
Added lines #L287 - L290 were not covered by tests
GitHub Check: Coverage annotations (🧪 jest-coverage-report-action)
src/utils/converter.ts
[warning] 288-288: 🧾 Statement is not covered
Warning! Not covered statement
[warning] 286-292: 🌿 Branch is not covered
Warning! Not covered branch
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/utils/converter.ts (4 hunks)
Additional context used
GitHub Check: codecov/patch
src/utils/converter.ts
[warning] 113-113: src/utils/converter.ts#L113
Added line #L113 was not covered by tests
[warning] 295-298: src/utils/converter.ts#L295-L298
Added lines #L295 - L298 were not covered by tests
GitHub Check: Coverage annotations (🧪 jest-coverage-report-action)
src/utils/converter.ts
[warning] 112-114: 🌿 Branch is not covered
Warning! Not covered branch
What are the changes introduced in this PR?
Add validators for mappings and refactor error classes
What is the related Linear task?
Resolves INT-2240
Please explain the objectives of your changes below
Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here
Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?
N/A
Any new dependencies introduced with this change?
N/A
Any new generic utility introduced or modified. Please explain the changes.
N/A
Any technical or performance related pointers to consider with the change?
N/A
@coderabbitai review
Developer checklist
My code follows the style guidelines of this project
No breaking changes are being introduced.
All related docs linked with the PR?
All changes manually tested?
Any documentation changes needed with this change?
Is the PR limited to 10 file changes?
Is the PR limited to one linear task?
Are relevant unit and component test-cases added?
Reviewer checklist
Is the type of change in the PR title appropriate as per the changes?
Verified that there are no credentials or confidential data exposed with the changes.
Summary by CodeRabbit
New Features
Bug Fixes
Tests