Repository: go-task/task

Issue:
task isn't sorting correctly in version 3.42.1
### Description

I updated go-task to the latest version via homebrew

```
task --version
Task version: 3.42.1 (Homebrew)
```

I expected the listing to act the same as before. (using `--sort none`)

Instead the sorting is acting up, where the order is changed using the default, and when using `--sort none`. The `alphanumeric` is behaving as expected. 


> NOTE: order expected is [up, down, remove:volumes]

Output, plain task

```
❯ task
task: Available tasks for this project:
* down:                 Stop the ghost and db services
* up:                   Start the ghost and db services
* remove:volumes:       Remove the ghost and db services
task: Task "default" does not exist
```

task -l
```
❯ task -l
task: Available tasks for this project:
* down:                 Stop the ghost and db services
* up:                   Start the ghost and db services
* remove:volumes:       Remove the ghost and db services
```

task -l --sort none

```
❯ task -l --sort none
task: Available tasks for this project:
* down:                 Stop the ghost and db services
* up:                   Start the ghost and db services
* remove:volumes:       Remove the ghost and db services
```

task -l --sort alphanumeric

```
❯ task -l --sort alphanumeric
task: Available tasks for this project:
* down:                 Stop the ghost and db services
* remove:volumes:       Remove the ghost and db services
* up:                   Start the ghost and db services
```


Using shell fish.

### Version

3.42.1

### Operating system

Mac OS X 15.3.2 (24D81)

### Experiments Enabled

_No response_

### Example Taskfile

```YAML
# https://taskfile.dev

version: '3'

tasks:
  # default:
  #   cmd: task -l --sort none
  #   silent: true

  up:
    desc: Start the ghost and db services
    cmds:
      - docker compose --env-file .env up -d --remove-orphans

  down:
    desc: Stop the ghost and db services
    cmds:
      - docker compose --env-file .env down

  remove:volumes:
    desc: Remove the ghost and db services
    cmds:
      - docker compose --env-file .env down --volumes
```

Discussion:
@trulede: @bartdorlandt the default behaviour is AlphaNumericWithRootTasksFirst (which is observed in your report) and that was also linked to the CLI option "none". I've created a PR which adds a sorter for the CLI option "none" which does not sort the tasks.@bartdorlandt: @trulede , Just to verify that AlphaNumericWithRootTasksFirst is actually the default... Because the outputs are different.

the default order was:

```
* down:                 Stop the ghost and db services
* up:                   Start the ghost and db services
* remove:volumes:       Remove the ghost and db services
```

while the AlphaNumeric is:

```
* down:                 Stop the ghost and db services
* remove:volumes:       Remove the ghost and db services
* up:                   Start the ghost and db services
```@trulede: @bartdorlandt as it is implemented now (it was recently changed), default sorting is "AlphaNumericWithRootTasksFirst" which is what you are seeing (root tasks are apparently those _without_ an `:` in the name). Then you have the choice of AlphaNumeric or None.
@bartdorlandt: That makes complete sense. The tasks with ":" are indeed below the other tasks. Thank you for clarifying and the quick fix. Awesome! @pd93: > root tasks are apparently those without an : in the name

Correct. Just to expand on this, "root tasks" are any tasks without a parent namespace. Namespaces are separated by colons in Task and can come from `includes` or by manually adding a `:` separator in a task name.

The reason for this sorting is that when sorting _just_ alphanumerically, other tasks get sorted by namespace since tasks in the same namespace have the same prefix, but since root tasks have no prefix, they get mixed in randomly amongst the other namespaces which feels weird, so we group them at the top.

Solution patch:
diff --git a/internal/flags/flags.go b/internal/flags/flags.go
index 7d437537..8c21193e 100644
--- a/internal/flags/flags.go
+++ b/internal/flags/flags.go
@@ -184,7 +184,7 @@ func WithExecutorOptions() task.ExecutorOption {
 		var sorter sort.Sorter
 		switch TaskSort {
 		case "none":
-			sorter = nil
+			sorter = sort.NoSort
 		case "alphanumeric":
 			sorter = sort.AlphaNumeric
 		}
diff --git a/internal/sort/sorter.go b/internal/sort/sorter.go
index 404bc84a..14195973 100644
--- a/internal/sort/sorter.go
+++ b/internal/sort/sorter.go
@@ -9,6 +9,11 @@ import (
 // A Sorter is any function that sorts a set of tasks.
 type Sorter func(items []string, namespaces []string) []string
 
+// NoSort leaves the tasks in the order they are defined.
+func NoSort(items []string, namespaces []string) []string {
+	return items
+}
+
 // AlphaNumeric sorts the JSON output so that tasks are in alpha numeric order
 // by task name.
 func AlphaNumeric(items []string, namespaces []string) []string {



Test patch:
diff --git a/internal/sort/sorter_test.go b/internal/sort/sorter_test.go
index e55f0f0f..50a0071e 100644
--- a/internal/sort/sorter_test.go
+++ b/internal/sort/sorter_test.go
@@ -79,3 +79,35 @@ func TestAlphaNumeric_Sort(t *testing.T) {
 		})
 	}
 }
+
+func TestNoSort_Sort(t *testing.T) {
+	t.Parallel()
+
+	item1 := "a-item1"
+	item2 := "m-item2"
+	item3 := "ns1:item3"
+	item4 := "ns2:item4"
+	item5 := "z-item5"
+	item6 := "ns3:item6"
+
+	tests := []struct {
+		name  string
+		items []string
+		want  []string
+	}{
+		{
+			name:  "all items in order of definition",
+			items: []string{item3, item2, item5, item1, item4, item6},
+			want:  []string{item3, item2, item5, item1, item4, item6},
+		},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			t.Parallel()
+
+			NoSort(tt.items, nil)
+			assert.Equal(t, tt.want, tt.items)
+		})
+	}
+}