Skip to content

Commit 1e42b89

Browse files
committed
migrate to jsonc config
1 parent 7068df3 commit 1e42b89

File tree

22 files changed

+69
-63
lines changed

22 files changed

+69
-63
lines changed

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.json`] file
48+
/// A data structured derived from the [`pglt.jsonc`] file
4949
pub rules: AnalyserRules,
5050
}
5151

crates/pglt_analyser/CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ 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.json` configuration file:
82+
We would like to set the options in the `pglt.jsonc` configuration file:
8383

8484
```json
8585
{
@@ -141,9 +141,9 @@ We currently require implementing _serde_'s traits `Deserialize`/`Serialize`.
141141

142142
Also, we use other `serde` macros to adjust the JSON configuration:
143143

144-
- `rename_all = "camelCase"`: it renames all fields in camel-case, so they are in line with the naming style of the `pglt.json`.
144+
- `rename_all = "camelCase"`: it renames all fields in camel-case, so they are in line with the naming style of the `pglt.jsonc`.
145145
- `deny_unknown_fields`: it raises an error if the configuration contains extraneous fields.
146-
- `default`: it uses the `Default` value when the field is missing from `pglt.json`. 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.
147147

148148
You can simply use a derive macros:
149149

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.json`.
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_json();
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.json`
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.json`
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.json`
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.json`
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.json` + 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.json` 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/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! This module contains the configuration of `pglt.json`
1+
//! This module contains the configuration of `pglt.jsonc`
22
//!
33
//! The configuration is divided by "tool", and then it's possible to further customise it
44
//! by language. The language might further options divided by tool.

crates/pglt_configuration/src/vcs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct VcsConfiguration {
2828
pub use_ignore_file: bool,
2929

3030
/// The folder where we should check for VCS files. By default, we will use the same
31-
/// folder where `pglt.json` was found.
31+
/// folder where `pglt.jsonc` was found.
3232
///
3333
/// If we can't find the configuration, it will attempt to use the current working directory.
3434
/// If no current working directory can't be found, we won't use the VCS integration, and a diagnostic

crates/pglt_fs/src/fs.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ mod os;
1818
pub struct ConfigName;
1919

2020
impl ConfigName {
21-
const PGLT_JSON: [&'static str; 1] = ["pglt.json"];
21+
const PGLT_JSONC: [&'static str; 1] = ["pglt.jsonc"];
2222

23-
pub const fn pglt_json() -> &'static str {
24-
Self::PGLT_JSON[0]
23+
pub const fn pglt_jsonc() -> &'static str {
24+
Self::PGLT_JSONC[0]
2525
}
2626

2727
pub const fn file_names() -> [&'static str; 1] {
28-
Self::PGLT_JSON
28+
Self::PGLT_JSONC
2929
}
3030
}
3131

crates/pglt_fs/src/path.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::ConfigName;
2121
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
2222
// NOTE: The order of the variants is important, the one on the top has the highest priority
2323
pub enum FileKind {
24-
/// A configuration file has the highest priority. It's usually `pglt.json`
24+
/// A configuration file has the highest priority. It's usually `pglt.jsonc`
2525
///
2626
/// Other third-party configuration files might be added in the future
2727
Config,
@@ -173,10 +173,10 @@ impl PgLTPath {
173173
}
174174

175175
/// The priority of the file.
176-
/// - `pglt.json` has the highest priority
176+
/// - `pglt.jsonc` has the highest priority
177177
/// - Other files are considered as files to handle
178178
fn priority(file_name: &OsStr) -> FileKinds {
179-
if file_name == ConfigName::pglt_json() {
179+
if file_name == ConfigName::pglt_jsonc() {
180180
FileKind::Config.into()
181181
} else {
182182
FileKind::Handleable.into()

crates/pglt_lsp/src/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl LSPServer {
7676
glob_pattern: GlobPattern::String(format!(
7777
"{}/{}",
7878
base_path.display(),
79-
ConfigName::pglt_json()
79+
ConfigName::pglt_jsonc()
8080
)),
8181
kind: Some(WatchKind::all()),
8282
},],
@@ -151,7 +151,7 @@ impl LanguageServer for LSPServer {
151151

152152
info!(
153153
"Attempting to load the configuration from '{}' file",
154-
ConfigName::pglt_json()
154+
ConfigName::pglt_jsonc()
155155
);
156156

157157
futures::join!(self.session.load_workspace_settings());

crates/pglt_lsp/src/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl Session {
400400
.map(|params| &params.client_capabilities)
401401
}
402402

403-
/// This function attempts to read the `pglt.json` configuration file from
403+
/// This function attempts to read the `pglt.jsonc` configuration file from
404404
/// the root URI and update the workspace settings accordingly
405405
#[tracing::instrument(level = "trace", skip(self))]
406406
pub(crate) async fn load_workspace_settings(&self) {

crates/pglt_lsp/tests/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ async fn test_database_connection() -> Result<()> {
372372
..Default::default()
373373
});
374374
fs.insert(
375-
url!("pglt.json").to_file_path().unwrap(),
375+
url!("pglt.jsonc").to_file_path().unwrap(),
376376
serde_json::to_string_pretty(&conf).unwrap(),
377377
);
378378

@@ -484,7 +484,7 @@ async fn test_completions() -> Result<()> {
484484
..Default::default()
485485
});
486486
fs.insert(
487-
url!("pglt.json").to_file_path().unwrap(),
487+
url!("pglt.jsonc").to_file_path().unwrap(),
488488
serde_json::to_string_pretty(&conf).unwrap(),
489489
);
490490

crates/pglt_workspace/src/configuration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn load_config(
120120
ConfigurationPathHint::None => file_system.working_directory().unwrap_or_default(),
121121
};
122122

123-
// We first search for `pglt.json`
123+
// We first search for `pglt.jsonc`
124124
if let Some(auto_search_result) = file_system.auto_search(
125125
&configuration_directory,
126126
ConfigName::file_names().as_slice(),
@@ -153,7 +153,7 @@ pub fn create_config(
153153
fs: &mut DynRef<dyn FileSystem>,
154154
configuration: &mut PartialConfiguration,
155155
) -> Result<(), WorkspaceError> {
156-
let path = PathBuf::from(ConfigName::pglt_json());
156+
let path = PathBuf::from(ConfigName::pglt_jsonc());
157157

158158
if fs.path_exists(&path) {
159159
return Err(ConfigurationDiagnostic::new_already_exists().into());

crates/pglt_workspace/src/workspace/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl WorkspaceServer {
108108
fn is_ignored(&self, path: &Path) -> bool {
109109
let file_name = path.file_name().and_then(|s| s.to_str());
110110
// Never ignore PgLT's config file regardless `include`/`ignore`
111-
(file_name != Some(ConfigName::pglt_json())) &&
111+
(file_name != Some(ConfigName::pglt_jsonc())) &&
112112
// Apply top-level `include`/`ignore
113113
(self.is_ignored_by_top_level_config(path) || self.is_ignored_by_migration_config(path))
114114
}

docs/checking_migrations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ To run it, simply point at your migrations directory.
88
pglt check supabase/migrations
99
```
1010

11-
When you are setting it up in an existing project, you might want to ignore all migrations that are already applied. To do so, add `migrationsDir` and `after` to your `pglt.json` file
11+
When you are setting it up in an existing project, you might want to ignore all migrations that are already applied. To do so, add `migrationsDir` and `after` to your `pglt.jsonc` file
1212

1313

1414
```json
@@ -28,5 +28,5 @@ pglt check supabase/migrations --migrations-dir="supabase/migrations" --after=17
2828

2929
This will only check migrations after the specified timestamp.
3030

31-
For pre-commit hooks and when working locally, use `--staged` to only lint files that have been staged. In CI environments, you most likely want to use `--changed` to only lint files that have been changed compared to your `vcs.default_branch` configuration. If `default_branch` is not set in your `pglt.json`, use `--since=REF` to specify the base branch to compare against.
31+
For pre-commit hooks and when working locally, use `--staged` to only lint files that have been staged. In CI environments, you most likely want to use `--changed` to only lint files that have been changed compared to your `vcs.default_branch` configuration. If `default_branch` is not set in your `pglt.jsonc`, use `--since=REF` to specify the base branch to compare against.
3232

docs/cli_reference.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Shows the version information and quit.
6262
- **` --verbose`** &mdash;
6363
Print additional diagnostics, and some diagnostics show more information. Also, print out what files were processed and which ones were modified.
6464
- **` --config-path`**=_`PATH`_ &mdash;
65-
Set the file path to the configuration file, or the directory path to find `pglt.json`. If used, it disables the default configuration file resolution.
65+
Set the file path to the configuration file, or the directory path to find `pglt.jsonc`. If used, it disables the default configuration file resolution.
6666
- **` --max-diagnostics`**=_`<none|<NUMBER>>`_ &mdash;
6767
Cap the amount of diagnostics displayed. When `none` is provided, the limit is lifted.
6868

@@ -111,7 +111,7 @@ Runs everything to the requested files.
111111
- **` --vcs-use-ignore-file`**=_`<true|false>`_ &mdash;
112112
Whether we should use the VCS ignore file. When [true], we will ignore the files specified in the ignore file.
113113
- **` --vcs-root`**=_`PATH`_ &mdash;
114-
The folder where we should check for VCS files. By default, we will use the same folder where `pglt.json` was found.
114+
The folder where we should check for VCS files. By default, we will use the same folder where `pglt.jsonc` was found.
115115

116116
If we can't find the configuration, it will attempt to use the current working directory. If no current working directory can't be found, we won't use the VCS integration, and a diagnostic will be emitted
117117
- **` --vcs-default-branch`**=_`BRANCH`_ &mdash;
@@ -149,7 +149,7 @@ Runs everything to the requested files.
149149
- **` --verbose`** &mdash;
150150
Print additional diagnostics, and some diagnostics show more information. Also, print out what files were processed and which ones were modified.
151151
- **` --config-path`**=_`PATH`_ &mdash;
152-
Set the file path to the configuration file, or the directory path to find `pglt.json`. If used, it disables the default configuration file resolution.
152+
Set the file path to the configuration file, or the directory path to find `pglt.jsonc`. If used, it disables the default configuration file resolution.
153153
- **` --max-diagnostics`**=_`<none|<NUMBER>>`_ &mdash;
154154
Cap the amount of diagnostics displayed. When `none` is provided, the limit is lifted.
155155

@@ -197,7 +197,7 @@ Runs everything to the requested files.
197197
- **` --changed`** &mdash;
198198
When set to true, only the files that have been changed compared to your `defaultBranch` configuration will be linted. This option should be used in CI environments.
199199
- **` --since`**=_`REF`_ &mdash;
200-
Use this to specify the base branch to compare against when you're using the --changed flag and the `defaultBranch` is not set in your `pglt.json`
200+
Use this to specify the base branch to compare against when you're using the --changed flag and the `defaultBranch` is not set in your `pglt.jsonc`
201201
- **`-h`**, **`--help`** &mdash;
202202
Prints help information
203203

@@ -220,7 +220,7 @@ Starts the daemon server process.
220220

221221
Uses environment variable **`PGLT_LOG_PATH`**
222222
- **` --config-path`**=_`PATH`_ &mdash;
223-
Allows to set a custom file path to the configuration file, or a custom directory path to find `pglt.json`
223+
Allows to set a custom file path to the configuration file, or a custom directory path to find `pglt.jsonc`
224224

225225
Uses environment variable **`PGLT_LOG_PREFIX_NAME`**
226226
- **`-h`**, **`--help`** &mdash;
@@ -267,7 +267,7 @@ Acts as a server for the Language Server Protocol over stdin/stdout.
267267

268268
Uses environment variable **`PGLT_LOG_PATH`**
269269
- **` --config-path`**=_`PATH`_ &mdash;
270-
Allows to set a custom file path to the configuration file, or a custom directory path to find `pglt.json`
270+
Allows to set a custom file path to the configuration file, or a custom directory path to find `pglt.jsonc`
271271

272272
Uses environment variable **`PGLT_CONFIG_PATH`**
273273
- **`-h`**, **`--help`** &mdash;

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ Our current focus is on refining and enhancing these core features while buildin
2929
3030
## Configuration
3131

32-
We recommend that you create a `pglt.json` configuration file for each project. This eliminates the need to repeat the CLI options each time you run a command, and ensures that we use the same configuration in your editor. Some options are also only available from a configuration file. If you are happy with the defaults, you don’t need to create a configuration file. To create the `pglt.json` file, run the `init` command in the root folder of your project:
32+
We recommend that you create a `pglt.jsonc` configuration file for each project. This eliminates the need to repeat the CLI options each time you run a command, and ensures that we use the same configuration in your editor. Some options are also only available from a configuration file. If you are happy with the defaults, you don’t need to create a configuration file. To create the `pglt.jsonc` file, run the `init` command in the root folder of your project:
3333

3434
```sh
3535
pglt init
3636
```
3737

38-
After running the `init` command, you’ll have a `pglt.json` file in your directory:
38+
After running the `init` command, you’ll have a `pglt.jsonc` file in your directory:
3939

4040
[//]: # (BEGIN DEFAULT_CONFIGURATION)
4141

docs/schemas/0.0.0/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@
401401
]
402402
},
403403
"root": {
404-
"description": "The folder where we should check for VCS files. By default, we will use the same folder where `pglt.json` was found.\n\nIf we can't find the configuration, it will attempt to use the current working directory. If no current working directory can't be found, we won't use the VCS integration, and a diagnostic will be emitted",
404+
"description": "The folder where we should check for VCS files. By default, we will use the same folder where `pglt.jsonc` was found.\n\nIf we can't find the configuration, it will attempt to use the current working directory. If no current working directory can't be found, we won't use the VCS integration, and a diagnostic will be emitted",
405405
"type": [
406406
"string",
407407
"null"

docs/schemas/latest/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@
401401
]
402402
},
403403
"root": {
404-
"description": "The folder where we should check for VCS files. By default, we will use the same folder where `pglt.json` was found.\n\nIf we can't find the configuration, it will attempt to use the current working directory. If no current working directory can't be found, we won't use the VCS integration, and a diagnostic will be emitted",
404+
"description": "The folder where we should check for VCS files. By default, we will use the same folder where `pglt.jsonc` was found.\n\nIf we can't find the configuration, it will attempt to use the current working directory. If no current working directory can't be found, we won't use the VCS integration, and a diagnostic will be emitted",
405405
"type": [
406406
"string",
407407
"null"

pglt.jsonc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"$schema": "./docs/schemas/latest/schema.json",
3+
"vcs": {
4+
"enabled": false,
5+
"clientKind": "git",
6+
"useIgnoreFile": false
7+
},
8+
"files": {
9+
"ignore": []
10+
},
11+
"linter": {
12+
"enabled": true,
13+
"rules": {
14+
"recommended": true
15+
}
16+
},
17+
// YOU CAN COMMENT ME OUT :)
18+
"db": {
19+
"host": "127.0.0.1",
20+
"port": 5432,
21+
"username": "postgres",
22+
"password": "postgres",
23+
"database": "postgres",
24+
"connTimeoutSecs": 10
25+
}
26+
}

pglt.toml

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)