mirror of
https://github.com/dlang-community/D-Scanner.git
synced 2025-04-26 05:10:03 +03:00
include resolved autofixes in --report
output (#915)
This commit is contained in:
parent
cae7d595b8
commit
4c759b072c
4 changed files with 108 additions and 3 deletions
|
@ -91,6 +91,11 @@ dscanner -S source/
|
||||||
dscanner --report source/
|
dscanner --report source/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The `--report` switch includes all information, plus cheap to compute autofixes
|
||||||
|
that are already resolved ahead of time, as well as the names for the autofixes
|
||||||
|
that need to be resolved using the `--resolveMessage` switch like described
|
||||||
|
below.
|
||||||
|
|
||||||
You can also specify custom formats using `-f` / `--errorFormat`, where there
|
You can also specify custom formats using `-f` / `--errorFormat`, where there
|
||||||
are also built-in formats for GitHub Actions:
|
are also built-in formats for GitHub Actions:
|
||||||
|
|
||||||
|
@ -101,7 +106,7 @@ dscanner -S -f github source/
|
||||||
dscanner -S -f '{filepath}({line}:{column})[{type}]: {message}' source/
|
dscanner -S -f '{filepath}({line}:{column})[{type}]: {message}' source/
|
||||||
```
|
```
|
||||||
|
|
||||||
To collect automatic issue fixes for a given location use
|
To resolve automatic issue fixes for a given location use
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# collecting automatic issue fixes
|
# collecting automatic issue fixes
|
||||||
|
|
|
@ -55,6 +55,9 @@ class DScannerJsonReporter
|
||||||
|
|
||||||
private static JSONValue toJson(Issue issue)
|
private static JSONValue toJson(Issue issue)
|
||||||
{
|
{
|
||||||
|
import std.sumtype : match;
|
||||||
|
import dscanner.analysis.base : AutoFix;
|
||||||
|
|
||||||
// dfmt off
|
// dfmt off
|
||||||
JSONValue js = JSONValue([
|
JSONValue js = JSONValue([
|
||||||
"key": JSONValue(issue.message.key),
|
"key": JSONValue(issue.message.key),
|
||||||
|
@ -80,6 +83,27 @@ class DScannerJsonReporter
|
||||||
"message": JSONValue(a.message),
|
"message": JSONValue(a.message),
|
||||||
])
|
])
|
||||||
).array
|
).array
|
||||||
|
),
|
||||||
|
"autofixes": JSONValue(
|
||||||
|
issue.message.autofixes.map!(a =>
|
||||||
|
JSONValue([
|
||||||
|
"name": JSONValue(a.name),
|
||||||
|
"replacements": a.replacements.match!(
|
||||||
|
(const AutoFix.CodeReplacement[] replacements) => JSONValue(
|
||||||
|
replacements.map!(r => JSONValue([
|
||||||
|
"range": JSONValue([
|
||||||
|
JSONValue(r.range[0]),
|
||||||
|
JSONValue(r.range[1])
|
||||||
|
]),
|
||||||
|
"newText": JSONValue(r.newText)
|
||||||
|
])).array
|
||||||
|
),
|
||||||
|
(const AutoFix.ResolveContext _) => JSONValue(
|
||||||
|
"resolvable"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
])
|
||||||
|
).array
|
||||||
)
|
)
|
||||||
]);
|
]);
|
||||||
// dfmt on
|
// dfmt on
|
||||||
|
|
|
@ -2,5 +2,11 @@ struct S
|
||||||
{
|
{
|
||||||
int myProp() @property
|
int myProp() @property
|
||||||
{
|
{
|
||||||
|
static if (a)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if (b)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,81 @@
|
||||||
"message": "Zero-parameter '@property' function should be marked 'const', 'inout', or 'immutable'.",
|
"message": "Zero-parameter '@property' function should be marked 'const', 'inout', or 'immutable'.",
|
||||||
"name": "function_attribute_check",
|
"name": "function_attribute_check",
|
||||||
"supplemental": [],
|
"supplemental": [],
|
||||||
|
"type": "warn",
|
||||||
|
"autofixes": [
|
||||||
|
{
|
||||||
|
"name": "Mark function `const`",
|
||||||
|
"replacements": [
|
||||||
|
{
|
||||||
|
"newText": " const",
|
||||||
|
"range": [
|
||||||
|
24,
|
||||||
|
24
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Mark function `inout`",
|
||||||
|
"replacements": [
|
||||||
|
{
|
||||||
|
"newText": " inout",
|
||||||
|
"range": [
|
||||||
|
24,
|
||||||
|
24
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Mark function `immutable`",
|
||||||
|
"replacements": [
|
||||||
|
{
|
||||||
|
"newText": " immutable",
|
||||||
|
"range": [
|
||||||
|
24,
|
||||||
|
24
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"autofixes": [
|
||||||
|
{
|
||||||
|
"name": "Insert `static`",
|
||||||
|
"replacements": [
|
||||||
|
{
|
||||||
|
"newText": "static ",
|
||||||
|
"range": [
|
||||||
|
69,
|
||||||
|
69
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Wrap '{}' block around 'if'",
|
||||||
|
"replacements": "resolvable"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"column": 3,
|
||||||
|
"endColumn": 10,
|
||||||
|
"endIndex": 71,
|
||||||
|
"endLine": 8,
|
||||||
|
"fileName": "it/source_autofix.d",
|
||||||
|
"index": 64,
|
||||||
|
"key": "dscanner.suspicious.static_if_else",
|
||||||
|
"line": 8,
|
||||||
|
"message": "Mismatched static if. Use 'else static if' here.",
|
||||||
|
"name": "static_if_else_check",
|
||||||
|
"supplemental": [],
|
||||||
"type": "warn"
|
"type": "warn"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"lineOfCodeCount": 0,
|
"lineOfCodeCount": 3,
|
||||||
"statementCount": 0,
|
"statementCount": 4,
|
||||||
"structCount": 1,
|
"structCount": 1,
|
||||||
"templateCount": 0,
|
"templateCount": 0,
|
||||||
"undocumentedPublicSymbols": 0
|
"undocumentedPublicSymbols": 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue