Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve "Add or update the header of this file." code smell in SonarQube?

Tags:

sonarqube

I have even tried "Compliant Solution" given :

/*
 * SonarQube, open source software quality management tool.
 * Copyright (C) 2008-2013 SonarSource
 * mailto:contact AT sonarsource DOT com
 *
 * SonarQube is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * SonarQube is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

but it's not fixing the code smell. Can you please give me the working SIMPLEST EXAMPLE which can solve this?

like image 602
Giovanno Avatar asked Apr 13 '18 08:04

Giovanno


People also ask

What is Sonarqube code smell?

Code Smell. A maintainability-related issue in the code. Leaving it as-is means that at best maintainers will have a harder time than they should making changes to the code. At worst, they'll be so confused by the state of the code that they'll introduce additional errors as they make changes.


2 Answers

This rule will have been configured with the expected header when it was added to the profile being applied to your project. You should check not the "Compliant Solution" but that configuration to see what's expected.

Note that the header can be configured as a regex. Typically this is used to deal with copyright year variations, but you should double check whether it's being used as a regex as well.

like image 181
G. Ann - SonarSource Team Avatar answered Nov 13 '22 03:11

G. Ann - SonarSource Team


Check your project settings for the header format configured for the Rule: Track lack of copyright and license headers (java:S1451)

If this is empty/blank, then insert a blank at the beginning of every file, which will resolve this issue.

If you are using SonarLint as a plugin you can find this setting under Window --> Preferences --> SonarLint --> Java --> Track lack of copyright and license headers

SonaLint configuration for eclipse plugin

PS: If you don't wanna do this and not a cup of your tea, simply disable this rule.

like image 1
Irshad Avatar answered Nov 13 '22 03:11

Irshad