Hi everybody, I want to ignore specific blocks in my code, is it possible to achieve this?
this is my current configuration at my .properties file:
sonar.projectKey=cuentame-v21234-backend
sonar.organization=cuentame12345test
sonar.host.url=https://sonarcloud.io
# Nombre y versión del proyecto mostrados en la UI de SonarCloud
sonar.projectName=Test Backend
#sonar.projectVersion=1.0
# Ruta relativa al archivo sonar-project.properties. Reemplaza "\" por "/" en Windows.
sonar.sources=.
# Directorios de pruebas
# sonar.tests=src/controllers/test,src/models/test,src/helpers/test,src/utils/test
# Cobertura de código
sonar.javascript.lcov.reportPaths=coverage/lcov.info
# Exclusiones: directorios y archivos a excluir del análisis
sonar.exclusions=node_modules/**,build/**,dist/**,coverage/**,logs/**,docs/**,src/config/**, src/middleware/**, src/constants/**, src/interceptors/**, src/controllers/**, src/schemas/**, src/models/translations/**, src/models/roles/**, src/cron/**, src/routes/**
# Inclusiones opcionales para archivos de prueba
# Esto asegura que solo los archivos de prueba relevantes sean analizados
sonar.test.inclusions=**/*.test.ts,**/*.spec.ts
# Ignorar bloques específicos de código en src/models/clientRHSection.ts
sonar.issue.ignore.block=block1
sonar.issue.ignore.block.block1.filePattern=src/models/**
sonar.issue.ignore.block.block1.beginBlockRegexp=.*//\s*sonar-ignore-start.*
sonar.issue.ignore.block.block1.endBlockRegexp=.*//\s*sonar-ignore-end.*
I even add the regex at the project console…
this is the code I’m testing to ignore…
// sonar-ignore-start
ClientDashboard.addHook('beforeCreate', async (instance: ClientDashboard | any) => {
// Client validation
const hasClient: any = await Client.findByPk(instance.clientId, { attributes: ['idClient'] });
// Evaluate wheater there´s an error to handle
let errorResponse = handlerErrorResponse(hasClient, 600, 404);
// If an error exist's
if (errorResponse.status !== 200) {
errorResponse.details = 'Client not found';
throw errorResponse;
}
// Dashboard type validation
const hasDashboardType: any = await DashboardType.findByPk(instance.dashboardTypeId, { attributes: ['idDashboardType'] });
// Evaluate wheater there´s an error to handle
let errorResponseDashboardType = handlerErrorResponse(hasDashboardType, 610, 404);
// If an error exist's
if (errorResponseDashboardType.status !== 200) {
errorResponseDashboardType.details = 'Dashboard type not found';
throw errorResponseDashboardType;
}
});
// sonar-ignore-end
And always appears as if it’s uncovered