I am writing an automatic repair system for some specific sonarqube bugs using INRIA's spoon. I want to write Junit tests for my repair system to check whether the bug has been repaired. I want to do something like this :
X = file;
Y = repair(X);
assert(! hasSonarqubeBug(Y));
Sonarqube analysis is only available for complete projects and not individual files. Sonarlint does analyse individual files but I don't know if there is a way to write a test like this with sonarlint.
With the Web api you're able to retrieve issues for any kind of component (files included) in Sonarqube. From the web api documentation (http(s)://sonarhost:9000//web_api/api/issues) for
GET api/issues/search parameters componentKeys:
-- Edit after comment --
To get possible new issues after changing the source code, you'll need a build and a code scan by a Sonarqube scanner. Beside Sonarlint IDE plugin, there's no local preview analysis (sonar.analysis.mode=preview for scanners is deprecated and will vanish soon).
Maybe there's some kind of hack with f.e. headless Eclipse and Sonarlint plugin (assuming you use Eclipse, don't know of headless with other IDEs) !?
You may also use the Sonarlint CLI which is not longer developed or supported, but it's still available here, though it might not work with newer Sonarqube versions.
TL;DR
It depends on your Sonarqube version, when using:
SQ 5.6.x, you may use a scanner with sonar.analysis.mode=preview, this will not publish the results to SQ Server.
SQ 6.x and later, you may try whether Sonarlint CLI still works or try with headless Eclipse. Otherwise you have to run your unitests in Eclipse and check with Sonarlint plugin.