-
Notifications
You must be signed in to change notification settings - Fork 37
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
[LiquidDoc][Theme Check] Add alias support for UnrecognizedRenderSnippetParams #831
Conversation
376a29e
to
0b1bbf4
Compare
0b1bbf4
to
51a2db1
Compare
51a2db1
to
619f11e
Compare
79481f6
to
6ce5eff
Compare
619f11e
to
e7f9907
Compare
6ce5eff
to
013ca06
Compare
e7f9907
to
ad1f83a
Compare
@@ -69,9 +69,42 @@ export const UnrecognizedRenderSnippetParams: LiquidCheckDefinition = { | |||
} | |||
} | |||
|
|||
function reportUnknownAliases( |
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.
This is handled quite differently that Named Parameters so I split this into its own function
snippetName: string, | ||
) { | ||
if (node.alias && !liquidDocParameters.has(node.alias) && node.variable) { | ||
const asAliasMatch = node.source.match(new RegExp(`as\\s+${node.alias}`)); |
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.
This is a bit of a hack to strip as alias
since we don't have that information in the AST right now. Luckily, it's a consistent pattern so this should work sufficiently.
I'm creating a separate ticket to address the parsing work, etc that would need to be done to do this with the node positions.
context.report({ | ||
message: `Unknown parameter '${node.alias}' in render tag for snippet '${snippetName}'`, | ||
startIndex: node.variable.position.start, | ||
endIndex: node.variable.position.end, |
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.
Right now this will only highlight **with 'product'** as alias
. This is due to the current capabilities of the parsing for render markup.
Tracked an issue here ( same as the one mentioned above)
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.
endIndex: node.variable.position.end, | |
endIndex: asAliasMatch ? node.variable.position.end + asAliasMatch[0].length : node.variable.position.end, |
What do you think about adding asAliasMatch[0].length
to the endIndex?
We could also add an offset to startIndex and endIndex to avoid spaces:
const startingOffset = node.source.slice(node.variable.position.start).indexOf(node.variable.kind);
...
context.report({
...
startIndex: startingOffset + node.variable.position.start,
endIndex: startingOffset + (asAliasMatch ? node.variable.position.end + asAliasMatch[0].length : node.variable.position.end),
})
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.
great idea!
ad1f83a
to
99aba80
Compare
- Update check to handle 'as' alias scenarios - Adjust fixer to correctly insert missing parameters
99aba80
to
2135423
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.
Optional suggestions for improving as
alias
1 optional change
1 mandatory change with node.source
replace
if (node.variable) { | ||
return fixer.remove( | ||
node.variable.position.start, | ||
node.source.indexOf(asAliasMatch[0]) + asAliasMatch[0].length, |
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.
node.source.indexOf(asAliasMatch[0]) + asAliasMatch[0].length, | |
node.source.slice(node.position.start).indexOf(asAliasMatch[0]) + asAliasMatch[0].length, |
This is a bit dangerous. I had two render tags with as foo
in it. node.source
returns the entire file, so doing a indexOf
could find the wrong one.
context.report({ | ||
message: `Unknown parameter '${node.alias}' in render tag for snippet '${snippetName}'`, | ||
startIndex: node.variable.position.start, | ||
endIndex: node.variable.position.end, |
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.
endIndex: node.variable.position.end, | |
endIndex: asAliasMatch ? node.variable.position.end + asAliasMatch[0].length : node.variable.position.end, |
What do you think about adding asAliasMatch[0].length
to the endIndex?
We could also add an offset to startIndex and endIndex to avoid spaces:
const startingOffset = node.source.slice(node.variable.position.start).indexOf(node.variable.kind);
...
context.report({
...
startIndex: startingOffset + node.variable.position.start,
endIndex: startingOffset + (asAliasMatch ? node.variable.position.end + asAliasMatch[0].length : node.variable.position.end),
})
- Handle multiple render tags - Expand error reporting to highlight entire alias if found
What are you adding in this PR?
Closes https://github.com/Shopify/developer-tools-team/issues/605
Adds alias support to the UnrecognizedRenderSnippetParams theme check
If the alias used is unrecognized, we will report this.
We also had to handle some edge cases for removal since this follows a different format.
What's next? Any followup issues?
Need to update type checking next
Before you deploy
changeset