Skip to content

Commit 614562c

Browse files
committed
fix: proper casing for keywords and types
1 parent 717b3c7 commit 614562c

699 files changed

Lines changed: 42825 additions & 42679 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/pgls_cli/src/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,11 @@ impl Diagnostic for FormatDiffDiagnostic {
473473
}
474474

475475
fn description(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
476-
write!(fmt, "File could be formatted using `--write`")
476+
write!(fmt, "Statement could be formatted using `--write`")
477477
}
478478

479479
fn message(&self, fmt: &mut pgls_console::fmt::Formatter<'_>) -> std::io::Result<()> {
480-
fmt.write_str("File could be formatted using `--write`")
480+
fmt.write_str("Statement could be formatted using `--write`")
481481
}
482482

483483
fn advices(&self, visitor: &mut dyn Visit) -> std::io::Result<()> {

crates/pgls_configuration/src/format.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ pub struct FormatConfiguration {
9898
/// Constant casing (NULL, TRUE, FALSE): "upper" or "lower". Default: "lower".
9999
#[partial(bpaf(long("constant-case")))]
100100
pub constant_case: KeywordCase,
101+
/// Data type casing (text, varchar, int): "upper" or "lower". Default: "lower".
102+
#[partial(bpaf(long("type-case")))]
103+
pub type_case: KeywordCase,
101104
/// A list of Unix shell style patterns. The formatter will ignore files/folders that will match these patterns.
102105
#[partial(bpaf(hide))]
103106
pub ignore: StringSet,
@@ -115,6 +118,7 @@ impl Default for FormatConfiguration {
115118
indent_style: IndentStyle::Spaces,
116119
keyword_case: KeywordCase::default(),
117120
constant_case: KeywordCase::default(),
121+
type_case: KeywordCase::default(),
118122
ignore: Default::default(),
119123
include: Default::default(),
120124
}

crates/pgls_pretty_print/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ pub struct FormatConfig {
4444
pub keyword_case: KeywordCase,
4545
/// Casing for constants (NULL, TRUE, FALSE). Default: Lower.
4646
pub constant_case: KeywordCase,
47+
/// Casing for data types (text, varchar, int). Default: Lower.
48+
pub type_case: KeywordCase,
4749
}
4850

4951
impl Default for FormatConfig {
@@ -54,6 +56,7 @@ impl Default for FormatConfig {
5456
indent_style: IndentStyle::Spaces,
5557
keyword_case: KeywordCase::default(),
5658
constant_case: KeywordCase::default(),
59+
type_case: KeywordCase::default(),
5760
}
5861
}
5962
}
@@ -66,6 +69,7 @@ impl From<FormatConfig> for RenderConfig {
6669
indent_style: config.indent_style,
6770
keyword_case: config.keyword_case,
6871
constant_case: config.constant_case,
72+
type_case: config.type_case,
6973
}
7074
}
7175
}
@@ -110,6 +114,7 @@ pub fn format_statement(
110114
indent_style: config.indent_style.clone(),
111115
keyword_case: config.keyword_case.clone(),
112116
constant_case: config.constant_case.clone(),
117+
type_case: config.type_case.clone(),
113118
};
114119

115120
let mut output = String::new();

crates/pgls_pretty_print/src/nodes/access_priv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(super) fn emit_access_priv(e: &mut EventEmitter, n: &AccessPriv) {
1313
// Empty priv_name means ALL privileges
1414
e.token(TokenKind::ALL_KW);
1515
e.space();
16-
e.token(TokenKind::IDENT("PRIVILEGES".to_string()));
16+
e.token(TokenKind::PRIVILEGES_KW);
1717
}
1818

1919
// Optional column list for column-level privileges

crates/pgls_pretty_print/src/nodes/alter_collation_stmt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ pub(super) fn emit_alter_collation_stmt(e: &mut EventEmitter, n: &AlterCollation
99

1010
e.token(TokenKind::ALTER_KW);
1111
e.space();
12-
e.token(TokenKind::IDENT("COLLATION".to_string()));
12+
e.token(TokenKind::COLLATION_KW);
1313
e.space();
1414

1515
if !n.collname.is_empty() {
1616
emit_dot_separated_list(e, &n.collname);
1717
}
1818

1919
e.line(LineType::SoftOrSpace);
20-
e.token(TokenKind::IDENT("REFRESH".to_string()));
20+
e.token(TokenKind::REFRESH_KW);
2121
e.space();
22-
e.token(TokenKind::IDENT("VERSION".to_string()));
22+
e.token(TokenKind::VERSION_KW);
2323

2424
e.token(TokenKind::SEMICOLON);
2525

crates/pgls_pretty_print/src/nodes/alter_database_refresh_coll_stmt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ pub(super) fn emit_alter_database_refresh_coll_stmt(
1010

1111
e.token(TokenKind::ALTER_KW);
1212
e.space();
13-
e.token(TokenKind::IDENT("DATABASE".to_string()));
13+
e.token(TokenKind::DATABASE_KW);
1414
e.space();
1515

1616
if !n.dbname.is_empty() {
1717
e.token(TokenKind::IDENT(n.dbname.clone()));
1818
}
1919

2020
e.line(LineType::SoftOrSpace);
21-
e.token(TokenKind::IDENT("REFRESH".to_string()));
21+
e.token(TokenKind::REFRESH_KW);
2222
e.space();
23-
e.token(TokenKind::IDENT("COLLATION".to_string()));
23+
e.token(TokenKind::COLLATION_KW);
2424
e.space();
25-
e.token(TokenKind::IDENT("VERSION".to_string()));
25+
e.token(TokenKind::VERSION_KW);
2626

2727
e.token(TokenKind::SEMICOLON);
2828

crates/pgls_pretty_print/src/nodes/alter_database_set_stmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(super) fn emit_alter_database_set_stmt(e: &mut EventEmitter, n: &AlterDataba
77

88
e.token(TokenKind::ALTER_KW);
99
e.space();
10-
e.token(TokenKind::IDENT("DATABASE".to_string()));
10+
e.token(TokenKind::DATABASE_KW);
1111
e.space();
1212

1313
if !n.dbname.is_empty() {

crates/pgls_pretty_print/src/nodes/alter_database_stmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub(super) fn emit_alter_database_stmt(e: &mut EventEmitter, n: &AlterDatabaseSt
99

1010
e.token(TokenKind::ALTER_KW);
1111
e.space();
12-
e.token(TokenKind::IDENT("DATABASE".to_string()));
12+
e.token(TokenKind::DATABASE_KW);
1313
e.space();
1414

1515
if !n.dbname.is_empty() {

crates/pgls_pretty_print/src/nodes/alter_default_privileges_stmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(super) fn emit_alter_default_privileges_stmt(
1414
e.space();
1515
e.token(TokenKind::DEFAULT_KW);
1616
e.space();
17-
e.token(TokenKind::IDENT("PRIVILEGES".to_string()));
17+
e.token(TokenKind::PRIVILEGES_KW);
1818

1919
// Options can contain FOR ROLE/USER and IN SCHEMA clauses
2020
for opt in &n.options {

crates/pgls_pretty_print/src/nodes/alter_domain_stmt.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub(super) fn emit_alter_domain_stmt(e: &mut EventEmitter, n: &AlterDomainStmt)
99

1010
e.token(TokenKind::ALTER_KW);
1111
e.space();
12-
e.token(TokenKind::IDENT("DOMAIN".to_string()));
12+
e.token(TokenKind::DOMAIN_KW);
1313
e.space();
1414

1515
// Note: missing_ok in AlterDomainStmt is for the constraint (DROP CONSTRAINT IF EXISTS),
@@ -44,14 +44,14 @@ pub(super) fn emit_alter_domain_stmt(e: &mut EventEmitter, n: &AlterDomainStmt)
4444
e.space();
4545
e.token(TokenKind::NOT_KW);
4646
e.space();
47-
e.token(TokenKind::IDENT("NULL".to_string()));
47+
e.token(TokenKind::NULL);
4848
}
4949
"O" => {
5050
e.token(TokenKind::SET_KW);
5151
e.space();
5252
e.token(TokenKind::NOT_KW);
5353
e.space();
54-
e.token(TokenKind::IDENT("NULL".to_string()));
54+
e.token(TokenKind::NULL);
5555
}
5656
"C" => {
5757
e.token(TokenKind::ADD_KW);
@@ -63,7 +63,7 @@ pub(super) fn emit_alter_domain_stmt(e: &mut EventEmitter, n: &AlterDomainStmt)
6363
"X" => {
6464
e.token(TokenKind::DROP_KW);
6565
e.space();
66-
e.token(TokenKind::IDENT("CONSTRAINT".to_string()));
66+
e.token(TokenKind::CONSTRAINT_KW);
6767
if n.missing_ok {
6868
e.space();
6969
e.token(TokenKind::IF_KW);
@@ -78,13 +78,13 @@ pub(super) fn emit_alter_domain_stmt(e: &mut EventEmitter, n: &AlterDomainStmt)
7878
// Only emit CASCADE explicitly; RESTRICT is the default
7979
if n.behavior == 2 {
8080
e.space();
81-
e.token(TokenKind::IDENT("CASCADE".to_string()));
81+
e.token(TokenKind::CASCADE_KW);
8282
}
8383
}
8484
"V" => {
85-
e.token(TokenKind::IDENT("VALIDATE".to_string()));
85+
e.token(TokenKind::VALIDATE_KW);
8686
e.space();
87-
e.token(TokenKind::IDENT("CONSTRAINT".to_string()));
87+
e.token(TokenKind::CONSTRAINT_KW);
8888
if !n.name.is_empty() {
8989
e.space();
9090
e.token(TokenKind::IDENT(n.name.clone()));

0 commit comments

Comments
 (0)