-
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
fix: add prefix for wildcard prop values #68
Conversation
WalkthroughThe changes involve removing 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
Test suite run success166 tests passing in 4 suites. Report generated by 🧪jest coverage report action from cf4a957 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #68 +/- ##
===========================================
Coverage 100.00% 100.00%
===========================================
Files 10 14 +4
Lines 3078 4539 +1461
Branches 726 1071 +345
===========================================
+ Hits 3078 4539 +1461 ☔ 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: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/translator.ts (2 hunks)
Additional comments not posted (2)
src/translator.ts (2)
545-547
: Introduced a new static methodtranslateObjectWildcardValue
to handle wildcard property values.This method centralizes the logic for handling wildcard values, which enhances maintainability and reduces duplication. Good use of static method to encapsulate utility logic that does not depend on instance state.
554-557
: RefactoredtranslateObjectWildcardValueExpr
to use the newtranslateObjectWildcardValue
method.This change ensures that the translation logic for wildcard values is reused effectively. It's a good practice to separate concerns, making the code cleaner and easier to maintain.
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- src/utils/converter.ts (4 hunks)
- test/scenarios/mappings/data.ts (2 hunks)
- test/scenarios/mappings/mappings_with_root_fields.json (1 hunks)
Files skipped from review due to trivial changes (1)
- test/scenarios/mappings/mappings_with_root_fields.json
Additional comments not posted (5)
test/scenarios/mappings/data.ts (3)
7-7
: The addition of thecoupon
field is correctly implemented.
189-189
: The addition of thecoupon_code
field for product 1 is correctly implemented.
195-195
: The addition of thecoupon_code
field for products 2 and 3 is correctly implemented.Also applies to: 202-202
src/utils/converter.ts (2)
62-87
: The changes in theprocessAllFilter
function enhance its flexibility and correctness in handling different types of expressions.
Line range hint
143-161
: The changes in thehandleNextPart
function improve its ability to handle different filters and selectors, aligning with the PR's objectives.
Release-As: 0.11.0
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: 1
Outside diff range and nitpick comments (3)
src/lexer.ts (1)
Line range hint
366-366
: Address the use ofthis
in a static context.- this refers to the class. + JsonTemplateLexer refers to the class.src/translator.ts (1)
Line range hint
900-900
: Address the use ofthis
in a static context.- this refers to the class. + JsonTemplateTranslator refers to the class.src/parser.ts (1)
Line range hint
1469-1469
: Clarify usage ofthis
in static context.The static analysis tool has flagged the use of
this
in a static context as potentially confusing. It's recommended to use the class name instead ofthis
to refer to static methods or properties. This change will make the code clearer and adhere to best practices.Also applies to: 1475-1475, 1482-1482, 1513-1513
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (9)
- src/lexer.ts (1 hunks)
- src/parser.ts (5 hunks)
- src/reverse_translator.ts (3 hunks)
- src/translator.ts (5 hunks)
- src/types.ts (2 hunks)
- src/utils/converter.ts (6 hunks)
- test/scenarios/objects/context_props.jt (1 hunks)
- test/scenarios/objects/data.ts (2 hunks)
- test/scenarios/objects/invalid_context_prop.jt (1 hunks)
Files skipped from review due to trivial changes (3)
- src/reverse_translator.ts
- src/types.ts
- test/scenarios/objects/context_props.jt
Files skipped from review as they are similar to previous changes (1)
- src/utils/converter.ts
Additional context used
Biome
src/lexer.ts
[error] 366-366: 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] 1469-1469: 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] 1475-1475: 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] 1482-1482: 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] 1513-1513: 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] 561-561: Do not add then to an object. (lint/suspicious/noThenProperty)
Additional comments not posted (5)
test/scenarios/objects/invalid_context_prop.jt (1)
4-4
: Ensure the new property key@e key
is correctly handled in the lexer and parser.Verification successful
The handling of the
@
symbol is present in bothsrc/lexer.ts
andsrc/parser.ts
, indicating that the lexer and parser are equipped to process tokens starting with@
. However, there is no specific handling for@e key
, which suggests that the lexer and parser are designed to handle@
tokens generically.
src/parser.ts
contains multiple instances where@
is matched and processed.src/lexer.ts
also includes logic to match@
and other related characters.Given this, it appears that the lexer and parser are capable of handling
@e key
through their existing mechanisms for@
tokens.
src/parser.ts
- Line:
} else if (this.lexer.match('@') || this.lexer.match('#')) {
- Line:
while (this.lexer.match('@') || this.lexer.match('#') || this.lexer.matchToArray()) {
- Line:
if (this.lexer.match('@')) {
- Line:
'@': undefined,
src/lexer.ts
- Line:
return this.match('@') && this.matchID(1);
- Line:
return value === '.' || value === '..' || value === '^' || value === '@';
- Line:
if (',;:{}()[]^+-*/%!><|=@~#?\n'.includes(ch1)) {
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the handling of `@e key` in lexer and parser. # Test: Search for handling of `@e key` in lexer and parser files. Expect: Proper handling logic. rg --type ts '@e key' src/lexer.ts src/parser.tsLength of output: 50
Script:
#!/bin/bash # Description: Verify the handling of `@e` in lexer and parser. # Test: Search for handling of `@e` in lexer and parser files. Expect: Proper handling logic. rg --type ts '@e' src/lexer.ts src/parser.tsLength of output: 44
Script:
#!/bin/bash # Description: Verify the handling of `@` in lexer and parser. # Test: Search for handling of `@` in lexer and parser files. Expect: Proper handling logic. rg --type ts '@' src/lexer.ts src/parser.tsLength of output: 531
test/scenarios/objects/data.ts (1)
5-5
: Review the added scenarios and properties for consistency and correctness.Also applies to: 25-27, 32-32, 38-40
Verification successful
The shell script results confirm that the new properties
context_props.jt
andinvalid_context_prop.jt
are correctly defined intest/scenarios/objects/data.ts
. However, to ensure that these properties are used correctly and consistently in the scenarios, we need to verify the scenarios' definitions and usages.
The shell script results confirm that the new properties
context_props.jt
andinvalid_context_prop.jt
are defined intest/scenarios/objects/data.ts
. However, the results do not provide additional context or usage information. To ensure correctness and consistency, we need to verify the scenarios' definitions and usages in the file.
The shell script results provide the full context of the scenarios using
context_props.jt
andinvalid_context_prop.jt
. Here are the relevant snippets:For
context_props.jt
:import { Scenario } from '../../types'; export const data: Scenario[] = [ { templatePath: 'context_props.jt', input: { traits: { name: 'John Doe', age: 30, },For
invalid_context_prop.jt
:}, }, }, }, { templatePath: 'invalid_context_prop.jt', error: 'Context prop is should be used with key expression', }, { output: { a: 1,Both scenarios appear to be correctly defined and logically consistent. The
context_props.jt
scenario includes aninput
property with traits, while theinvalid_context_prop.jt
scenario includes anerror
property with a relevant error message.No issues were found in the definitions and usages of these scenarios.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the consistency and correctness of the new scenarios and properties. # Test: Check if the new properties and scenarios are correctly defined and used. Expect: Proper definitions and usages. rg --type ts 'context_props.jt' test/scenarios/objects/ rg --type ts 'invalid_context_prop.jt' test/scenarios/objects/Length of output: 263
Script:
#!/bin/bash # Description: Verify the scenarios using the new properties for correctness and consistency. # Test: Check if the scenarios using 'context_props.jt' and 'invalid_context_prop.jt' are correctly defined and used. rg --type ts 'context_props.jt' test/scenarios/objects/ rg --type ts 'invalid_context_prop.jt' test/scenarios/objects/Length of output: 263
Script:
#!/bin/bash # Description: Verify the scenarios using the new properties for correctness and consistency. # Test: Check the full context of the scenarios using 'context_props.jt' and 'invalid_context_prop.jt'. rg -A 5 -B 5 'context_props.jt' test/scenarios/objects/data.ts rg -A 5 -B 5 'invalid_context_prop.jt' test/scenarios/objects/data.tsLength of output: 511
src/lexer.ts (1)
96-96
: Review the implementation ofmatchObjectContextProp
to ensure it correctly matches context properties.src/translator.ts (1)
537-557
: Review the implementation oftranslateObjectContextProp
to ensure it correctly translates context properties.src/parser.ts (1)
Line range hint
561-561
: Verify the use of 'then' property.The static analysis tool flagged the use of a 'then' property as suspicious. Please verify if this property is being used appropriately within the codebase, as it might be a false positive or a genuine issue depending on the context.
Verification successful
The search results show multiple instances of the 'then' property being used in different files. To verify if these usages are appropriate, we need to review the context in which 'then' is used in the relevant files.
The context provided by the search results shows that the 'then' property is used as part of a
ConditionalExpression
interface and is consistently used in the context of parsing and translating conditional expressions. This usage appears to be appropriate and intentional within the codebase.
src/types.ts
: Defines theConditionalExpression
interface withif
,then
, andelse
properties.src/translator.ts
: Uses thethen
property to translate conditional expressions.src/reverse_translator.ts
: Uses thethen
property to reverse translate conditional expressions.src/parser.ts
: Parses thethen
part of a conditional expression.Given this context, the use of the 'then' property is appropriate and does not indicate any issues.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Search for 'then' property usage in the codebase. rg --type ts "then"Length of output: 460
Script:
#!/bin/bash # Description: Display the context of 'then' property usage in the relevant files. # Display context in src/types.ts echo "Context in src/types.ts:" rg --context 5 --type ts "then" src/types.ts # Display context in src/translator.ts echo "Context in src/translator.ts:" rg --context 5 --type ts "then" src/translator.ts # Display context in src/reverse_translator.ts echo "Context in src/reverse_translator.ts:" rg --context 5 --type ts "then" src/reverse_translator.ts # Display context in src/parser.ts echo "Context in src/parser.ts:" rg --context 5 --type ts "then" src/parser.tsLength of output: 2136
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: 1
Outside diff range and nitpick comments (2)
src/parser.ts (2)
Line range hint
1469-1469
: Clarify the use ofthis
in static context.The use of
this
in a static context can be confusing and potentially lead to errors if the static methods are called without an instance of the class. Consider using the class name instead to access static methods or properties.- this.isArrayFilterExpressionSimple(part as ArrayFilterExpression); + JsonTemplateParser.isArrayFilterExpressionSimple(part as ArrayFilterExpression); - this.isSimplePathPart(part); + JsonTemplateParser.isSimplePathPart(part); - this.isSimplePath(pathExpr); + JsonTemplateParser.isSimplePath(pathExpr); - this.isRichPath(pathExpr); + JsonTemplateParser.isRichPath(pathExpr);Also applies to: 1475-1475, 1482-1482, 1513-1513
Line range hint
561-561
: Clarify the use of.then
property in objects.The static analysis tool flagged the use of
.then
in objects as potentially suspicious. If this is intentional and has a specific use case in the context of your application, consider adding a comment to clarify its purpose to maintain code readability and prevent confusion during future maintenance.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- src/parser.ts (5 hunks)
- src/reverse_translator.ts (3 hunks)
- src/utils/converter.ts (6 hunks)
- test/scenarios/objects/data.ts (2 hunks)
Files skipped from review due to trivial changes (1)
- test/scenarios/objects/data.ts
Files skipped from review as they are similar to previous changes (2)
- src/reverse_translator.ts
- src/utils/converter.ts
Additional context used
Biome
src/parser.ts
[error] 1469-1469: 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] 1475-1475: 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] 1482-1482: 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] 1513-1513: 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] 561-561: Do not add then to an object. (lint/suspicious/noThenProperty)
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: 1
Outside diff range and nitpick comments (2)
src/utils/converter.ts (1)
[!TIP]
Codebase VerificationThe return type change of
handleNextPart
fromObjectExpression
toExpression
has not been fully accounted for. The code still checks ifobjectExpr.type
isSyntaxType.OBJECT_EXPR
, indicating an expectation ofObjectExpression
.
- `src/utils/converter.ts: The return value of handleNextPart is assigned to objectExpr, and there is a type check for objectExpr.type to be SyntaxType.OBJECT_EXPR.
Please review and update the handling of the return type to ensure consistency with the new
Expression
type.Analysis chain
Line range hint
149-167
: ThehandleNextPart
function's return type has been changed fromObjectExpression
toExpression
. This change is part of the broader refactoring to handle expressions more generically. Verify that all usages of this function have been updated to handle the new return type correctly.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all usages of `handleNextPart` handle the new return type. # Test: Search for the function usage. Expect: Proper handling of the new return type. rg --type typescript $'handleNextPart'Length of output: 72
Script:
#!/bin/bash # Description: Verify all usages of `handleNextPart` handle the new return type. # Test: Search for the function usage. Expect: Proper handling of the new return type. rg 'handleNextPart' --glob '*.ts'Length of output: 189
Script:
#!/bin/bash # Extract and display lines around the usage of `handleNextPart` in `src/utils/converter.ts` to verify handling of the new return type. rg 'handleNextPart' --glob 'src/utils/converter.ts' -A 5 -B 5Length of output: 1194
src/parser.ts (1)
Line range hint
1469-1469
: Replacethis
withJsonTemplateParser
in static methods to avoid confusion.- this.isArrayFilterExpressionSimple(part as ArrayFilterExpression); + JsonTemplateParser.isArrayFilterExpressionSimple(part as ArrayFilterExpression); - this.isSimplePathPart(part); + JsonTemplateParser.isSimplePathPart(part); - this.isSimplePath(pathExpr); + JsonTemplateParser.isSimplePath(pathExpr); - this.isRichPath(pathExpr); + JsonTemplateParser.isRichPath(pathExpr);Using
this
in static methods can lead to confusion about the context in which it is used. Replacing it with the class name clarifies that these methods are static.Also applies to: 1475-1475, 1482-1482, 1513-1513
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- src/parser.ts (5 hunks)
- src/reverse_translator.ts (3 hunks)
- src/utils/converter.ts (6 hunks)
Additional context used
Biome
src/parser.ts
[error] 1469-1469: 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] 1475-1475: 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] 1482-1482: 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] 1513-1513: 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] 561-561: Do not add then to an object. (lint/suspicious/noThenProperty)
Additional comments not posted (6)
src/utils/converter.ts (3)
13-13
: The import ofTokenType
from '../types' is noted. Ensure that all usages ofTokenType
are consistent and correct throughout the file.
62-87
: TheprocessAllFilter
function has been modified to returnExpression
instead ofObjectExpression
. This change aligns with the PR's objective to refine handling of expressions. Ensure that all calls to this function correctly handle the new return type.Verification successful
The call to
processAllFilter
insrc/utils/converter.ts
is within a conditional block and the returnedExpression
is used directly. This indicates that the new return type is being handled correctly.
src/utils/converter.ts
: The call toprocessAllFilter
is within a conditional block checking the type ofnextOutputPart.filter
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all calls to `processAllFilter` handle the new return type. # Test: Search for the function usage. Expect: Proper handling of the new return type. rg --type typescript $'processAllFilter'Length of output: 74
Script:
#!/bin/bash # Description: Verify all calls to `processAllFilter` handle the new return type. # Test: Search for the function usage. Expect: Proper handling of the new return type. rg --type ts 'processAllFilter'Length of output: 178
Script:
#!/bin/bash # Extract lines around the call to `processAllFilter` in `src/utils/converter.ts` to verify handling of the new return type. rg -A 5 -B 5 'processAllFilter' src/utils/converter.tsLength of output: 879
118-140
: TheprocessWildCardSelector
function has been updated to handle wildcard selectors more robustly by introducing context variables (contextVar: 'e'
). This is a significant change that enhances the function's ability to manage complex mappings. Ensure that the context variable 'e' is properly defined and used in the scope where this function is called.src/reverse_translator.ts (1)
440-442
: ThetranslateObjectPropExpression
method now includes handling forcontextVar
. This addition allows for more dynamic translation based on the context variable. Ensure that the context variable is properly managed and does not lead to any unintended side effects.Verification successful
The
contextVar
is defined and used across multiple files, and its management appears consistent and intentional. Here are the key points:
- Definition:
contextVar
is defined as an optional string inObjectPropExpression
insrc/types.ts
.- Usage in
src/parser.ts
: It is assigned a value fromgetObjectPropContextVar()
and checked for validity.- Usage in
src/reverse_translator.ts
: It is used to prepend@
to the context variable in thetranslateObjectPropExpression
method.- Usage in
src/utils/converter.ts
: It is set to'e'
in an object.- Usage in
src/translator.ts
: It is used in generating assignment code and translating object context properties.The
contextVar
is managed properly without any apparent side effects.
src/types.ts
src/parser.ts
src/reverse_translator.ts
src/utils/converter.ts
src/translator.ts
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the proper management of the context variable in `translateObjectPropExpression`. # Test: Search for the usage of the context variable in `translateObjectPropExpression`. Expect: Proper management without side effects. rg --type typescript $'contextVar'Length of output: 68
Script:
#!/bin/bash # Description: Verify the proper management of the context variable in `translateObjectPropExpression`. # Test: Search for the usage of the context variable in TypeScript files. Expect: Proper management without side effects. rg --type ts 'contextVar'Length of output: 489
Script:
#!/bin/bash # Description: Extract relevant code snippets for `contextVar` usage to ensure proper management. # Extract the definition of `contextVar` in `src/types.ts` rg --type ts --context 5 'contextVar' src/types.ts # Extract the usage of `contextVar` in `src/parser.ts` rg --type ts --context 5 'contextVar' src/parser.ts # Extract the usage of `contextVar` in `src/reverse_translator.ts` rg --type ts --context 5 'contextVar' src/reverse_translator.ts # Extract the usage of `contextVar` in `src/utils/converter.ts` rg --type ts --context 5 'contextVar' src/utils/converter.ts # Extract the usage of `contextVar` in `src/translator.ts` rg --type ts --context 5 'contextVar' src/translator.tsLength of output: 2518
src/parser.ts (2)
1130-1134
: The refactoring ofisWildcardPropKey
togetObjectPropContextVar
appears correctly implemented.
1138-1149
: The integration of context variable extraction inparseNormalObjectPropExpr
is well implemented.
What are the changes introduced in this PR?
This is to avoid conflicts with user-defined variables
What is the related Linear task?
Resolves INT-2160
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
Refactor
Tests