Skip to content

Commit d33599d

Browse files
committed
add codegen for linter
1 parent fe7f2e0 commit d33599d

File tree

17 files changed

+328
-35
lines changed

17 files changed

+328
-35
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pg_diagnostics_categories/src/categories.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
// must be between `define_categories! {\n` and `\n ;\n`.
1414

1515
define_categories! {
16-
"somerule": "https://example.com/some-rule",
16+
"lint/nursery/banDropColumn": "https://pglsp.dev/linter/rules/ban-drop-column",
17+
// end lint rules
1718
;
19+
// General categories
1820
"stdin",
1921
"lint",
2022
"check",
@@ -28,4 +30,9 @@ define_categories! {
2830
"internalError/panic",
2931
"syntax",
3032
"dummy",
33+
34+
// Lint groups
35+
"lint",
36+
"lint/performance",
37+
"lint/suspicious",
3138
}

crates/pg_linter/src/lint.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! Generated file, do not edit by hand, see `xtask/codegen`
22
3+
pub mod nursery;
34
pub mod performance;
4-
::pg_analyse::declare_category! { pub Lint { kind : Lint , groups : [self :: performance :: Performance ,] } }
5+
::pg_analyse::declare_category! { pub Lint { kind : Lint , groups : [self :: nursery :: Nursery , self :: performance :: Performance ,] } }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//! Generated file, do not edit by hand, see `xtask/codegen`
2+
3+
use pg_analyse::declare_lint_group;
4+
pub mod ban_drop_column;
5+
declare_lint_group! { pub Nursery { name : "nursery" , rules : [self :: ban_drop_column :: BanDropColumn ,] } }
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use pg_analyse::{context::RuleContext, declare_lint_rule, Rule, RuleDiagnostic};
2+
use pg_console::markup;
3+
4+
declare_lint_rule! {
5+
/// Succinct description of the rule.
6+
///
7+
/// Put context and details about the rule.
8+
///
9+
/// Try to stay consistent with the descriptions of implemented rules.
10+
///
11+
/// ## Examples
12+
///
13+
/// ### Invalid
14+
///
15+
/// ```sql,expect_diagnostic
16+
/// select 1;
17+
/// ```
18+
///
19+
/// ### Valid
20+
///
21+
/// ``sql`
22+
/// select 2;
23+
/// ```
24+
///
25+
pub BanDropColumn {
26+
version: "next",
27+
name: "banDropColumn",
28+
recommended: false,
29+
}
30+
}
31+
32+
impl Rule for BanDropColumn {
33+
type Options = ();
34+
35+
fn run(ctx: &RuleContext<Self>) -> Vec<RuleDiagnostic> {
36+
Vec::new()
37+
}
38+
}
Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
//! Generated file, do not edit by hand, see `xtask/codegen`
22
33
use pg_analyse::declare_lint_group;
4-
54
pub mod prefer_text_field;
6-
7-
declare_lint_group! {
8-
pub Performance {
9-
name : "performance" ,
10-
rules : [
11-
self :: prefer_text_field :: PreferTextField ,
12-
]
13-
}
14-
}
5+
declare_lint_group! { pub Performance { name : "performance" , rules : [self :: prefer_text_field :: PreferTextField ,] } }

crates/pg_linter/src/lint/performance/prefer_text_field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pg_analyse::declare_lint_rule! {
2828
///
2929
pub PreferTextField {
3030
version: "0.0.1",
31-
name: "prefer-text-field",
31+
name: "preferTextField",
3232
recommended: true,
3333
}
3434
}

crates/pg_linter/src/options.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Generated file, do not edit by hand, see `xtask/codegen`
22
33
use crate::lint;
4-
5-
pub type NoDescendingSpecificity =
4+
pub type BanDropColumn =
5+
<lint::nursery::ban_drop_column::BanDropColumn as pg_analyse::Rule>::Options;
6+
pub type PreferTextField =
67
<lint::performance::prefer_text_field::PreferTextField as pg_analyse::Rule>::Options;

crates/pg_linter/src/registry.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Generated file, do not edit by hand, see `xtask/codegen`
22
33
use pg_analyse::RegistryVisitor;
4-
54
pub fn visit_registry<V: RegistryVisitor>(registry: &mut V) {
65
registry.record_category::<crate::lint::Lint>();
76
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
select 2;

0 commit comments

Comments
 (0)