Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
Add option to disable linting on save
Browse files Browse the repository at this point in the history
  • Loading branch information
notskm committed Dec 7, 2019
1 parent e35b21b commit 3a5baa4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ equivalent to 0.2.0
- Initial release

## [Unreleased]

- Added: `clang-tidy.lintOnSave` option to disable automatic linting on file save
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This extension contributes the following settings:
* `clang-tidy.checks`: List of checks to enable or disable
* `clang-tidy.compilerArgs`: List of arguments to append to the compiler command line
* `clang-tidy.compilerArgsBefore`: List of arguments to prepend to the compiler command line
* `clang-tidy.lintOnSave`: Whether or not to lint files when they are saved

## Extension Commands

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
"type": "array",
"default": [],
"description": "Extra arguments to prepend to the compiler command line"
},
"clang-tidy.lintOnSave": {
"type": "boolean",
"default": true,
"description": "Automatically lint files when they are saved"
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ export function activate(context: vscode.ExtensionContext) {
}
}

subscriptions.push(workspace.onDidSaveTextDocument(lintAndSetDiagnostics));
subscriptions.push(workspace.onDidSaveTextDocument(doc => {
if (workspace.getConfiguration('clang-tidy').get('lintOnSave')) {
lintAndSetDiagnostics(doc);
}
}));
subscriptions.push(workspace.onDidOpenTextDocument(lintAndSetDiagnostics));
subscriptions.push(workspace.onDidCloseTextDocument(doc => diagnosticCollection.delete(doc.uri)));

subscriptions.push(workspace.onDidSaveTextDocument(doc => {
if (doc.uri.scheme === 'file' && doc.uri.fsPath.endsWith('.clang-tidy')) {
workspace.textDocuments.forEach(lintAndSetDiagnostics);
if (workspace.getConfiguration('clang-tidy').get('lintOnSave')) {
if (doc.uri.scheme === 'file' && doc.uri.fsPath.endsWith('.clang-tidy')) {
workspace.textDocuments.forEach(lintAndSetDiagnostics);
}
}
}));

Expand Down

0 comments on commit 3a5baa4

Please sign in to comment.