how to specify code lines to exclude them from Codacy analysis - annotations

Codacy analysis on git project
I had to exclude a few code lines from codacy analysis
Ho I can do it?
is Codacy has own anotations?(e.g. #SkipLine)
//need crutch for codacy analysis

Currently, codacy do not have annotations to skip lines, but the linters that codacy runs to analyse the code, if they support annotations to ignore lines, you can use it and they will be ignored during the analysis. For example, Codacy runs eslint behind the scenes, so if you wish to ignore some specific pattern in a specific line you can do it like this:
const res = eval('42'); // eslint-disable-line no-eval

Related

Ignore or bypass errors phpcs

How to bypass or ignore specific errors/warnings in vscode?, I am using phpcs.
What you are looking for is to ignore the warning and/or errors, that are notified by the phpcs in the console of the vscode.
For Warnings
Use the following config in your settings.json
"phpcs.showWarnings": false,
this will remove all the warnings displayed in the output console.
For Errors
You should go trough the DOCS for complete details but to remove the errors related to the Doc block and the formatting standards you can set the
"phpcs.errorSeverity": 6,
Although it is mostly used for testing or code reviews to check for total warnings and errors by setting different values for both, but for development i dont do that and keep it to the default value that is 5 but you can get rid of those errors above in your image.
The vscode-phpcs refers to the GitHub project squizlabs/PHP_CodeSniffer, which integrates PHP_CodeSniffer into VSCode.
Its readme mentions the setting phpcs.ignorePatterns:
An array of glob patterns to skip files and folders that match when linting your documents.
{
"phpcs.ignorePatterns": [
"*/ignored-file.php",
"*/ignored-dir/*"
]
}
That refers to PHP CodeSniffer --ignore option.
That is not what you want exactly, since it ignores all errors on a given set of file.
But you could use PHP CodeSniffer syntax to ignore errors:
Ignoring Parts of a File
Some parts of your code may be unable to conform to your coding standard. For example, you might have to break your standard to integrate with an external library or web service.
To stop PHP_CodeSniffer generating errors for this code, you can wrap it in special comments. PHP_CodeSniffer will then hide all errors and warnings that are generated for these lines of code.
$xmlPackage = new XMLPackage;
// phpcs:disable
$xmlPackage['error_code'] = get_default_error_code_value();
$xmlPackage->send();
// phpcs:enable
Again, not exactly what you want, since you have to specify that on a file-by-file basis
You can disable multiple error message codes, sniff, categories, or standards by using a comma separated list.
You can also selectively re-enable just the ones you want.
The following example disables the entire PEAR coding standard, and all the Squiz array sniffs, before selectively re-enabling a specific sniff. It then re-enables all checking rules at the end.
// phpcs:disable PEAR,Squiz.Arrays
$foo = [1,2,3];
bar($foo,true);
// phpcs:enable PEAR.Functions.FunctionCallSignature
bar($foo,false);
// phpcs:enable

Karma - Instanbul - console.log being counted as test?

I noticed that Karma/Istanbul is marking console.log() as covered testcase?
Is there anyway we can make Istanbul to skip console.log()?
I could just remove or rename the console.log, but I am interested if there are such options in Istanbul?
Here is an example:
If you want to ignore some statements from coverage report use special formed comments:
https://github.com/gotwarlost/istanbul/blob/master/ignoring-code-for-coverage.md

Wrong coverage report in karma

I've configured my karma.conf.js with enabled preprocessing to get a report about the code coverage of my tests. I've added this line to the preprocessors section.
preprocessors: {
'public/js/app.js': ['coverage'],
'public/js/filters.js': ['coverage'],
'public/js/directives.js': ['coverage'],
'public/js/services/*.js': ['coverage'],
'public/js/controllers/*.js': ['coverage'],
},
What I'm get is a report that is totally wrong. I know that I've written tests for each modules and the function within. But the coverage report shows me only the tests for the services correctly.
For instance the tests for directives. I know that I've written some tests and the tests will also be executed. But the report shows me that I've just tests for 36% of my code lines.
What could be the reason for this strange behavior?
Update:
I see this output from the spec reporter:
Directives:
bsTooltip:
when the element was created:
PASSED - should call the popup function
bsSwitchtext:
when the model isBusy changes to true:
PASSED - should call the button method with loading
when the model isBusy changes to false changes:
PASSED - should call the button method with loading
So I think that my test will all be executed.
Looks like there's issue with Typescript & Jasmine which is used by Angular. Enabling source map for test build appears to fix this issue.
I enabled source map in Angular 6.1 as follows,
Go to angular.json and in main project, find test, and add sourceMap:true to enable source map for the test run.
to enable that in CLI, run with command --source-map or --sm=true
Github issue links
Code coverage report issue with branch coverage (if path not taken)
ng test --code-coverage in 6.1 improperly detecting branches
I'm obligated to write this answer as I had the same issue, and this was the first question on Google search.
Try adding a console.log('testing123'); at one of the points which shows as not covered. If it shows up when you run the tests you know that something is going wrong with Istanbul.
However my guess would be that either there is something wrong with your configuration, and those tests are not running at al, or the tests are not executing the code as you think they are.
Try changing what you have in preprocessors to:
preprocessors: {
'**/public/js/**/*.js': ['coverage']
},
I was not able to the report to work unless I followed the specific syntax with **/ before directors in the preprocessors object.
The karma-coverage documentation includes the preceding **/ before directories listed in preprocessors.
Based on this SO answer.

Cruise Control .net Changing Log File appereance

i would like to change the apperance of the log file, generated by ccnet. It is useful, if the error messages are separated from the original Log Messages, but in order to debug, it is a bit tricky to see, when the error really happened. Our powershell skript runs for 6-8 hours and creates about 38k lines in the log file, so i would really apprechiate a solution, how i could list the errors with the other lines in the log files. Additionally it would be cool, if all the errors would still appear separatedly.
So far i have not found a lot documentary that explained how to change the log file output...
Simon
Not sure how this is logged, but in the end, logs produced during the build are put into the build-log file, that you will find in artifacts folder.
Then this logs are transposed into html output using xsl transforms. If none of the built-in reports is useful to you, you can create a custom xsl and plug it in, see the dashboard.config file, the following section allows for adding additional xsl transforms:
<buildReportBuildPlugin>
<xslReportBuildPlugin description="MSBuild Log" actionName="MSBuildBuildReport" xslFileName="xsl\MSBuild4Log.xsl"/>
...
If you know what the error messages are going to be you can parse them with an xsl file and generate some html that will show up in the build emails. The following goes in ccservice.exe.config.
<xslFiles>
<file name="c:\path\to\custom_errors.xsl"/>
</xslFiles>
custom_errors.xsl is an xsl file that finds the error messages in the raw build log xml and then generates html from them. This html will show up in the build emails. You have to create custom_errors.xsl. It's a significant amount of work to get working the first time especially if you're new to xml/xsl/html/css. If you undertake this I suggest doing all the testing outside of ccnet using a xsl transformer and inputting a sample ccnet build log. ccnet uses a css file to style the html so be aware of that. You can edit this too.
Note you have to restart the ccnet service after editing ccservice.exe.config.

How do I get the SpecFlow Scenario to be reported when the test runs?

I've managed to tune the output from my SpecFlow tests so that it reads nicely, with just the steps reported plus failures. But it's still pretty unreadable without the Feature and Scenario names also being reported.
Looking at the generated code, it appears that the Feature and Scenario names are encoded as NUnit DescriptionAttributes.
Can I configure SpecFlow or NUnit to also report these to stdout, so I get a nicely flowing "story-like" output?
If you define an extra method in your step definition class as follows then NUnit will report the feature and scenario text.
[BeforeScenario]
public void OutputScenario()
{
Console.WriteLine("Feature: " + FeatureContext.Current.FeatureInfo.Title);
Console.WriteLine(FeatureContext.Current.FeatureInfo.Description);
Console.WriteLine("\r\nScenario: " + ScenarioContext.Current.ScenarioInfo.Title);
}
I hope this helps.