Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #89: allow user to customize rules xml #90

Merged
merged 5 commits into from
Aug 6, 2018

Conversation

duncanp-lseg
Copy link

The code follows the same pattern used for customizing SQALE i.e.

  • first time the exe is called, a template rules.xml is created
  • the user can customize the file, then run the exe again using the /rules parameter to tell the exe to use the customized rules file

duncanp-sonar added 3 commits August 3, 2018 17:17
- added option for the user to supply the rules.xml file to use, similar to the option for SQALE files.
@ghost ghost assigned duncanp-lseg Aug 3, 2018
@ghost ghost added the Status: Needs Review label Aug 3, 2018
<tag>t1</tag>
<tag>t2</tag>
<debtRemediationFunction>CONSTANT_ISSUE</debtRemediationFunction>
<debtRemediationFunctionOffset>15min</debtRemediationFunctionOffset>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't currently generate template files files with tags or debt remediation data. However, this test checks that the serializer could correctly serialize that data. I'll add documentation to the readme explaining how to manually add these elements.


namespace SonarQube.Plugins.Roslyn
{
public enum DebtRemediationFunctionType

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SonarC# and SonarVB currently support only CONSTANT_ISSUE so I am not sure if we will be able to provide the other values.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a comment saying they are unsupported by the C# plugin currently.


namespace SonarQube.Plugins.Roslyn
{
public enum IssueType

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we allow external users to provide the new type (hotspot)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plugin in LTS-compatible so I don't think hotspots are available.

}
set
{
this.DebtRemediationFunction = (DebtRemediationFunctionType)Enum.Parse(typeof(DebtRemediationFunctionType), value);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to do a TryParse and assign Unspecified in case of wrong value?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is ok; we'll fail fast if the user supplies an invalid value.

LogMessageForGeneratedSqale(generatedSqaleFile);

return createdJarFilePath;
}

private void LogMessageForGeneratedRules(string generatedFile)
{
if (generatedFile != null)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to also log (another message) when the file is null?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case the user will have supplied the file name as a parameter, and a message will have been logged in line 218 above.

/// </summary>
private bool IsValidRulesFile(string filePath)
{
Debug.Assert(!string.IsNullOrWhiteSpace(filePath));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO those 2 assertions needs to be if/throw.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're assertions because they are checking the validity of our code, not the user input. We don't expect our code to reach this point if the file is null or missing.
If the user has supplied a valid file then the code will already have thrown (see comment in line 419 below).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

{
string expectedFilePath = GetExpectedRuleTemplateFilePath(outputDir, package);

Assert.IsTrue(File.Exists(expectedFilePath), "Expecting a template rule file to have been created");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use fluent assertions instead.

private static void AssertRuleTemplateDoesNotExist(string outputDir)
{
string[] matches = Directory.GetFiles(outputDir, "*rules*template*", SearchOption.AllDirectories);
Assert.AreEqual(0, matches.Length, "Not expecting any rules template files to exist");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use fluent assertions instead.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@duncanp-sonar You missed this one.

{
public class ProcessedArgsBuilder
{
private string packageId;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be readonly.

private string ruleFilePath;
private bool acceptLicenses;
private bool recurseDependencies;
private string outputDirectory;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonly

this.packageId = packageId;
this.outputDirectory = outputDir;
}
public ProcessedArgsBuilder SetPackageVersion(string packageVersion)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing blank line before this method declaration.

@sonarqubecloud sonarqubecloud bot deleted a comment from duncanp-lseg Aug 6, 2018
Copy link

@sonarqubecloud sonarqubecloud bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SonarQube analysis found issues:
Bug Bugs: 0
Vulnerability Vulnerabilities: 0
Code Smell Code Smells: 2

See all issues in SonarCloud

@@ -25,7 +25,8 @@ namespace SonarQube.Plugins.Roslyn.CommandLine
{
public class ProcessedArgs
{
public ProcessedArgs(string packageId, SemanticVersion packageVersion, string language, string sqaleFilePath, bool acceptLicenses, bool recurseDependencies, string outputDirectory)
public ProcessedArgs(string packageId, SemanticVersion packageVersion, string language, string sqaleFilePath, string ruleFilePath,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Smell Code Smell: Constructor has 8 parameters, which is greater than the 7 authorized. (csharpsquid:S107)

See it in SonarCloud


try
{
// TODO: consider adding further checks
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Smell Code Smell: Complete the task associated to this 'TODO' comment. (csharpsquid:S1135)

See it in SonarCloud

@Evangelink Evangelink merged commit d34380f into master Aug 6, 2018
@ghost ghost removed the Status: Needs Review label Aug 6, 2018
@Evangelink Evangelink deleted the duncanp/rulesXmlRb branch August 6, 2018 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants