Comments (6)
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.
Are there other strategies besides using contains
?
from gritql.
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.
@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.
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.
@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)
- grit toml mismatch
- Improve git warning `--force`
- Improved auto-indentation
- (Solved) How to make react props to children HOT 8
- Alternative diff output HOT 3
- Feature request: Specify range for query on a specific file HOT 7
- Pattern namespacing
- Disable pattern `and`
- Clarify which patterns are tested with grit patterns test
- [regression] grit check has no progress bar
- (Solved) How Can I ensure import in js? HOT 3
- Improve multi-part identifier matching HOT 1
- `grit patterns list --jsonl` doesn't produce JSONL
- The `https://grit.io/studio` site is stuck in an infinite loading loop. HOT 11
- Apply directly on stdin HOT 2
- `grit apply` hangs on very large repos
- Rewrite wrongly changes JavaScript `for` loop conditions HOT 1
- Rewrite wrongly removes the empty statement after the `if` condition in JavaScript.
- C support
- Error: Invalid grit.yml HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gritql.