nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: numtide/treefmt
Pull request #290 (2024-05-14 19:29:57)

fix: -f short flag for specifying formatters
Preserves backwards compatibility with v1

Signed-off-by: Brian McGee <brian@bmcgee.ie>



Patch:
diff --git a/cli/cli.go b/cli/cli.go
index 9ebf8a2..d399777 100644
--- a/cli/cli.go
+++ b/cli/cli.go
@@ -15,7 +15,7 @@ type Format struct {
 	ClearCache            bool               `short:"c" help:"Reset the evaluation cache. Use in case the cache is not precise enough."`
 	ConfigFile            string             `type:"existingfile" default:"./treefmt.toml" help:"The config file to use."`
 	FailOnChange          bool               `help:"Exit with error if any changes were made. Useful for CI."`
-	Formatters            []string           `help:"Specify formatters to apply. Defaults to all formatters."`
+	Formatters            []string           `short:"f" help:"Specify formatters to apply. Defaults to all formatters."`
 	TreeRoot              string             `type:"existingdir" default:"." help:"The root directory from which treefmt will start walking the filesystem."`
 	Walk                  walk.Type          `enum:"auto,git,filesystem" default:"auto" help:"The method used to traverse the files within --tree-root. Currently supports 'auto', 'git' or 'filesystem'."`
 	Verbosity             int                `name:"verbose" short:"v" type:"counter" default:"0" env:"LOG_LEVEL" help:"Set the verbosity of logs e.g. -vv."`


Test patch:
diff --git a/cli/format_test.go b/cli/format_test.go
index 0d86cba..51d26a8 100644
--- a/cli/format_test.go
+++ b/cli/format_test.go
@@ -106,7 +106,7 @@ func TestSpecifyingFormatters(t *testing.T) {
 	assertStats(t, as, 31, 31, 2, 2)
 
 	setup()
-	_, err = cmd(t, "-c", "--config-file", configPath, "--tree-root", tempDir, "--formatters", "ruby,nix")
+	_, err = cmd(t, "-c", "--config-file", configPath, "--tree-root", tempDir, "-f", "ruby,nix")
 	as.NoError(err)
 	assertStats(t, as, 31, 31, 2, 2)
Repository: numtide/treefmt
Pull request #297 (2024-05-17 10:48:14)

Error out when a path matches multiple formatters
When multiple formatters need to operate on the same path they must do so as part of a pipeline to avoid concurrent modification and non-deterministic issues.

This change will detect when a path has matched against more than one pipeline and error out indicating the pipelines involved.

Signed-off-by: Brian McGee <brian@bmcgee.ie>



Patch:
diff --git a/cli/format.go b/cli/format.go
index aa72ff5..4b14220 100644
--- a/cli/format.go
+++ b/cli/format.go
@@ -372,20 +372,24 @@ func applyFormatters(ctx context.Context) func() error {
 
 		// iterate the files channel, checking if any pipeline wants it, and attempting to apply if so.
 		for file := range filesCh {
-			var matched bool
+			var matches []string
+
 			for key, pipeline := range pipelines {
 				if !pipeline.Wants(file) {
 					continue
 				}
-				matched = true
+				matches = append(matches, key)
 				tryApply(key, file)
 			}
-			if matched {
-				stats.Add(stats.Matched, 1)
-			} else {
+			switch len(matches) {
+			case 0:
 				log.Debugf("no match found: %s", file.Path)
 				// no match, so we send it direct to the processed channel
 				processedCh <- file
+			case 1:
+				stats.Add(stats.Matched, 1)
+			default:
+				return fmt.Errorf("path '%s' matched multiple formatters/pipelines %v", file.Path, matches)
 			}
 		}
 


Test patch:
diff --git a/cli/format_test.go b/cli/format_test.go
index 51d26a8..e4c3b2a 100644
--- a/cli/format_test.go
+++ b/cli/format_test.go
@@ -196,6 +196,37 @@ func TestIncludesAndExcludes(t *testing.T) {
 	assertStats(t, as, 31, 31, 2, 0)
 }
 
+func TestMatchingMultiplePipelines(t *testing.T) {
+	as := require.New(t)
+
+	tempDir := test.TempExamples(t)
+	configPath := tempDir + "/multiple.toml"
+
+	cfg := config2.Config{
+		Formatters: map[string]*config2.Formatter{
+			"echo": {
+				Command:  "echo",
+				Includes: []string{"*"},
+			},
+			"touch": {
+				Command:  "touch",
+				Includes: []string{"*"},
+			},
+		},
+	}
+
+	test.WriteConfig(t, configPath, cfg)
+	_, err := cmd(t, "-c", "--config-file", configPath, "--tree-root", tempDir)
+	as.ErrorContains(err, "matched multiple formatters/pipelines")
+	as.ErrorContains(err, "echo")
+	as.ErrorContains(err, "touch")
+
+	// run with only one formatter
+	test.WriteConfig(t, configPath, cfg)
+	_, err = cmd(t, "-c", "--config-file", configPath, "--tree-root", tempDir, "-f", "echo")
+	as.NoError(err)
+}
+
 func TestCache(t *testing.T) {
 	as := require.New(t)