You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sorry if this should be super apparent, but I've beat my head on it awhile now and need some help.
I'd like to lint and warn when a specific JSX element (MyComponent) being used using GritQL. I thought it would resemble something like this, but Im unable to get the JsxReferenceIdentifier to match on the pattern.
language js(jsx)
or {
JsxTagExpression() as $tag where {
$tag <: contains JsxOpeningElement() as $memberName where {
$memberName <: contains JsxReferenceIdentifier() as $ref where {
$ref <: `MyComponent`, // this pattern doesnt match
register_diagnostic(
span=$ref,
message="Dont use this"
)
}
}
}
}
I want to warn when JSX code has a MyComponent element, and the label attribute has a trailing colon:
<MyComponentlabel="test:"/>// ⚠️Should warn
I tried using basic pattern matching with a regular expression to test the label value, which I thought would be a simplier approach but for some reason I couldnt get this to work with the double-quotes?
or {
`<MyComponent $... label="$text" $... >`,
`<MyComponent $... label="$text" $... />`
} where {
$text <: r".*:\s*$",
register_diagnostic(
span=$text,
message="Dont use this"
)
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Sorry if this should be super apparent, but I've beat my head on it awhile now and need some help.
I'd like to lint and warn when a specific JSX element (
MyComponent) being used using GritQL. I thought it would resemble something like this, but Im unable to get theJsxReferenceIdentifierto match on the pattern.Playground URL
The X problem:
I want to warn when JSX code has a
MyComponentelement, and thelabelattribute has a trailing colon:I tried using basic pattern matching with a regular expression to test the label value, which I thought would be a simplier approach but for some reason I couldnt get this to work with the double-quotes?
Any help would be appreciated! Thank you!
Beta Was this translation helpful? Give feedback.
All reactions