From 757bc7401373e9f7dbd411e1cacea2d2eee09f92 Mon Sep 17 00:00:00 2001
From: Fernandez Ludovic <ldez@users.noreply.github.com>
Date: Wed, 19 Feb 2025 17:02:27 +0100
Subject: [PATCH 1/3] chore: remove sort-results option

---
 .golangci.next.reference.yml               |  4 ----
 jsonschema/golangci.next.jsonschema.json   |  5 -----
 pkg/commands/flagsets.go                   |  2 --
 pkg/config/output.go                       | 14 ++++--------
 pkg/config/output_test.go                  | 25 ++++++----------------
 pkg/result/processors/sort_results.go      |  4 ----
 pkg/result/processors/sort_results_test.go | 15 ++-----------
 7 files changed, 12 insertions(+), 57 deletions(-)

diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml
index 4e32e784a3a4..3af21beae649 100644
--- a/.golangci.next.reference.yml
+++ b/.golangci.next.reference.yml
@@ -4102,10 +4102,6 @@ output:
   # Default: ""
   path-prefix: ""
 
-  # Sort results by the order defined in `sort-order`.
-  # Default: false
-  sort-results: true
-
   # Order to use when sorting results.
   # Require `sort-results` to `true`.
   # Possible values: `file`, `linter`, and `severity`.
diff --git a/jsonschema/golangci.next.jsonschema.json b/jsonschema/golangci.next.jsonschema.json
index 6e8891ac8020..25b765c289c8 100644
--- a/jsonschema/golangci.next.jsonschema.json
+++ b/jsonschema/golangci.next.jsonschema.json
@@ -3890,11 +3890,6 @@
           "items": {
             "enum": ["linter", "severity", "file"]
           }
-        },
-        "sort-results": {
-          "description": "Sort results by: filepath, line and column.",
-          "type": "boolean",
-          "default": true
         }
       }
     },
diff --git a/pkg/commands/flagsets.go b/pkg/commands/flagsets.go
index 4260c8712af1..071c7730568c 100644
--- a/pkg/commands/flagsets.go
+++ b/pkg/commands/flagsets.go
@@ -70,8 +70,6 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
 }
 
 func setupOutputFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
-	internal.AddFlagAndBind(v, fs, fs.Bool, "sort-results", "output.sort-results", false,
-		color.GreenString("Sort linter results"))
 	internal.AddFlagAndBind(v, fs, fs.StringSlice, "sort-order", "output.sort-order", nil,
 		color.GreenString("Sort order of linter results"))
 	internal.AddFlagAndBind(v, fs, fs.String, "path-prefix", "output.path-prefix", "",
diff --git a/pkg/config/output.go b/pkg/config/output.go
index a2b1eb9980cf..43dce3900ccc 100644
--- a/pkg/config/output.go
+++ b/pkg/config/output.go
@@ -1,25 +1,19 @@
 package config
 
 import (
-	"errors"
 	"fmt"
 	"slices"
 	"strings"
 )
 
 type Output struct {
-	Formats     Formats  `mapstructure:"formats"`
-	SortResults bool     `mapstructure:"sort-results"`
-	SortOrder   []string `mapstructure:"sort-order"`
-	PathPrefix  string   `mapstructure:"path-prefix"`
-	ShowStats   bool     `mapstructure:"show-stats"`
+	Formats    Formats  `mapstructure:"formats"`
+	SortOrder  []string `mapstructure:"sort-order"`
+	PathPrefix string   `mapstructure:"path-prefix"`
+	ShowStats  bool     `mapstructure:"show-stats"`
 }
 
 func (o *Output) Validate() error {
-	if !o.SortResults && len(o.SortOrder) > 0 {
-		return errors.New("sort-results should be 'true' to use sort-order")
-	}
-
 	validOrders := []string{"linter", "file", "severity"}
 
 	all := strings.Join(o.SortOrder, " ")
diff --git a/pkg/config/output_test.go b/pkg/config/output_test.go
index 6d8aad17953f..1e19323d15a0 100644
--- a/pkg/config/output_test.go
+++ b/pkg/config/output_test.go
@@ -14,29 +14,25 @@ func TestOutput_Validate(t *testing.T) {
 		{
 			desc: "file",
 			settings: &Output{
-				SortResults: true,
-				SortOrder:   []string{"file"},
+				SortOrder: []string{"file"},
 			},
 		},
 		{
 			desc: "linter",
 			settings: &Output{
-				SortResults: true,
-				SortOrder:   []string{"linter"},
+				SortOrder: []string{"linter"},
 			},
 		},
 		{
 			desc: "severity",
 			settings: &Output{
-				SortResults: true,
-				SortOrder:   []string{"severity"},
+				SortOrder: []string{"severity"},
 			},
 		},
 		{
 			desc: "multiple",
 			settings: &Output{
-				SortResults: true,
-				SortOrder:   []string{"file", "linter", "severity"},
+				SortOrder: []string{"file", "linter", "severity"},
 			},
 		},
 	}
@@ -57,26 +53,17 @@ func TestOutput_Validate_error(t *testing.T) {
 		settings *Output
 		expected string
 	}{
-		{
-			desc: "sort-results false and sort-order",
-			settings: &Output{
-				SortOrder: []string{"file"},
-			},
-			expected: "sort-results should be 'true' to use sort-order",
-		},
 		{
 			desc: "invalid sort-order",
 			settings: &Output{
-				SortResults: true,
-				SortOrder:   []string{"a"},
+				SortOrder: []string{"a"},
 			},
 			expected: `unsupported sort-order name "a"`,
 		},
 		{
 			desc: "duplicate",
 			settings: &Output{
-				SortResults: true,
-				SortOrder:   []string{"file", "linter", "severity", "linter"},
+				SortOrder: []string{"file", "linter", "severity", "linter"},
 			},
 			expected: `the sort-order name "linter" is repeated several times`,
 		},
diff --git a/pkg/result/processors/sort_results.go b/pkg/result/processors/sort_results.go
index 96f5574f6f10..4bc7636015dc 100644
--- a/pkg/result/processors/sort_results.go
+++ b/pkg/result/processors/sort_results.go
@@ -55,10 +55,6 @@ func (SortResults) Name() string { return "sort_results" }
 
 // Process is performing sorting of the result issues.
 func (p SortResults) Process(issues []result.Issue) ([]result.Issue, error) {
-	if !p.cfg.SortResults {
-		return issues, nil
-	}
-
 	if len(p.cfg.SortOrder) == 0 {
 		p.cfg.SortOrder = []string{orderNameFile}
 	}
diff --git a/pkg/result/processors/sort_results_test.go b/pkg/result/processors/sort_results_test.go
index fe9782abab39..039dfce296bf 100644
--- a/pkg/result/processors/sort_results_test.go
+++ b/pkg/result/processors/sort_results_test.go
@@ -209,22 +209,11 @@ func Test_numericCompare(t *testing.T) {
 	}
 }
 
-func TestSortResults_Process_noSorting(t *testing.T) {
+func TestSortResults_Process(t *testing.T) {
 	tests := make([]result.Issue, len(issues))
 	copy(tests, issues)
 
-	sr := NewSortResults(&config.Output{})
-
-	results, err := sr.Process(tests)
-	require.NoError(t, err)
-	assert.Equal(t, tests, results)
-}
-
-func TestSortResults_Process_Sorting(t *testing.T) {
-	tests := make([]result.Issue, len(issues))
-	copy(tests, issues)
-
-	cfg := &config.Output{SortResults: true}
+	cfg := &config.Output{}
 
 	sr := NewSortResults(cfg)
 

From fc6a1fe953a70a36b545309594405c511aa16e03 Mon Sep 17 00:00:00 2001
From: Fernandez Ludovic <ldez@users.noreply.github.com>
Date: Wed, 19 Feb 2025 17:04:46 +0100
Subject: [PATCH 2/3] chore: new sort-order default

---
 .golangci.next.reference.yml               |  2 +-
 pkg/commands/flagsets.go                   |  2 --
 pkg/result/processors/sort_results.go      |  2 +-
 pkg/result/processors/sort_results_test.go |  2 +-
 test/run_test.go                           | 41 ++++++----------------
 5 files changed, 14 insertions(+), 35 deletions(-)

diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml
index 3af21beae649..54c126766063 100644
--- a/.golangci.next.reference.yml
+++ b/.golangci.next.reference.yml
@@ -4114,7 +4114,7 @@ output:
   #   5. low
   # Either they are sorted alphabetically.
   #
-  # Default: ["file"]
+  # Default: ["linter", "file"]
   sort-order:
     - linter
     - severity
diff --git a/pkg/commands/flagsets.go b/pkg/commands/flagsets.go
index 071c7730568c..aee7fd330ff1 100644
--- a/pkg/commands/flagsets.go
+++ b/pkg/commands/flagsets.go
@@ -70,8 +70,6 @@ func setupRunFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
 }
 
 func setupOutputFlagSet(v *viper.Viper, fs *pflag.FlagSet) {
-	internal.AddFlagAndBind(v, fs, fs.StringSlice, "sort-order", "output.sort-order", nil,
-		color.GreenString("Sort order of linter results"))
 	internal.AddFlagAndBind(v, fs, fs.String, "path-prefix", "output.path-prefix", "",
 		color.GreenString("Path prefix to add to output"))
 	internal.AddFlagAndBind(v, fs, fs.Bool, "show-stats", "output.show-stats", false, color.GreenString("Show statistics per linter"))
diff --git a/pkg/result/processors/sort_results.go b/pkg/result/processors/sort_results.go
index 4bc7636015dc..ecadb69980fe 100644
--- a/pkg/result/processors/sort_results.go
+++ b/pkg/result/processors/sort_results.go
@@ -56,7 +56,7 @@ func (SortResults) Name() string { return "sort_results" }
 // Process is performing sorting of the result issues.
 func (p SortResults) Process(issues []result.Issue) ([]result.Issue, error) {
 	if len(p.cfg.SortOrder) == 0 {
-		p.cfg.SortOrder = []string{orderNameFile}
+		p.cfg.SortOrder = []string{orderNameLinter, orderNameFile}
 	}
 
 	var cmps []issueComparator
diff --git a/pkg/result/processors/sort_results_test.go b/pkg/result/processors/sort_results_test.go
index 039dfce296bf..f63cf36078cc 100644
--- a/pkg/result/processors/sort_results_test.go
+++ b/pkg/result/processors/sort_results_test.go
@@ -219,7 +219,7 @@ func TestSortResults_Process(t *testing.T) {
 
 	results, err := sr.Process(tests)
 	require.NoError(t, err)
-	assert.Equal(t, []result.Issue{issues[3], issues[2], issues[1], issues[0]}, results)
+	assert.Equal(t, []result.Issue{issues[1], issues[0], issues[3], issues[2]}, results)
 }
 
 func compToString(c int) string {
diff --git a/test/run_test.go b/test/run_test.go
index 84e6d139373e..d607c1f6193e 100644
--- a/test/run_test.go
+++ b/test/run_test.go
@@ -367,38 +367,19 @@ func TestUnsafeOk(t *testing.T) {
 }
 
 func TestSortedResults(t *testing.T) {
-	testCases := []struct {
-		opt  string
-		want string
-	}{
-		{
-			opt: "--sort-results=false",
-			want: "testdata/sort_results/main.go:15:13: Error return value is not checked (errcheck)" + "\n" +
-				"testdata/sort_results/main.go:12:5: var `db` is unused (unused)",
-		},
-		{
-			opt: "--sort-results=true",
-			want: "testdata/sort_results/main.go:12:5: var `db` is unused (unused)" + "\n" +
-				"testdata/sort_results/main.go:15:13: Error return value is not checked (errcheck)",
-		},
-	}
-
 	binPath := testshared.InstallGolangciLint(t)
 
-	for _, test := range testCases {
-		t.Run(test.opt, func(t *testing.T) {
-			t.Parallel()
-
-			testshared.NewRunnerBuilder(t).
-				WithNoConfig().
-				WithArgs("--output.text.print-issued-lines=false", test.opt).
-				WithTargetPath(testdataDir, "sort_results").
-				WithBinPath(binPath).
-				Runner().
-				Run().
-				ExpectExitCode(exitcodes.IssuesFound).ExpectOutputEq(test.want + "\n")
-		})
-	}
+	testshared.NewRunnerBuilder(t).
+		WithNoConfig().
+		WithArgs("--output.text.print-issued-lines=false").
+		WithTargetPath(testdataDir, "sort_results").
+		WithBinPath(binPath).
+		Runner().
+		Run().
+		ExpectExitCode(exitcodes.IssuesFound).ExpectOutputEq(
+		"testdata/sort_results/main.go:15:13: Error return value is not checked (errcheck)" + "\n" +
+			"testdata/sort_results/main.go:12:5: var `db` is unused (unused)" + "\n",
+	)
 }
 
 func TestIdentifierUsedOnlyInTests(t *testing.T) {

From 3ea23c9097a5e51ff619e2eeab7e2415a0a70be4 Mon Sep 17 00:00:00 2001
From: Fernandez Ludovic <ldez@users.noreply.github.com>
Date: Mon, 24 Feb 2025 13:39:13 +0100
Subject: [PATCH 3/3] review

---
 .golangci.next.reference.yml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/.golangci.next.reference.yml b/.golangci.next.reference.yml
index 54c126766063..2a8d145e2179 100644
--- a/.golangci.next.reference.yml
+++ b/.golangci.next.reference.yml
@@ -4103,7 +4103,6 @@ output:
   path-prefix: ""
 
   # Order to use when sorting results.
-  # Require `sort-results` to `true`.
   # Possible values: `file`, `linter`, and `severity`.
   #
   # If the severity values are inside the following list, they are ordered in this order: