-
Notifications
You must be signed in to change notification settings - Fork 103
chore: expose schema_cache & file_context in lint rules #449
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
Changes from 13 commits
c76b319
18af004
597173f
8aaa5f5
55d4c16
8c9aa05
83005a1
491013b
922c5e0
17463d8
361aaa9
d8299f1
47344e8
a79764f
9426b1f
bf70e8f
806a093
6be942f
e649818
0ad31be
7682c1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#[derive(Default)] | ||
pub struct AnalysedFileContext {} | ||
|
||
impl AnalysedFileContext { | ||
#[allow(unused)] | ||
pub fn update_from(&mut self, stmt_root: &pgt_query_ext::NodeEnum) {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
use pgt_analyse::{Rule, RuleDiagnostic, RuleSource, context::RuleContext, declare_lint_rule}; | ||
use pgt_analyse::{ | ||
AnalysedFileContext, Rule, RuleDiagnostic, RuleSource, context::RuleContext, declare_lint_rule, | ||
}; | ||
use pgt_console::markup; | ||
use pgt_diagnostics::Severity; | ||
use pgt_schema_cache::SchemaCache; | ||
|
||
declare_lint_rule! { | ||
/// Adding a new column that is NOT NULL and has no default value to an existing table effectively makes it required. | ||
|
@@ -27,7 +30,11 @@ declare_lint_rule! { | |
impl Rule for AddingRequiredField { | ||
type Options = (); | ||
|
||
fn run(ctx: &RuleContext<Self>) -> Vec<RuleDiagnostic> { | ||
fn run( | ||
ctx: &RuleContext<Self>, | ||
_file_context: &AnalysedFileContext, | ||
_schema_cache: Option<&SchemaCache>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from an API standpoint, I would put these two into the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I felt the But I don't have a hard opinion |
||
) -> Vec<RuleDiagnostic> { | ||
let mut diagnostics = vec![]; | ||
|
||
if let pgt_query_ext::NodeEnum::AlterTableStmt(stmt) = ctx.stmt() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's just a scaffold for the file context.
We can add properties in future linting PRs.
eugene works the same way: link