Skip to content

Commit b068358

Browse files
committed
feat(sanity): add --fix option (#258)
* feat: add --fix option Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp> * feat: override fix method for REC007 Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp> * refactor: do refactoring Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp> * docs: update document Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp> * docs: add docstring of the behavior Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp> * refactor: update report color Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp> --------- Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
1 parent e53fdeb commit b068358

9 files changed

Lines changed: 231 additions & 108 deletions

File tree

docs/cli/t4sanity.md

Lines changed: 47 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,46 @@ 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
96+
97+
>>>Sanity checking...: 1it [00:00, 9.70it/s]
98+
99+
=== DatasetID: dataset1 ===
100+
...
101+
REC007: --> FIXED ✅
102+
- All categories either must have an 'index' set or all have a 'null' index.
103+
...
104+
105+
+-----------+---------+--------+--------+---------+----------+-------+
106+
| DatasetID | Version | Passed | Failed | Skipped | Warnings | Fixed |
107+
+-----------+---------+--------+--------+---------+----------+-------+
108+
| dataset1 | 0 | 49 | 0 | 2 | 3 | 1 |
109+
+-----------+---------+--------+--------+---------+----------+-------+
86110
```
87111
112+
The generated report contains failure or warning reasons, but it's considered as passed if the fix was successful.
113+
88114
### Exit Status Logic
89115
90116
`t4sanity` CLI returns the exit code based on the following conditions:
91117
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 |
118+
| Condition | `--strict` | `--fix` | Exit Code | Notes |
119+
| ---------------------------------------------------------------------------------- | ----------------- | ------- | --------- | ------------------------------------------------------------------------- |
120+
| At least one `Severity.ERROR` rule failed | N/A | `False` | 1 | Always fails the run |
121+
| At least one `Severity.ERROR` rule failed, but fixed | N/A | `True` | 0 | Run is considered successful, error reasons are reported and `Fixed=true` |
122+
| At least one `Severity.WARNING` rule failed, no `Severity.ERROR` failed | `False` (default) | N/A | 0 | Run is considered successful, warnings are reported |
123+
| At least one `Severity.WARNING` rule failed, no `Severity.ERROR` failed | `True` | `False` | 1 | Treat warnings as failures; exit with failure |
124+
| 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` |
125+
| All rules passed or skipped | N/A | N/A | 0 | Run is considered successful |
98126
99127
### Dump Results as JSON
100128
@@ -117,7 +145,8 @@ Then a JSON file named `result.json` will be generated as follows:
117145
"severity": "<WARNING/ERROR: str>",
118146
"description": "<Description: str>",
119147
"status": "<PASSED/FAILED/SKIPPED: str>",
120-
"reasons": "<[<Reason1>, <Reason2>, ...]: [str; N] | null>" // Failed or skipped reasons, null if passed
148+
"reasons": "<[<Reason1>, <Reason2>, ...]: [str; N] | null>",
149+
"fixed": "<Fixed: bool>"
121150
},
122151
]
123152
}
@@ -134,3 +163,4 @@ Here is the description of the JSON format:
134163
- `description`: A description of the rule.
135164
- `status`: What happened when it ran.
136165
- `reasons`: An array of reasons for failure or skipped rules, null if passed.
166+
- `fixed`: Whether the rule was fixed.

0 commit comments

Comments
 (0)