Hi @BorisT ,
Thanks for the screenshot. That looks correct. Have you tried scanning “Development” branch again yet? After setting it as the main branch, you need to scan “Development” branch once more.
Joe
Hi @BorisT ,
Thanks for the screenshot. That looks correct. Have you tried scanning “Development” branch again yet? After setting it as the main branch, you need to scan “Development” branch once more.
Joe
Hi @Joe ,
Unfortunately, deleting the project, recreating it, setting Development as the main branch and scanning it several times did not resolve the issue.
Is there something else that we can try?
Is there something in configuration files that can cause this issue?
Like in sonar-project.properties or package.json?
Thanks,
Boris.
Hi @BorisT ,
I cannot replicate your issue. Can you give me the exact steps in how you are creating this issue so that I can reproduce it?
Regards,
Joe
Is this happening on all your projects or just one project? Are you able to reproduce the problem with a new project?
Hi @Joe ,
This issue happens only in one of two projects.
As far as I can tell, I’m not doing anything different in terms of SonarQube properties or Jenkins pipeline SonarQube setup…
Please let me know what steps/files/configurations you need me to give you.
Thanks,
Boris.
Hi @BorisT ,
My colleague reminded me of another reason that the “The main branch of this project is empty” message appears: the nloc
measure for the main branch of the project is null or equal to 0.
Can you verify there are actual lines of code in your main branch?
In any case, here are the steps that I used to try to reproduce your issue but failed to replicate your scenario:
Please try my procedure and see if that works for you.
Hi @Joe ,
I checked the line of codes in the project’s Code display and it is indeed Null!
Please refer to the screenshot.
When I took a look at another project, I noticed the same issue.
But, on closer inspection I’ve noticed that *.js
files do have a line code count.
The *.ts
files are ignored.
Since this is a TypeScript project, I don’t understand why the TypeScript files are not counted…
Please refer to the following screenshot.
Is there a setting I’m missing in the sonar-project.properties
file?
Here’s my sonar-project.properties
configuration:
# Project General Settings
sonar.projectKey=server-acme-project
sonar.projectName=server-acme Project
sonar.projectVersion=1.0
sonar.language=ts
sonar.sourceEncoding=UTF-8
# Source File Inclusions/Exclusions
sonar.sources=src
sonar.inclusions=src/**/*.ts
sonar.exclusions=src/**/*.spec.ts, src/**/*mock*.ts, src/**/*Mock*.ts, src/**/*.test.ts, src/**/*.snap, src/docs/**/*, src/recordings/**/*, src/public/**/*
# Test File Inclusions/Exclusions
sonar.tests=src
sonar.test.inclusions=src/**/*.spec.ts, src/**/*.test.ts
sonar.test.exclusions=
# Linter
sonar.ts.tslintconfigpath=.eslintrc.json
sonar.eslint.reportPaths=reports/eslint/js-lint-results.json
# JavaScript/TypeScript Code covarge
sonar.javascript.lcov.reportPaths=reports/jest-coverage/unit/lcov.info,reports/jest-coverage/parser/lcov.info,reports/jest-coverage/integration/lcov.info
sonar.testExecutionReportPaths=reports/jestSonar-unit-test-reporter.xml
Thanks,
Boris.
Hi @BorisT !
Thanks for confirming the null issue, now that makes sense.
Regarding your other TS project, You should remove the sonar.language=ts
parameter since that is not necessary, our scanner will detect the proper language by itself.
Note that your sonar.inclusions
says src/**/*.ts
, that means only .ts files in the src directory (“Patterns used to include some source files and only these ones in analysis.”). Is that your intent? You are showing the workers
folder, which seems to be excluded.
Can you paste the contents of one of those files or take a screenshot and show what SonarQube UI shows when you click on, say, reportWorker.ts
?
Hi @Joe,
I’ve removed the sonar.language=ts
, but it didn’t change the nloc
measure. It is still null for TypeScript.
Yes, we only interested in *.ts
files to be scanned (plus one single *.js file)
The screenshot with the workers
folder is from another project (with the same issue).
The sonar-project.properties
file for this project looks like this:
# Project General Settings
sonar.projectKey=bbat-project
sonar.projectName=acme-bitcoin-algo-tech
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
# Source File Inclusions/Exclusions
sonar.sources=src, DAL, remote, service, userMovements, workers
sonar.inclusions=src/**/*.ts, DAL/**/*.ts, models/**/*.ts, DAL/**/*.ts, remote/**/*.ts, service/**/*.ts, userMovements/**/*.ts, workers/**/*.ts, workers/**/*.js
sonar.exclusions=src/**/*.spec.ts, src/**/*mock*.ts, src/**/*Mock*.ts, src/**/*.test.ts, src/**/*.snap, src/docs/**/*, src/recordings/**/*, src/public/**/*
# Test File Inclusions/Exclusions
sonar.test.inclusions=**/*.spec.ts, **/*.test.ts
sonar.test.exclusions=dist, node_modules, .husky, .vscode, config, diagrams, helm,
# Linter
sonar.ts.tslintconfigpath=.eslintrc.json
sonar.eslint.reportPaths=reports/eslint/js-lint-results.json
# JavaScript/TypeScript Code covarge
sonar.javascript.lcov.reportPaths=reports/jest-coverage/unit/lcov.info
sonar.testExecutionReportPaths=reports/jestSonar-unit-test-reporter.xml
The content of reportWorker.ts
:
import { mongoDbConnections } from '../mongo-db-connections.service';
import { isMainThread, parentPort } from 'worker_threads';
import { Message } from '../service/pubsub/models/message/message';
import { BBAT } from '../src/BBAT';
import { UserMovementsMapperAndSaver } from '../userMovements/userMovements.service';
import { TimeService } from '../service/time/time.service';
import { ReportWorkerResponse } from './reportWorkerResponse';
import { concatMap, last } from 'rxjs/operators';
import { reject } from 'lodash';
import { Country, TaxMethodTypes } from '../models/bbatReportSummary.model';
const pubsubBBATSubtopicName = 'Start';
async function bbatReportCreation(userId: string) {
const userMovementsMapperAndSaver = new UserMovementsMapperAndSaver(userId);
const startTime: number = TimeService.toMillisecondsTimeStamp();
const movementsCount = await userMovementsMapperAndSaver.saveMovementsInChunks();
console.log(`===================== number of movements: ${movementsCount} ================`);
console.log(`======================= for user ${userId} ==========================`);
const bbat = new BBAT(
userId,
movementsCount,
[TaxMethodTypes.FIFO, TaxMethodTypes.FIFO_EXCHANGES, TaxMethodTypes.FIFO_TECH],
Country.ISR,
false
);
const diff = TimeService.differentInMillisecondsByTimeStamps(startTime);
console.log(`Fetch and convert movements in ${TimeService.toFormat(diff, 'HH:mm:ss.SSS')}`);
let deferredResolve: (value: void | PromiseLike<void>) => void;
const promise = new Promise<void>((resolve, reject) => {
deferredResolve = resolve;
});
(await bbat.createStock())
.pipe(
last(),
concatMap(_ => bbat.createReport())
)
.subscribe({
complete: () => {
console.log('Finished calculation job on report worker!');
deferredResolve();
},
error: err => {
reject(err);
}
});
return promise;
}
async function connect() {
const promiseBbatConnection = mongoDbConnections.getBbatDbConnection();
const promiseAcmeConnection = mongoDbConnections.getAcmeDbConnection();
return await Promise.all([promiseBbatConnection, promiseAcmeConnection]);
}
async function setupWorker() {
console.log('Loading BBAT report worker...');
if (!isMainThread) {
try {
await connect();
} catch (error) {
console.log(`Failed to initiate MongoDB connection for BBAT - ${error.message}`);
throw error;
}
parentPort.on('message', async (message: Message) => {
if (message.subTopic === pubsubBBATSubtopicName) {
try {
await bbatReportCreation(message.payload.userId);
parentPort.postMessage({ success: true, data: { message: message } } as ReportWorkerResponse);
} catch (error) {
parentPort.postMessage({
success: false,
data: { errorMessage: error.message, pubsubMessage: message }
} as ReportWorkerResponse);
}
} else {
console.warn(`Received unknown message with subtopic ${message.subTopic}. Ignoring.`);
}
});
}
}
void setupWorker();
Thanks,
Boris.
Hi @BorisT ,
Apologies for the delay. Here are my observations:
sonar.ts.tslintconfigpath=.eslintrc.json
is not a valid analysis parameter, does this work? You can delete this parameter.reportWorker.ts
file reveals that all looks fine. My suggestion, based on your slightly complex sonar.source, inclusions, exclusions settings, is to start from a blank slate and slowly add the following analysis scopes in this order:
Ideally, you shouldn’t have to define such detailed analysis scope. Usually, sonar.exclusions should be enough. On rare occasions will you need to use sonar.inclusions.
Please try adding each parameter and its values slowly, one by one to deconstruct and hopefully reproduce the issue.
Joe
@Joe I’m having this problem with a project that was working fine and that now displays “The main branch of this project is empty” and has characteristics similar to what @BorisT describes. Except that we dont have any inclusions, just exclusions. I dont know when this started displaying that message but it was recent, within the last few weeks.
Ours is a node v12.16.1 project (we have work in progress to bring it up to v16 but thats not happening for a few days or weeks.).
Hi @StingyJack ,
I suggest creating a new thread so they’ll be a greater audience to see your issue.
Have you reviewed this thread yet? There are several things to check here:
If you still need an explanation for your issue, can you attach your DEBUG Sonar scanner analysis logs in the new thread so we can inspect it?
This is the thread that most closely matches the problem I am seeing. I will have to figure out how to get the DEBUG sonar logs. This may require help from another team in my org.
It took me a long time to figure this out, but this was in the build information:
WARN: SonarScanner for .NET detected only TEST files and no MAIN files for C# in the current solution. Only TEST-code related results will be imported to your SonarQube/SonarCloud project. Many of our rules (e.g. vulnerabilities) are raised only on MAIN-code. Read more about how the SonarScanner for .NET detects test projects: https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects
The solution was to add this to the non-test csproj files:
<PropertyGroup>
<!-- Project is not a test project -->
<SonarQubeTestProject>false</SonarQubeTestProject>
</PropertyGroup>
I also marked the test projects csproj files with
<PropertyGroup>
<!-- Project is a test project -->
<SonarQubeTestProject>true</SonarQubeTestProject>
</PropertyGroup>
And this was found in our build logs recently…
ERROR: Only Node.js v12.22 or later is supported, got 12.16.1.
org.sonarsource.nodejs.NodeCommandException: Only Node.js v12.22 or later is supported, got 12.16.1.
at org.sonarsource.nodejs.NodeCommandBuilderImpl.checkNodeCompatibility(NodeCommandBuilderImpl.java:172)
at org.sonarsource.nodejs.NodeCommandBuilderImpl.build(NodeCommandBuilderImpl.java:143)
at org.sonar.plugins.javascript.eslint.EslintBridgeServerImpl.initNodeCommand(EslintBridgeServerImpl.java:183)
at org.sonar.plugins.javascript.eslint.EslintBridgeServerImpl.startServer(EslintBridgeServerImpl.java:128)
at org.sonar.plugins.javascript.eslint.EslintBridgeServerImpl.startServerLazily(EslintBridgeServerImpl.java:212)
All of the sonarcloud facilities seem to be working: coverage, duplication, issues, sec hotspots. I can browse the code files in sonarcloud but it just shows 0 lines.
updating to node v 16 did fix this.
Hi @StingyJack ,
Thanks for coming back to us .
@BorisT Did you try updating your version of NodeJS? Did that solve the problem?
Hi @Wouter_Admiraal,
I no longer work on this project (the last time I touched it was a long time ago…).
I don’t remember if I update NodeJS version, or not, at the time…
Sorry I couldn’t be more helpful
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.