Skip to content

Commit 01f8cdf

Browse files
committed
feat: add --fix option
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
1 parent ab32553 commit 01f8cdf

6 files changed

Lines changed: 138 additions & 99 deletions

File tree

docs/cli/t4sanity.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ $ t4sanity -h
1414
│ --revision -rv TEXT Specify if you want to check the specific version. [default: None] │
1515
│ --exclude -e TEXT Exclude specific rules or rule groups. [default: None] │
1616
│ --strict -s Indicates whether warnings are treated as failures. │
17+
│ --fix -f Attempt to fix the issues reported by the sanity check. │
1718
│ --install-completion Install completion for the current shell. │
1819
│ --show-completion Show completion for the current shell, to copy it or customize the installation. │
1920
│ --help -h Show this message and exit. │
@@ -58,11 +59,20 @@ $ t4sanity <DATA_ROOT>
5859
STR008: ✅
5960
...
6061

61-
+-----------+---------+--------+--------+---------+----------+
62-
| DatasetID | Version | Passed | Failed | Skipped | Warnings |
63-
+-----------+---------+--------+--------+---------+----------+
64-
| dataset1 | 0 | 49 | 0 | 2 | 3 |
65-
+-----------+---------+--------+--------+---------+----------+
62+
+-----------+---------+--------+--------+---------+----------+-------+
63+
| DatasetID | Version | Passed | Failed | Skipped | Warnings | Fixed |
64+
+-----------+---------+--------+--------+---------+----------+-------+
65+
| dataset1 | 0 | 49 | 0 | 2 | 3 | 0 |
66+
+-----------+---------+--------+--------+---------+----------+-------+
67+
```
68+
69+
### Exclude Checks
70+
71+
With `-e; --exclude` option enables us to exclude specific checks by specifying the **rule IDs or groups**:
72+
73+
```shell
74+
# Exclude STR001 and all FMT-relevant rules
75+
t4sanity <DATA_ROOT> -e STR001 -e FMT
6676
```
6777
6878
### Strict Mode
@@ -73,28 +83,30 @@ With `-s; --strict` option enables us to treat warnings as failures:
7383
7484
```shell
7585
# Run strict mode
76-
t4sanity <DATA_ROOT> -s
86+
t4sanity <DATA_ROOT> --strict
7787
```
7888
79-
### Exclude Checks
89+
### Fix Issues
8090
81-
With `-e; --excludes` option enables us to exclude specific checks by specifying the **rule IDs or groups**:
91+
With `-f; --fix` option enables to fix issues automatically:
8292
8393
```shell
84-
# Exclude STR001 and all FMT-relevant rules
85-
t4sanity <DATA_ROOT> -e STR001 -e FMT
94+
# Fix issues automatically
95+
t4sanity <DATA_ROOT> --fix
8696
```
8797
8898
### Exit Status Logic
8999
90100
`t4sanity` CLI returns the exit code based on the following conditions:
91101
92-
| Condition | `--strict` | Exit Code | Notes |
93-
| ----------------------------------------------------------------------- | ----------------- | --------- | --------------------------------------------------- |
94-
| At least one `Severity.ERROR` rule failed | N/A | 1 | Always fails the run |
95-
| At least one `Severity.WARNING` rule failed, no `Severity.ERROR` failed | `False` (default) | 0 | Run is considered successful, warnings are reported |
96-
| At least one `Severity.WARNING` rule failed, no `Severity.ERROR` failed | `True` | 1 | Treat warnings as failures; exit with failure |
97-
| All rules passed or skipped | N/A | 0 | Run is considered successful |
102+
| Condition | `--strict` | `--fix` | Exit Code | Notes |
103+
| ---------------------------------------------------------------------------------- | ----------------- | ------- | --------- | ------------------------------------------------------------------------- |
104+
| At least one `Severity.ERROR` rule failed | N/A | `False` | 1 | Always fails the run |
105+
| At least one `Severity.ERROR` rule failed, but fixed | N/A | `True` | 0 | Run is considered successful, error reasons are reported and `Fixed=true` |
106+
| At least one `Severity.WARNING` rule failed, no `Severity.ERROR` failed | `False` (default) | N/A | 0 | Run is considered successful, warnings are reported |
107+
| At least one `Severity.WARNING` rule failed, no `Severity.ERROR` failed | `True` | `False` | 1 | Treat warnings as failures; exit with failure |
108+
| At least one `Severity.WARNING` rule failed, no `Severity.ERROR` failed, but fixed | `True` | `True` | 0 | Run is considered successful, warnings are reported and `Fixed=true` |
109+
| All rules passed or skipped | N/A | N/A | 0 | Run is considered successful |
98110
99111
### Dump Results as JSON
100112
@@ -117,7 +129,8 @@ Then a JSON file named `result.json` will be generated as follows:
117129
"severity": "<WARNING/ERROR: str>",
118130
"description": "<Description: str>",
119131
"status": "<PASSED/FAILED/SKIPPED: str>",
120-
"reasons": "<[<Reason1>, <Reason2>, ...]: [str; N] | null>" // Failed or skipped reasons, null if passed
132+
"reasons": "<[<Reason1>, <Reason2>, ...]: [str; N] | null>", // Failed or skipped reasons, null if passed
133+
"fixed": "<Fixed: bool>"
121134
},
122135
]
123136
}
@@ -134,3 +147,4 @@ Here is the description of the JSON format:
134147
- `description`: A description of the rule.
135148
- `status`: What happened when it ran.
136149
- `reasons`: An array of reasons for failure or skipped rules, null if passed.
150+
- `fixed`: Whether the rule was fixed.

0 commit comments

Comments
 (0)