Task Runner

Why task runner?

Linting makes more sense when run before committing your code. By doing so you can ensure no errors go into the repository and enforce code style. But running a lint process on a whole project is slow, and linting results can be irrelevant. Ultimately you only want to lint files that will be committed.

task-runner.json

After installation, you must have a task-runner.json file in your .husky directory that you can use to define your tasks.

you can run and test your tasks with dotnet husky run command. Once you are sure that your tasks are working properly, you can add it to the hook.

e.g

dotnet husky add pre-commit -c "dotnet husky run --group pre-commit"
A real-world example.
{
   "tasks": [
      {
         "name": "dotnet-format",
         "group": "pre-commit",
         "command": "dotnet",
         "args": ["dotnet-format", "--include", "${staged}"],
         "include": ["**/*.cs", "**/*.vb"]
      },
      {
         "name": "commit-message-linter",
         "command": "dotnet",
         "args": [
            "husky",
            "exec",
            ".husky/csx/commit-lint.csx",
            "--args",
            "${args}"
         ]
      },
      {
         "name": "warning-check",
         "command": "dotnet",
         "group": "pre-push",
         "args": ["build", "/warnaserror"],
         "include": ["**/*.cs", "**/*.vb"]
      },
      {
         "name": "eslint",
         "group": "pre-commit",
         "pathMode": "absolute",
         "cwd": "Client",
         "command": "npm",
         "args": ["run", "lint", "${staged}"],
         "include": ["**/*.ts", "**/*.vue", "**/*.js"]
      },
      {
         "name": "prettier",
         "group": "pre-commit",
         "pathMode": "absolute",
         "cwd": "Client",
         "command": "npx",
         "args": ["prettier", "--write", "${staged}"],
         "include": [
            "**/*.ts",
            "**/*.vue",
            "**/*.js",
            "**/*.json",
            "**/*.yml",
            "**/*.css",
            "**/*.scss"
         ]
      },
      {
         "name": "Welcome",
         "output": "always",
         "command": "bash",
         "args": ["-c", "echo Nice work! 🥂"],
         "windows": {
            "command": "cmd",
            "args": ["/c", "echo Nice work! 🥂"]
         }
      },
      {
         "name": "Run JB Clean Up Code",
         "command": "cmd",
         "pathMode": "relative",
         "args": [
           "/c",
           "dotnet",
           "jb",
           "cleanupcode",
           "proj.sln",
           "--profile=Team: Full Cleanup",
           "--include=${args}"
         ],
         "group": "pre-commit"
      }
   ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80