Skip to content

Commit 970e407

Browse files
authored
feature #6: support for project file (#14)
* feature #6: support for project file * updated readme
1 parent a82ab00 commit 970e407

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- **Configurable severity threshold**: Filter out messages below a chosen severity level (`info`, `warning`, or `error`).
1010
- **Set C/C++ standard**: Easily specify `--std=<id>` (e.g. `c++17`, `c99`, etc.).
1111
- **Diagnostic cleanup**: When you close a file, its diagnostics are automatically cleared.
12-
12+
- **Project file support**: You can feed your project file to cppcheck through the `--project` flag in the `cppcheck-official.arguments` field in the extension settings.
1313
## Requirements
1414

1515
**Cppcheck** must be installed on your system.

src/extension.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,28 @@ async function runCppcheckOnFileXML(
192192
return arg;
193193
});
194194

195-
const args = [
196-
'--enable=all',
197-
'--xml',
198-
'--xml-version=2',
199-
standardArg,
200-
...extraArgsParsed,
201-
filePath.replace(/\\/g, '/')
202-
].filter(Boolean);
203-
204-
const proc = cp.spawn(commandPath, args);
195+
let proc;
196+
if (extraArgs.includes("--project")) {
197+
const args = [
198+
'--enable=all',
199+
'--xml',
200+
'--xml-version=2',
201+
`--file-filter=${filePath.replace(/\\/g, '/')}`,
202+
standardArg,
203+
...extraArgsParsed
204+
].filter(Boolean);
205+
proc = cp.spawn(commandPath, args);
206+
} else {
207+
const args = [
208+
'--enable=all',
209+
'--xml',
210+
'--xml-version=2',
211+
standardArg,
212+
...extraArgsParsed,
213+
filePath.replace(/\\/g, '/')
214+
].filter(Boolean);
215+
proc = cp.spawn(commandPath, args);
216+
}
205217

206218
// if spawn fails (e.g. ENOENT or permission denied)
207219
proc.on("error", (err) => {

0 commit comments

Comments
 (0)