Skip to content

Commit 96b39c5

Browse files
committed
add option to select diagnostic level of problems
1 parent a7fc2a8 commit 96b39c5

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ sudo wget -O /usr/bin/spelling.txt "https://raw.githubusercontent.com/torvalds/l
1414
sudo chmod 755 /usr/bin/checkpatch.pl
1515
```
1616

17-
1817
### Windows
1918

2019
cmd as administrator:
@@ -31,8 +30,9 @@ GNU 'diff' executable should also be available (can be done by installing [git-f
3130
* `checkpatch.checkCommit` Select specific commit to be tested
3231
* `checkpatch.toggleAutoRun` Toggle automatic checkpatch for the current workspace
3332

34-
## settings.json
35-
* `checkpatch.checkpatchPath` path to the checkpatch.pl script
33+
## Settings
34+
* `checkpatch.checkpatchPath` Path to the checkpatch.pl script
3635
* `checkpatch.checkpatchArgs` checkpatch arguments to use
37-
* `checkpatch.run` control whether the linting is automatic on save or manually triggered using the `checkpatch.checkFile` command.
36+
* `checkpatch.run` Control whether the linting is automatic on save or manually triggered using the `checkpatch.checkFile` command.
3837
* `checkpatch.exclude` Glob patterns for excluding files and folders from automatic checks.
38+
* `checkpatch.diagnosticLevel` Diagnostic level of checkpatch errors.

package.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@
5757
"type": "array",
5858
"default": [],
5959
"description": "Glob patterns for excluding files and folders from automatic checks."
60+
},
61+
"checkpatch.diagnosticLevel": {
62+
"type": "string",
63+
"enum": [
64+
"Error",
65+
"Warning",
66+
"Information",
67+
"Hint"
68+
],
69+
"default": "Information",
70+
"description": "Select the diagnostic level of checkpatch problems"
6071
}
6172
}
6273
},

src/checkpatchProvider.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,20 @@ export interface LinterConfig {
99
path: string;
1010
args: string[];
1111
excludeGlobs: string[];
12+
diagnosticSeverity: vscode.DiagnosticSeverity;
1213
}
1314

1415
interface RepoPickItem extends vscode.QuickPickItem {
1516
repo: Repository;
1617
}
1718

19+
const diagSeverityMap = new Map<string, vscode.DiagnosticSeverity>([
20+
['Error', vscode.DiagnosticSeverity.Error],
21+
['Warning', vscode.DiagnosticSeverity.Warning],
22+
['Information', vscode.DiagnosticSeverity.Information],
23+
['Hint', vscode.DiagnosticSeverity.Hint],
24+
]);
25+
1826
export default class CheckpatchProvider implements vscode.CodeActionProvider {
1927
private linterConfig!: LinterConfig;
2028
private documentListener!: vscode.Disposable;
@@ -58,6 +66,7 @@ export default class CheckpatchProvider implements vscode.CodeActionProvider {
5866
path: config.checkpatchPath,
5967
args: config.checkpatchArgs,
6068
excludeGlobs: config.exclude,
69+
diagnosticSeverity: diagSeverityMap.get(config.diagnosticLevel) ?? vscode.DiagnosticSeverity.Information
6170
};
6271

6372
if (this.documentListener) {
@@ -103,8 +112,8 @@ export default class CheckpatchProvider implements vscode.CodeActionProvider {
103112
let fileName = matches[4];
104113
let errorline = parseInt(matches[5]);
105114
let range = new vscode.Range(errorline - 1, 0, errorline - 1, Number.MAX_VALUE);
115+
let diagnostic = new vscode.Diagnostic(range, `${type}:${message}`, this.linterConfig.diagnosticSeverity);
106116

107-
let diagnostic = new vscode.Diagnostic(range, `${type}:${message}`, vscode.DiagnosticSeverity.Information);
108117
diagnostic.code = type;
109118
diagnostic.source = 'checkpatch';
110119

0 commit comments

Comments
 (0)