Skip to content

Commit 8b161d1

Browse files
authored
feat: add no-error-on-unmatched-pattern option (#639)
Currently, `squawk` exits with failure when the provided path pattern does not match any file. This behavior can be unexpected, specifically when `squawk` is given the instruction to ignore files (via `excluded_paths `) and thus does not find any file to work on. See issues #387 and #363 for more details. This PR adds the option `--no-error-on-unmatched-pattern`, which causes the exit code to be `0` in cases mentioned above. `squawk` will still print the message stating that no files were found with the given pattern, which should help debugging cases where this may be unexpected.
1 parent a58a323 commit 8b161d1

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

crates/squawk/src/main.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ struct Opt {
147147
global = true
148148
)]
149149
no_assume_in_transaction: bool,
150+
/// Do not exit with an error when provided path patterns do not match any files
151+
#[structopt(long = "no-error-on-unmatched-pattern", global = true)]
152+
no_error_on_unmatched_pattern: bool,
150153
}
151154

152155
#[allow(clippy::too_many_lines)]
@@ -213,10 +216,17 @@ Please open an issue at https://github.com/sbdchd/squawk/issues/new with the log
213216
conf.assume_in_transaction.unwrap_or_default()
214217
};
215218

219+
let no_error_on_unmatched_pattern = if opts.no_error_on_unmatched_pattern {
220+
opts.no_error_on_unmatched_pattern
221+
} else {
222+
false
223+
};
224+
216225
info!("pg version: {pg_version:?}");
217226
info!("excluded rules: {:?}", &excluded_rules);
218227
info!("excluded paths: {:?}", &excluded_paths);
219228
info!("assume in a transaction: {assume_in_transaction:?}");
229+
info!("no error on unmatched pattern: {no_error_on_unmatched_pattern:?}");
220230

221231
let mut clap_app = Opt::clap();
222232
let is_stdin = !io::stdin().is_terminal();
@@ -251,7 +261,9 @@ Please open an issue at https://github.com/sbdchd/squawk/issues/new with the log
251261
"Failed to find files for provided patterns: {:?}",
252262
opts.path_patterns
253263
);
254-
process::exit(1);
264+
if !no_error_on_unmatched_pattern {
265+
process::exit(1);
266+
}
255267
}
256268
if !found_paths.is_empty() || is_stdin {
257269
let stdout = io::stdout();
@@ -275,7 +287,7 @@ Please open an issue at https://github.com/sbdchd/squawk/issues/new with the log
275287
)?;
276288
return Ok(exit_code);
277289
}
278-
} else {
290+
} else if !no_error_on_unmatched_pattern {
279291
clap_app.print_long_help()?;
280292
println!();
281293
}

docs/docs/cli.md

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -130,49 +130,60 @@ USAGE:
130130
squawk [FLAGS] [OPTIONS] [path]... [SUBCOMMAND]
131131
132132
FLAGS:
133-
--assume-in-transaction
133+
--assume-in-transaction
134134
Assume that a transaction will wrap each SQL file when run by a migration tool
135-
135+
136136
Use --no-assume-in-transaction to override any config file that sets this
137-
-h, --help
137+
-h, --help
138138
Prints help information
139139
140-
-V, --version
140+
--no-error-on-unmatched-pattern
141+
Do not exit with an error when provided path patterns do not match any files
142+
143+
-V, --version
141144
Prints version information
142145
143-
--verbose
146+
--verbose
144147
Enable debug logging output
145148
146149
147150
OPTIONS:
148-
-c, --config <config-path>
151+
-c, --config <config-path>
149152
Path to the squawk config file (.squawk.toml)
150153
151-
--debug <format>
152-
Output debug format [possible values: Lex, Parsed]
153-
154-
-e, --exclude <rule>...
154+
--debug <format>
155+
Output debug format [possible values: Lex, Parse, Ast]
156+
157+
--exclude-path <excluded-path>...
158+
Paths to exclude
159+
160+
For example:
161+
162+
`--exclude-path=005_user_ids.sql --exclude-path=009_account_emails.sql`
163+
164+
`--exclude-path='*user_ids.sql'`
165+
-e, --exclude <rule>...
155166
Exclude specific warnings
156-
167+
157168
For example: --exclude=require-concurrent-index-creation,ban-drop-database
158-
159-
--pg-version <pg-version>
169+
--pg-version <pg-version>
160170
Specify postgres version
161-
171+
162172
For example: --pg-version=13.0
163-
--reporter <reporter>
164-
Style of error reporting [possible values: Tty, Gcc, Json]
173+
--reporter <reporter>
174+
Style of error reporting [possible values: Tty, Gcc, Json, Gitlab]
165175
166-
--stdin-filepath <filepath>
176+
--stdin-filepath <filepath>
167177
Path to use in reporting for stdin
168178
169179
170180
ARGS:
171-
<path>...
172-
Paths to search
181+
<path>...
182+
Paths or patterns to search
173183
174184
175185
SUBCOMMANDS:
176186
help Prints this message or the help of the given subcommand(s)
187+
server Run the language server
177188
upload-to-github Comment on a PR with Squawk's results
178189
```

0 commit comments

Comments
 (0)