Code Monkey home page Code Monkey logo

Comments (6)

ilevyor avatar ilevyor commented on May 20, 2024

good catch in the docs.

The error message is trying to explain that most patterns are auto wrapped

https://docs.grit.io/language/bubble#pattern-auto-wrap

sequential is not auto wrapped because it only matches on files, so the pattern inside of a sequential needs to match a top level file. in this case the easy fix is to insert a contains in front of each step like so:

sequential {    
    contains `console.log($message)` => `console.warn($message)`,
    contains `console.warn($message)` => `console.info($message)`
}

from gritql.

jonathan-s avatar jonathan-s commented on May 20, 2024

Are there other strategies besides using contains?

from gritql.

morgante avatar morgante commented on May 20, 2024

Are there other strategies besides using contains?

The core thing is that each step is matching the file as a whole. In most cases, you want to look for some code inside the file so contains is the best option. Why do you want an alternative?

from gritql.

jonathan-s avatar jonathan-s commented on May 20, 2024

@morgante This may be another bug, or some misunderstanding from my side.

The following grit code.

sequential {
        bubble file($body) where $body <: contains `def $name($args, $...): $funcbody` where {
        $args <: `self` => .
    }
}

Seems to replace the first self in a function.

While the following grit code

`def $name($args, $...): $funcbody` where {
    $args <: `self` => .
}

replaces all the self in the python code of the file. So clearly just using the construct with bubble and contains are not equivalent.

Python code to use.

class AlertTest(BaseTest):
    @vcr.use_cassette
    def test_rule(self):
        resp = self.get("/url/alert/rule")
        self.assertEqual(resp.status_code, 200)

    @vcr.use_cassette
    def test_alert_search(self):
        resp = self.post(
            "/url/alert/search",
            data={
                "alert_rule": "oeuoeu",
                "use_case": "usecase",
                "panels": "count,rules,details",
            },
        )

        self.assertEqual(resp.status_code, 200)

from gritql.

morgante avatar morgante commented on May 20, 2024

The bubble needs to go around the scope you actually want to isolate, like this:

sequential {
    file($body) where $body <: contains bubble `def $name($args, $...): $funcbody` where {
        $args <: `self` => .
    }
}

from gritql.

jonathan-s avatar jonathan-s commented on May 20, 2024

@morgante Thank you.
Worth noting that the example in documentation here > https://docs.grit.io/language/patterns#sequential

contains

sequential {
    bubble file($body) where $body <: contains `console.log($message)` => `console.warn($message)`,
    bubble file($body) where $body <: contains `console.warn($message)` => `console.info($message)`
}

In other words it is using bubble the very first.

Also I'm noticing that or does not seem to work together with bubble. Is there a way to make that work?

Ie the following code does not work as expected finding zero matches. Though each sequence in separation does work as expected.

sequential {
    file($body) where $body <: contains bubble `class $name($parent): $funcbody` => $funcbody,
    file($body) where $body <: contains bubble or {
        `self.assertEqual($first, $second)` => `assert $first == $second`,
        `self.assertEqual($first, $second, $third)` => `assert $first == $second`
    },
}

Some feedback regarding sequential. I'm finding the use of sequential pretty fiddly and it's hard to know exactly what's going on and why it's not working.

The way I conceptualize sequential is a loop, so that each statement is applied on the file in question. Right now if you have a series of statements and one of the statements doesn't match, nothing at all is changed on the file. That makes it difficult to debug, but also it may be desirable to apply the series of transformations and if one doesn't match it would still apply the other transformations.

I would rather get a warning message saying that the following statement was had no match in xxx file, and thus no transformation happened there.

Also it would be nice if no extra syntax was needed to stay consistent with single statement transformations.

from gritql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.