Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa34f7fcb6 |
No files matched your search
@@ -48,6 +48,14 @@ pub fn run(args: &[String], verbose: u8) -> Result<i32> {
|
||||
cmd.arg("--format=json");
|
||||
}
|
||||
|
||||
// Pint only includes `appliedFixers`/`fixers` in verbose mode; without -v
|
||||
// the JSON lists file names with no rule data, so the filter has nothing
|
||||
// to report. Inject it unless the caller already asked for a verbosity
|
||||
// level, so `rtk pint -vv` etc. still passes through untouched.
|
||||
if !has_format && !is_utility_cmd && !has_verbose_flag(args) {
|
||||
cmd.arg("-v");
|
||||
}
|
||||
|
||||
for arg in args {
|
||||
cmd.arg(arg);
|
||||
}
|
||||
@@ -73,6 +81,10 @@ pub fn run(args: &[String], verbose: u8) -> Result<i32> {
|
||||
)
|
||||
}
|
||||
|
||||
fn has_verbose_flag(args: &[String]) -> bool {
|
||||
args.iter().any(|a| matches!(a.as_str(), "-v" | "-vv" | "-vvv"))
|
||||
}
|
||||
|
||||
pub(crate) fn filter_pint_json(output: &str) -> String {
|
||||
let trimmed = output.trim();
|
||||
if trimmed.is_empty() {
|
||||
@@ -219,6 +231,38 @@ mod tests {
|
||||
assert!(result.contains("x.php (0)"), "got: {}", result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pint_non_verbose_real_output_loses_rule_data() {
|
||||
// Real `pint --format=json` output WITHOUT -v: Pint only includes
|
||||
// fixers when run verbosely, so files that were changed still show
|
||||
// up with no rule names. This is the exact shape that motivated
|
||||
// injecting -v in run() — without it, every real invocation of
|
||||
// `rtk pint` reports "0 changes" even when files were reformatted.
|
||||
let json = include_str!("../../../tests/fixtures/pint_json_non_verbose.txt");
|
||||
let result = filter_pint_json(json);
|
||||
assert!(result.contains("0 changes in 2 files"), "got: {}", result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pint_verbose_real_output_preserves_rule_data() {
|
||||
// Same run with -v: fixers are populated, so rtk can actually report
|
||||
// which rules fired per file.
|
||||
let json = include_str!("../../../tests/fixtures/pint_json_verbose.txt");
|
||||
let result = filter_pint_json(json);
|
||||
assert!(result.contains("changes in 2 files"), "got: {}", result);
|
||||
assert!(!result.contains("0 changes in 2 files"), "got: {}", result);
|
||||
assert!(result.contains("no_unused_imports"), "got: {}", result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_has_verbose_flag() {
|
||||
assert!(has_verbose_flag(&["-v".to_string()]));
|
||||
assert!(has_verbose_flag(&["-vv".to_string()]));
|
||||
assert!(has_verbose_flag(&["-vvv".to_string()]));
|
||||
assert!(!has_verbose_flag(&["--dirty".to_string()]));
|
||||
assert!(!has_verbose_flag(&[]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pint_invalid_json_falls_back() {
|
||||
let result = filter_pint_json("Laravel Pint v1.13.6\n\n... some text ...");
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"about":"PHP CS Fixer 3.95.8 Adalbertus by Fabien Potencier, Dariusz Ruminski and contributors.","files":[{"name":"app\/Foo.php"},{"name":"app\/Bar.php"}],"time":{"total":0},"memory":0}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"about":"PHP CS Fixer 3.95.8 Adalbertus by Fabien Potencier, Dariusz Ruminski and contributors.","files":[{"name":"app\/Foo.php","appliedFixers":["single_space_around_construct","method_argument_space","blank_line_after_opening_tag","braces_position","no_unused_imports","blank_line_before_statement","binary_operator_spaces"],"diff":"--- \/work\/app\/Foo.php\n+++ \/work\/app\/Foo.php\n@@ -1,14 +1,15 @@\n <?php\n+\n namespace App;\n-use Illuminate\\Support\\Str;\n-use App\\Models\\User;\n \n class Foo\n {\n- public function bar($x,$y) {\n- if($x==$y){\n+ public function bar($x, $y)\n+ {\n+ if ($x == $y) {\n return true;\n }\n- return false;\n+\n+ return false;\n }\n }\n"},{"name":"app\/Bar.php","appliedFixers":["modifier_keywords","class_definition","single_space_around_construct","blank_line_after_opening_tag","braces_position","statement_indentation","blank_line_after_namespace","blank_line_before_statement","binary_operator_spaces"],"diff":"--- \/work\/app\/Bar.php\n+++ \/work\/app\/Bar.php\n@@ -1,9 +1,14 @@\n <?php\n+\n namespace App;\n-class Bar {\n-function baz() {\n-$a=1;\n-$b = 2;\n-return $a+$b;\n-}\n+\n+class Bar\n+{\n+ public function baz()\n+ {\n+ $a = 1;\n+ $b = 2;\n+\n+ return $a + $b;\n+ }\n }\n"}],"time":{"total":0},"memory":0}
|
||||
Reference in new issue
Block a user