getgrit / gritql

GritQL is a query language for searching, linting, and modifying code.

Home Page:https://docs.grit.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

(Solved) How Can I ensure import in js?

gaki2 opened this issue · comments

I want to make a condition saying that
if CommonButton is imported from '@miri-unicorn/miricanvas-ds', then ~~~~.

engine marzano(0.1)
language js

`CommonButton` as $common_button where {
    and {
        $base = `@miri-unicorn/miricanvas-ds`,
        // this is not working.
        $common_button <: imported_from($base),
        // Below code is not working even though I imported { CommonButton } from '@miri-unicorn/miricanvas-ds'.
        $common_button <: remove_import($base),
        $button = `Button`,
        $source = `@miri-unicorn/miricanvas-ds/v2`,
        $button <: ensure_import_from($source),
    }
}

Is there any pattern i can use?
imported_from pattern seems to be not working.

스크린샷 2024-04-24 오전 11 19 07

You need to include the quotes:

engine marzano(0.1)
language js

`CommonButton` as $common_button where {
        $base = `'@miri-unicorn/miricanvas-ds'`,
        // this is not working.
        $common_button <: imported_from($base),
        $common_button <: remove_import($base),
        $button = `Button`,
        $source = `@miri-unicorn/miricanvas-ds/v2`,
        $button <: ensure_import_from($source),
}

@morgante Thank you so much.

Is there place that I can see pure patterns?
e.g. imported_from(), remove_import(), jsx_element() ....

Here is just showing abstracted usage.

We need to improve documentation for our utility patterns. For now the best resource is probably just looking at the code itself: https://github.com/getgrit/stdlib/blob/bc2aad90806268020ba5d610cc2092abbf4e0484/.grit/patterns/js/imports.grit#L15