Skip to content
| Marketplace
Sign in
Visual Studio Code>Linters>ForeshockNew to Visual Studio Code? Get it now.
Foreshock

Foreshock

Preview

Mustafa YÜCELER

|
2 installs
| (0) | Free
Before you open a pull request: builds your .NET solution without restore, sends a SonarQube pull request analysis of your branch and lists its code smells; or runs your tests with coverage and checks the quality gate.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Foreshock for VS Code

Preview. Source: github.com/myclr08/foreshock. Install from the VS Code Marketplace (myclr08.foreshock) or download the VSIX from the GitHub releases (Extensions view > ... > Install from VSIX...).

See what SonarQube will say about your pull request before you open it.

Foreshock is for .NET teams that use SonarQube Server Developer Edition or higher. From VS Code it:

  1. Analyze Changes (Code Smells): builds your solution without restore, sends a SonarQube pull request analysis of your branch (compared with master) and lists the code smells of your changes.
  2. Run Tests & Check Quality Gate: also runs your unit tests with coverage, sends the coverage with the analysis and shows whether the quality gate passes, condition by condition (for example Coverage on New Code 62.5%, required ≥ 80.0%). After the first run only what changed runs again (see Incremental coverage).

You enter the server URL and a personal token once.

Install

  1. Download foreshock-<version>.vsix from the releases.
  2. VS Code: Extensions view → … menu → Install from VSIX…, or code --install-extension foreshock-<version>.vsix.

Connect once

Run Foreshock: Connect to SonarQube (or click Connect in the Foreshock view):

  1. the server URL, the address you open SonarQube with;
  2. a user token: in SonarQube, My Account → Security → Generate Tokens, type User Token.

Foreshock checks both (api/server/version, api/system/status, api/authentication/validate), stores the URL in your user settings (foreshock.serverUrl) and the token in the operating system keychain (VS Code SecretStorage), never in a settings file. Run the command again to change them, Foreshock: Disconnect (Forget Token) to remove the token.

The project key is taken from foreshock.projectKey, else from sonar-project.properties, an Azure Pipelines SonarQubePrepare task (projectKey:) or a sonarscanner begin /k: line in your CI files; otherwise Foreshock asks once per solution and lets you search the server. Foreshock: Select SonarQube Project changes it.

Use

Open the Foreshock view in the activity bar and click one of the two buttons, or run the commands from the Command Palette.

  • Analyze Changes (Code Smells): begin → dotnet build --no-restore → end → wait for the server → code smells.
  • Run Tests & Check Quality Gate: begin → build → dotnet test --no-build with coverage → end → wait → quality gate, coverage numbers and code smells.

Results:

  • The Foreshock view: last run (branch, base, pull request key, server, duration, tests), Quality Gate (every condition with actual and required value), Code Smells grouped by file (rule, severity, message; click to open the file at the line), Open in SonarQube.
  • Problems panel: one entry per code smell, source Foreshock; the rule links to the issue on the server. Cleared when a new run starts.
  • Status bar: the running step (click to cancel), then Gate passed / failed · N code smells (· incremental when only part of the tests ran).
  • Output → Foreshock: every step with its duration, the exact commands (token masked), every HTTP call, the scanner output.

Only one run at a time; Cancel stops the whole process tree (on Windows with taskkill /T /F). Unsaved files are saved first.

The two commands share one analysis

Both commands analyze the same pull request on the server (foreshock-<branch>), so the later run replaces the earlier one. Analyze Changes sends no coverage, so it does not show a quality gate (it would fail on coverage only): the view says not evaluated: run tests to check the gate. The gate of your last test run stays visible, marked stale once a later Analyze Changes replaced it on the server.

Incremental coverage

Typical loop: the gate fails on coverage, you add a few tests, you run again. With foreshock.coverage.incremental on (the default), the second run executes only your new tests, yet SonarQube still receives the complete coverage. Every analysis of a pull request replaces the previous one, so Foreshock always sends the reports of the projects it did not run (from its cache) together with the fresh ones.

What runs when, per test project:

Since the last run What runs
Nothing it depends on changed nothing: its cached coverage is reused
Only new tests were added (new test methods or classes; existing code untouched) only the new tests (dotnet test --filter)
Production code, a project file, test data, or an existing test changed; a test was deleted the whole project
A new test project the whole project
Build/test settings, coverage tool, .NET SDK, Directory.Build.*, global.json, NuGet.config or the solution changed everything (full run)

The first run (no cache yet) is a full run. Foreshock: Run All Tests & Check Quality Gate always runs everything (and refills the cache); Foreshock: Clear Coverage Cache deletes the cache. The view's last run shows Test run: incremental — 1 project ran (3 new tests), 1 reused, with each project's action and the reason; the output lists the whole plan.

Why the result is exact. Coverage is a union: a line is covered when any test covers it. Adding independent tests can only add covered lines; existing tests and the code they run are unchanged, so their cached coverage is still right. Foreshock hashes every file each test project depends on (its project references, transitively) and compares changed test files token by token, so anything other than a pure addition (an edited test body, a new field or constructor, a changed setup method, a new attribute with wider effect) runs the whole project. Cached reports are also checked against the source files they cover. When in doubt, it runs more, never less.

Limits. The shortcut assumes tests are independent and deterministic. Tests that share state (static fields, shared fixtures, a database), depend on time, randomness, the network or files outside the projects, or enumerate the test assembly by reflection can cover different lines in a full run; use Run All Tests when that matters. Projects loaded by path or reflection rather than ProjectReference are not tracked, and floating NuGet versions (1.*) can change without any file changing (pin them or use a lock file). Incremental mode needs coverlet; with dotnet-coverage every run is a full run. Test projects in Microsoft.Testing.Platform mode rerun whole instead of running only new tests. The cache is per machine and checkout.

The cache is in .foreshock/ next to the solution, with a .gitignore inside so git ignores it. One run uses it at a time; a second VS Code window waits with an explanation. With a pull request analysis nothing changes on the server side: only which tests run locally and which report files the scanner gets. The full rules: docs/incremental-coverage.md.

What counts as your change

SonarQube analyzes the files your branch commits changed compared with the base branch. Uncommitted edits count only inside those files; untracked files and edits to other files are not part of the pull request. Foreshock lists such files and asks before it continues: commit them first (no push needed). It also warns when your local master is behind origin/master (the scanner uses the local one) and on shallow clones.

When something fails

Errors say what to do and offer a button: connect again (expired token), install the scanner, run dotnet restore once (Foreshock never restores), fetch the base branch, select the project. Foreshock: Copy Diagnostic Log copies the log with the token removed; the second option also replaces the server address, project and pull request keys, branch names, local paths, project and test names and your user name, so you can share it outside your company.

Requirements

  • SonarQube Server Developer Edition or higher (pull request analysis), 9.9 LTA or newer; primary target 2026.1. Community Build / Community Edition is refused with an explanation.
  • A user token with Browse and Execute Analysis on the project. A Global Analysis Token cannot read results.
  • .NET SDK (dotnet on PATH or foreshock.dotnetPath), git, packages restored once (dotnet restore).
  • SonarScanner for .NET as a dotnet tool: dotnet tool install --global dotnet-sonarscanner (Foreshock: Install SonarScanner for .NET does it). Where NuGet is blocked, download the scanner zip (.NET version), unzip it and set foreshock.scannerPath to the folder.
  • Java: provided by the server (10.6+ with SonarScanner for .NET 7+) unless an administrator turned that off; otherwise Java 17+ in JAVA_HOME or sonar.scanner.javaExePath.
  • Coverage: coverlet.collector in the test projects, or the dotnet-coverage tool.
  • A solution file (.sln or .slnx); with several, Foreshock asks once.

Settings

Setting Default
foreshock.serverUrl Set by Connect to SonarQube.
foreshock.projectKey Project key; empty: detected or asked once.
foreshock.baseBranch master sonar.pullrequest.base; must exist locally or as origin/<name>.
foreshock.pullRequestKey Empty: foreshock-<branch> (never collides with CI's numeric keys).
foreshock.solution .sln/.slnx to build; empty: the only one, or asked once.
foreshock.dotnetPath dotnet The dotnet executable.
foreshock.scannerPath Scanner folder, SonarScanner.MSBuild.dll or .exe when it is not a dotnet tool.
foreshock.coverageTool auto auto, coverlet, dotnet-coverage or none.
foreshock.testArguments [] Extra dotnet test arguments (--settings x.runsettings, --filter ...).
foreshock.buildArguments [] Extra dotnet build arguments (-c Release is repeated for the tests).
foreshock.scannerProperties {} Extra /d: analysis properties (sonar.exclusions, ...).
foreshock.tokenTransport environment environment (SONARQUBE_SCANNER_PARAMS) or argument (/d:sonar.token=, masked).
foreshock.analysisTimeoutSeconds 600 How long to wait for the server to process the analysis.
foreshock.keepScannerFiles false Keep .sonarqube/ after a run (it instruments later builds while it exists).
foreshock.coverage.incremental true Run only what changed and reuse cached coverage (Incremental coverage).

Limits

  • Each branch has one pull request analysis on the server, visible to others in the project's pull request list and removed by the server after its inactivity period.
  • If the SonarQube project is bound to a DevOps platform, the server may record a decoration warning for the Foreshock pull request (it does not exist there).
  • Test projects on Microsoft.Testing.Platform need a coverage tool that supports it.
  • At most 1000 code smells are listed (the total is shown).

Privacy

Foreshock talks only to your SonarQube server and runs dotnet and git locally. No telemetry.


Foreshock is not affiliated with or endorsed by SonarSource. SonarQube and SonarScanner are trademarks of SonarSource SA. MIT license.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft