Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- **Configurable severity threshold**: Filter out messages below a chosen severity level (`info`, `warning`, or `error`).
- **Set C/C++ standard**: Easily specify `--std=<id>` (e.g. `c++17`, `c99`, etc.).
- **Diagnostic cleanup**: When you close a file, its diagnostics are automatically cleared.

- **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.
## Requirements

**Cppcheck** must be installed on your system.
Expand Down
32 changes: 22 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,28 @@ async function runCppcheckOnFileXML(
return arg;
});

const args = [
'--enable=all',
'--xml',
'--xml-version=2',
standardArg,
...extraArgsParsed,
filePath.replace(/\\/g, '/')
].filter(Boolean);

const proc = cp.spawn(commandPath, args);
let proc;
if (extraArgs.includes("--project")) {
const args = [
'--enable=all',
'--xml',
'--xml-version=2',
`--file-filter=${filePath.replace(/\\/g, '/')}`,
standardArg,
...extraArgsParsed
].filter(Boolean);
proc = cp.spawn(commandPath, args);
} else {
const args = [
'--enable=all',
'--xml',
'--xml-version=2',
standardArg,
...extraArgsParsed,
filePath.replace(/\\/g, '/')
].filter(Boolean);
proc = cp.spawn(commandPath, args);
}

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