I want to disable a SonarQube rule for multiple files at different paths. Also I want to make this configuration within the pom.xml and to through the Sonar UI.
I couldn't find any clue on how to do this. My best guess is that I have to create multiple rules:
<sonar.issue.ignore.multicriteria>e1,e2</sonar.issue.ignore.multicriteria>
<!-- disable rule on naming convention -->
<sonar.issue.ignore.multicriteria.e1.ruleKey>
java:S117
</sonar.issue.ignore.multicriteria.e1.ruleKey>
<sonar.issue.ignore.multicriteria.e1.resourceKey>
firstPath
</sonar.issue.ignore.multicriteria.e1.resourceKey>
<sonar.issue.ignore.multicriteria.e2.ruleKey>
java:S117
</sonar.issue.ignore.multicriteria.e2.ruleKey>
<sonar.issue.ignore.multicriteria.e2.resourceKey>
secondPath
</sonar.issue.ignore.multicriteria.e2.resourceKey>
I was wondering if there was a more compact way to do this. I was thinking of something like this:
<sonar.issue.ignore.multicriteria>e1</sonar.issue.ignore.multicriteria>
<!-- disable rule on naming convention -->
<sonar.issue.ignore.multicriteria.e1.ruleKey>
java:S117
</sonar.issue.ignore.multicriteria.e1.ruleKey>
<sonar.issue.ignore.multicriteria.e1.resourceKey>
firstPath, secondPath
</sonar.issue.ignore.multicriteria.e1.resourceKey>
However I have no idea if this syntax will be accepted or not. I guess I should try it, but I'd rather not since in order to test it I would need to push the change to my CI server.
This seems not to be supported according to config in answer https://stackoverflow.com/a/63632140/7251133
I agree it would be really nice when lists would be allowed in rule and resource.
Related
We have the requirement, that we shall host an SAPUI5 application inside a java-application's host, which our vendor offered to us by implementing and exposing jxbrowser.
This vendor's java application offers an api, which can be accessed from within our SAPUI5 application.
This java api offers also an environment (or config-settings), where, amongst a rich set of settings, also a user language can be obtained.
And this language is neither a sap-logon language param nor is it guaranteed to be always the language which is set up in the "jx-browser" ( if possible at all, like in all real browsers ), and it uses the standard i18n _xy_AB acronym's naming style.
And I want to load the proper i18n_xy.properties at onInit of my first view and set them in the code.
We do have currently 4 of them ( _de,_it,_fr ), and the fallback is also present.
I am a little idiot, because I found some quick n dirty code, but this was about one month ago and I simply forgot the link and all of that. So now I need to ask( and maybe even for a best practice solution to this...)
So, additionally, another (my personal) requirement is, that, once I retrieve the right i18n file, I want to set it, in a way, that, whenever later on, I would use
info = this.getView().getModel("i18n").getResourceBundle().getText("obfuscated");
I always obtain the right text in the right language.
What I think of, is: Load the proper file ( according to the environment settings from the api ) in onInit, set this i18n as the proper one for the rest of the application's runtime and use a easy name for it, which will then be referred to as, maybe this:
info = this.getView().getModel("i18n_loaded").getResourceBundle().getText("obfuscated");
Is this possible, is this the right way, and , if not, which one is, according to some kind of guidelines, the best practice for this scenario ?
You can pass the parameter in the url:
sap-ui-language=en
Or set the default language in your JavaScript code:
sap.ui.getCore().getConfiguration().setLanguage("en-US");
I was not completely aware, that the determination of the used locale also works the other way around.
Meaning, if the ressource bundle contains e.g. 4 i18's,called i18_en, i18_it, i18_de, i18_fr, and the either the app is set up by
sap.ui.getCore().getConfiguration().setLanguage("en-US");
or the url-param, this not only means, that:
All ui-elements will be translated propery, once the locale's acronym is properly spotted
ALSO this is automatically replaced by the proper spotted ressource file and the translated text is retrieved properly....
info = this.getView().getModel("i18n").getResourceBundle().getText("obfuscated");
I was aware of how this fallback determination of a locale works, but I was not aware that it works also the other way around.
I close my question and i do not care about any rewards.
In my eslint config (YAML format), I'm extending 3 different configurations:
extends:
- airbnb-base
- plugin:angular/johnpapa
- ionic
My questions are as follows:
Is this the correct format in YAML?
Some of these extensions have overlapping rules (or multiple of them extend eslint:recommended): will I get the same error multiple times if the error is related to one of these "shared" rules?
At first, Yes, it's the correct format in YAML (see for example ESLint - Configuring Plugins). As JSON, it would be
{
"extends": [
"airbnb-base",
"plugin:angular/johnpapa",
"ionic"
]
}
If you have multiple rulesets in your extend section, each following ruleset will extend or overwrite the previous ones. So you will only have one setting for each rule (see ESLint - Extending Configuration Files) Sometimes when the rules from the shareable configs are conflicting and you can't define a specific order for the extend section you have to manually define this specific rule in you rules section.
So the answer to you second question is: No, you won't get the same error multiple times.
The correct way to extend eslint rules is like so:
extends: ["standard", "plugin:jest/recommended"]
I'm working with a component bitrix:catalog (which is standard one) and faced an issue. I want to add some extra GET parameters to switch view mode. I think there is no need to rewrite whole component to make such switcher, so I added extra keys in result_modifier in a way similar to:
$this->__component->arResultCacheKeys = array_merge($this->__component->arResultCacheKeys, array('key1', "key2"));
Earlier in the same result_modifier I perform adding those extra keys in $arResult['key1'] etc. They seem to be correctly saved, but only for current inquiry such as ?view=list or view=card, that means only one variable value is saved and it does not react on changing of GET parameter. Is there simple and correct way to make that component to cache and to output data based on GET variable? The only idea which came to my mind is to rewrite component by adding extra parameter and checking of GET, but I think there must more simple and correct solution to make in via template. Human Readable Links are turned on. And I want to have auto-cash being turned on as well. If I turn it off it starts working as planned.
One of possible solutions is to rewrite it cache by SetTemplateCachedData but it still seems to me rough and incorrect way for such simple task.
Bitrix masters please help me to find correct solution, google can't help at the moment.
If you use standard bitrix:catalog component, you may be use standart bitrix:catalog.section. In that component.php used standart component cache.
That means you can describe additional parametr in you custom .parameters.php, and set it in bitrix:catalog.section params.
Standart component cache set cacheId based on arParams.
So you include component should look like this:
$APPLICATION->IncludeComponent(
"bitrix:catalog.section",
"",
array(
"IBLOCK_TYPE" => $arParams["IBLOCK_TYPE"],
"IBLOCK_ID" => $arParams["IBLOCK_ID"],
"ELEMENT_SORT_FIELD" => $arParams["ELEMENT_SORT_FIELD"],
"ELEMENT_SORT_ORDER" => $arParams["ELEMENT_SORT_ORDER"],
....
....
"NEW_ADDITIONAL_GET_PARAMS"=> $_GET['view']
),
$component
);
Of course better way somethink like
"NEW_ADDITIONAL_GET_PARAMS"=> (in_array($_GET['view'],array('list','card'))?$_GET['view']:'list')
But may be you need just set right catalog params: SEF_MODE SEF_FOLDER SEF_URL_TEMPLATES
I've got a project I'm working on and some of the files violate some of the rules, but in ways that are not real issues, and are thus distracting noise. However, I don't want to disable these rules globally, and I would prefer not to have to mark 'em as false positives one by one.
Is there a way to disable Sonar rules for specific files, and if so, how?
Since SonarQube 4.0, you can define issue exclusion patterns based on rule key and file path pattern.
On previous versions, you can rely upon the Switch Off Violations plugin.
You can annotate a class or a method with SuppressWarnings.
Here is an example:
#java.lang.SuppressWarnings("squid:S00111")
squid:S00111 in this case is a Sonar issue ID. You can find this issue id from the Sonar web ui.
Building on Mithfindel's answer and dpk's comment, this removes the warning
System.out and System.err should not be used as loggers
from all classes in packages named log (or any subpackage thereof) by adding an ignore pattern for the rule squid:S106:
For a list of the keys to all your rules go to your profile under Quality Profiles and select Download to get a .csv file containing all the rules' keys.
I'm using SonarQube version 4.1.1.
You can set specific files and rules under sonar-project.properties with following contents:
# Ignore Issues
sonar.issue.ignore.multicriteria=e1,e2
# Skip Bold Check
sonar.issue.ignore.multicriteria.e1.ruleKey=Web:BoldCheck
sonar.issue.ignore.multicriteria.e1.resourceKey=**/*.html
# Skip Tag Check
sonar.issue.ignore.multicriteria.e2.ruleKey=Web:S1234
sonar.issue.ignore.multicriteria.e2.resourceKey=**/*.html
Change the ruleKey and resourceKey based on your specific need.
Using below annotation we can ignore the rule from the specific files
For one rule
#java.lang.SuppressWarnings("squid:S2696")
#Slf4j
#Service
public class PaymentServiceImpl implements PaymentService {....
For more than one rule
#java.lang.SuppressWarnings({"squid:S2696", "squid:S1172", "squid:CommentedOutCodeLine"})
#Slf4j
#Service
public class PaymentServiceImpl implements PaymentService {...
Yes, it is possible.
1.Goto Administration tab->Analysis Scope->Issues
2.There , you will find "Ignore Issues on Multiple Criteria".
3.Provide Rule ID in "Rule Key pattern" textbox [Rule ID can be found by clicking on the particular rule and find it in top right corner]
4.Provide Filepath for which you need to ignore rule in "File Path Pattern" textbox
5.Click on Save Issues settings
Image to know where Rule ID will be present in the page
Image where Rule key pattern and File Key pattern text boxes are present
I know this doesn't exactly match the form of www.example.com/class/function/ID/, but what I want to display to the user would make more sense.
This is what I would like to do:
www.example.com/project/id/item/item_id/
So, an example would be:
www.example.com/project/5/item/198237/
And this would be the behavior:
www.example.com/project/ --> This would show a list of projects (current implementation)
www.example.com/project/5/ --> This would show a list of items on project 5 (current implementation)
www.example.com/project/5/item/ --> This wouldn't really mean anything different than the line above. (Is that bad?)
www.example.com/project/5/item/198237/ --> This would show details for item 198237.
So, each item is directly associated with one and only one project.
The only way I can think how to do this is to bloat the "project" controller and parse the various parameters and control ALL views from that "project" controller. I'd prefer not to do this, because the model and view for an "item" are truly separate from the model and view of a "project."
The only other solution (that I am currently implementing and don't prefer) is to have the following:
www.example.com/project/5/
www.example.com/item/198237/
Is there any way to build a hierarchical URL as I showed at the beginning without bloating the "project" controller?
There are 3 options, sorted by how practical they can be:
Use URI Routing. Define a regular expression that will use a specific controller/method combination for each URL.
Something like that could help you, in routes.php:
$route['project/'] = 'project/viewall';
$route['project/(.+)'] = 'project/view/$1';
$route['project/(.+)/item/'] = 'project/view/$1';
$route['project/(.+)/item/(.+)'] = 'item/view/$2';
That is, considering your controllers are item and project respectively. Also note that $n in the value corresponds to the part matched in the n-th parenthesis.
Use the same controller with (or without) redirection. I guess you already considered this.
Use redirection at a lower level, such as ModRewrite on Apache servers. You could come up with a rule similar to the one in routes.php. If you are already using such a method, it wouldn't be a bad idea to use that, but only if you are already using such a thing, and preferably, in the case of Apache, in the server configuration rather than an .htaccess file.
You can control all of these options using routes.php (found in the config folder). You can alternatively catch any of your URI segments using the URI class, as in $this->uri->segment(2). That is if you have the URL helper loaded. That you can load by default in the autoload.php file (also in the config folder).