Skip to content

Commit 6a3d573

Browse files
refactor: migrate to jsonc config (#239)
* chore: add our own text-size * fix: test * chore: cleanup feature gates * chore: cleanup remaining feature gates * refactor: migrate to json config * fix: lint * feat: add schema field * migrate to jsonc config * fix: run docs codegen * Update configuration.rs Co-authored-by: Julian Domke <68325451+juleswritescode@users.noreply.github.com> * add unit tests * fix: replace_secion --------- Co-authored-by: Julian Domke <68325451+juleswritescode@users.noreply.github.com>
1 parent b8ec48f commit 6a3d573

Some content is hidden

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

45 files changed

+446
-201
lines changed

Cargo.lock

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

crates/pglt_analyse/src/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl AnalyserRules {
4545
/// A set of information useful to the analyser infrastructure
4646
#[derive(Debug, Default)]
4747
pub struct AnalyserOptions {
48-
/// A data structured derived from the [`pglt.toml`] file
48+
/// A data structured derived from the [`pglt.jsonc`] file
4949
pub rules: AnalyserRules,
5050
}
5151

crates/pglt_analyse/src/rule.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ use std::fmt::Debug;
1212
use crate::{categories::RuleCategory, context::RuleContext, registry::RegistryVisitor};
1313

1414
#[derive(Clone, Debug)]
15-
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
15+
#[cfg_attr(
16+
feature = "serde",
17+
derive(serde::Serialize),
18+
serde(rename_all = "camelCase")
19+
)]
1620
/// Static metadata containing information about a rule
1721
pub struct RuleMetadata {
1822
/// It marks if a rule is deprecated, and if so a reason has to be provided.

crates/pglt_analyser/CONTRIBUTING.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,24 @@ Let's assume that the rule we implement support the following options:
7979
- `threshold`: an integer between 0 and 255;
8080
- `behaviorExceptions`: an array of strings.
8181

82-
We would like to set the options in the `pglt.toml` configuration file:
83-
84-
```toml
85-
[linter.rules.safety.myRule]
86-
level = "warn"
87-
options = {
88-
behavior = "A"
89-
threshold = 20
90-
behaviorExceptions = ["one", "two"]
82+
We would like to set the options in the `pglt.jsonc` configuration file:
83+
84+
```json
85+
{
86+
"linter": {
87+
"rules": {
88+
"safety": {
89+
"myRule": {
90+
"level": "warn",
91+
"options": {
92+
"behavior": "A",
93+
"threshold": 20,
94+
"behaviorExceptions": ["one", "two"]
95+
}
96+
}
97+
}
98+
}
99+
}
91100
}
92101
```
93102

@@ -132,16 +141,16 @@ We currently require implementing _serde_'s traits `Deserialize`/`Serialize`.
132141

133142
Also, we use other `serde` macros to adjust the JSON configuration:
134143

135-
- `rename_all = "snake_case"`: it renames all fields in camel-case, so they are in line with the naming style of the `pglt.toml`.
144+
- `rename_all = "camelCase"`: it renames all fields in camel-case, so they are in line with the naming style of the `pglt.jsonc`.
136145
- `deny_unknown_fields`: it raises an error if the configuration contains extraneous fields.
137-
- `default`: it uses the `Default` value when the field is missing from `pglt.toml`. This macro makes the field optional.
146+
- `default`: it uses the `Default` value when the field is missing from `pglt.jsonc`. This macro makes the field optional.
138147

139148
You can simply use a derive macros:
140149

141150
```rust
142151
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
143152
#[cfg_attr(feature = "schemars", derive(JsonSchema))]
144-
#[serde(rename_all = "snake_case", deny_unknown_fields, default)]
153+
#[serde(rename_all = "camelCase", deny_unknown_fields, default)]
145154
pub struct MyRuleOptions {
146155
#[serde(default, skip_serializing_if = "is_default")]
147156
main_behavior: Behavior,

crates/pglt_cli/src/cli_options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct CliOptions {
2626
#[bpaf(long("verbose"), switch, fallback(false))]
2727
pub verbose: bool,
2828

29-
/// Set the file path to the configuration file, or the directory path to find `pglt.toml`.
29+
/// Set the file path to the configuration file, or the directory path to find `pglt.jsonc`.
3030
/// If used, it disables the default configuration file resolution.
3131
#[bpaf(long("config-path"), argument("PATH"), optional)]
3232
pub config_path: Option<String>,

crates/pglt_cli/src/commands/init.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use pglt_workspace::configuration::create_config;
66

77
pub(crate) fn init(mut session: CliSession) -> Result<(), CliDiagnostic> {
88
let fs = &mut session.app.fs;
9-
create_config(fs, PartialConfiguration::init())?;
10-
let file_created = ConfigName::pglt_toml();
9+
let config = &mut PartialConfiguration::init();
10+
create_config(fs, config)?;
11+
let file_created = ConfigName::pglt_jsonc();
1112
session.app.console.log(markup! {
1213
"
1314
Welcome to the Postgres Language Tools! Let's get you started...

crates/pglt_cli/src/commands/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub enum PgltCommand {
5858
changed: bool,
5959

6060
/// Use this to specify the base branch to compare against when you're using the --changed
61-
/// flag and the `defaultBranch` is not set in your `pglt.toml`
61+
/// flag and the `defaultBranch` is not set in your `pglt.jsonc`
6262
#[bpaf(long("since"), argument("REF"))]
6363
since: Option<String>,
6464

@@ -91,7 +91,7 @@ pub enum PgltCommand {
9191
)]
9292
log_path: PathBuf,
9393
/// Allows to set a custom file path to the configuration file,
94-
/// or a custom directory path to find `pglt.toml`
94+
/// or a custom directory path to find `pglt.jsonc`
9595
#[bpaf(env("PGLT_LOG_PREFIX_NAME"), long("config-path"), argument("PATH"))]
9696
config_path: Option<PathBuf>,
9797
},
@@ -127,7 +127,7 @@ pub enum PgltCommand {
127127
)]
128128
log_path: PathBuf,
129129
/// Allows to set a custom file path to the configuration file,
130-
/// or a custom directory path to find `pglt.toml`
130+
/// or a custom directory path to find `pglt.jsonc`
131131
#[bpaf(env("PGLT_CONFIG_PATH"), long("config-path"), argument("PATH"))]
132132
config_path: Option<PathBuf>,
133133
/// Bogus argument to make the command work with vscode-languageclient
@@ -164,7 +164,7 @@ pub enum PgltCommand {
164164
#[bpaf(long("stop-on-disconnect"), hide_usage)]
165165
stop_on_disconnect: bool,
166166
/// Allows to set a custom file path to the configuration file,
167-
/// or a custom directory path to find `pglt.toml`
167+
/// or a custom directory path to find `pglt.jsonc`
168168
#[bpaf(env("PGLT_CONFIG_PATH"), long("config-path"), argument("PATH"))]
169169
config_path: Option<PathBuf>,
170170
},

crates/pglt_cli/src/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub enum CliDiagnostic {
4848
IoError(IoDiagnostic),
4949
/// The daemon is not running
5050
ServerNotRunning(ServerNotRunning),
51-
/// The end configuration (`pglt.toml` + other options) is incompatible with the command
51+
/// The end configuration (`pglt.jsonc` + other options) is incompatible with the command
5252
IncompatibleEndConfiguration(IncompatibleEndConfiguration),
5353
/// No files processed during the file system traversal
5454
NoFilesWereProcessed(NoFilesWereProcessed),
@@ -410,7 +410,7 @@ impl CliDiagnostic {
410410
Self::ServerNotRunning(ServerNotRunning)
411411
}
412412

413-
/// Emitted when the end configuration (`pglt.toml` file + CLI arguments + LSP configuration)
413+
/// Emitted when the end configuration (`pglt.jsonc` file + CLI arguments + LSP configuration)
414414
/// results in a combination of options that doesn't allow to run the command correctly.
415415
///
416416
/// A reason needs to be provided

crates/pglt_configuration/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ rustc-hash = { workspace = true }
2525
schemars = { workspace = true, features = ["indexmap1"], optional = true }
2626
serde = { workspace = true, features = ["derive"] }
2727
serde_json = { workspace = true, features = ["raw_value"] }
28-
toml = { workspace = true }
2928

3029
[lib]
3130
doctest = false

crates/pglt_configuration/src/database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
66
#[derive(Clone, Debug, Deserialize, Eq, Partial, PartialEq, Serialize)]
77
#[partial(derive(Bpaf, Clone, Eq, PartialEq, Merge))]
88
#[partial(cfg_attr(feature = "schema", derive(schemars::JsonSchema)))]
9-
#[partial(serde(rename_all = "snake_case", default, deny_unknown_fields))]
9+
#[partial(serde(rename_all = "camelCase", default, deny_unknown_fields))]
1010
pub struct DatabaseConfiguration {
1111
/// The host of the database.
1212
#[partial(bpaf(long("host")))]

0 commit comments

Comments
 (0)