-
Notifications
You must be signed in to change notification settings - Fork 1
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
Consider adding eugene lint
command
#37
Comments
I think we can probably do all of the hints we have right now, if we accept some false positives and we make some of the hints optional (eg. we can look for |
Been taking a stab at working with the parse trees from pg_query, and I think it's very clunky. The grammar is huge and because of the structure, there's so much |
Here's a small example for accessing the type of an fn alters_table_lints(node: &pg_query::NodeRef) -> Vec<String> {
if let pg_query::NodeRef::AlterTableStmt(stmt) = node {
let next = &stmt.cmds;
next.iter()
.filter_map(|child| {
let node_ref = child.node.as_ref()?;
is_alters_type_cmd(&node_ref.to_ref())
})
.collect()
} else {
Vec::new()
}
}
fn is_alters_type_cmd(node: &pg_query::NodeRef) -> Option<String> {
if let pg_query::NodeRef::AlterTableCmd(cmd) = node {
let def_node = cmd.def.as_ref()?.node.as_ref()?;
if let pg_query::NodeRef::ColumnDef(def) = def_node.to_ref() {
if def.type_name.is_some() {
Some(cmd.name.to_string())
} else { None }
} else {
None
}
} else {
None
}
} |
This is huge, and perhaps not the right place to start: https://www.postgresql.org/docs/current/sql-altertable.html I have a 130 line match now, and only barely touching the surface of |
Like, what goes on the end of |
The mvp here is to:
|
Currently looks feasible to add useful stuff here, although it will be more prone to false positives and there's stuff that we're bound to miss that |
With #36 we're introducing a dependency to pg_query.rs, which gives us the full postgres SQL parser. It would be interesting to see if we can write some lint rules that do not depend on running the postgres server for some of the hints we currently provide. Here's a list of things we may be able to warn about using the parse tree from pg_query:
NOT VALID
:NOT NULL
CONCURRENTLY
It may also be that we can do some manual inspection of the parse tree to figure out that some statements take dangerous locks, then warn about that. However, many of these will give us false positives that we can't statically verify now, so we probably want to support some sort of comment syntax to let
eugene
ignore the statement, eg.The text was updated successfully, but these errors were encountered: