This repository has been archived by the owner on May 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from codiga/codiga-yaml-ignore
Add support for `ignore` property in codiga.yml
- Loading branch information
Showing
16 changed files
with
1,197 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/Extension/Rosie/Model/Codiga/CodigaCodeAnalysisConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Extension.Rosie.Model.Codiga | ||
{ | ||
/// <summary> | ||
/// Represents a codiga.yml configuration file. | ||
/// </summary> | ||
/// <see cref="CodigaConfigFileUtil.DeserializeConfig"/> | ||
public class CodigaCodeAnalysisConfig | ||
{ | ||
public static readonly CodigaCodeAnalysisConfig EMPTY = new CodigaCodeAnalysisConfig(); | ||
|
||
private List<string>? _rulesets; | ||
|
||
public List<string> Rulesets | ||
{ | ||
get => _rulesets ?? new List<string>(); | ||
set => _rulesets = value; | ||
} | ||
|
||
/// <summary> | ||
/// Stores [ruleset name -> ruleset ignore configuration] mappings. | ||
/// <br/> | ||
/// Using a map instead of a <c>List<RulesetIgnore></c>, so that we can query the ruleset | ||
/// configs by name, without having to filter the list by the ruleset name. | ||
/// </summary> | ||
public IDictionary<string, RulesetIgnore> Ignore { get; } = new Dictionary<string, RulesetIgnore>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Extension.Rosie.Model.Codiga | ||
{ | ||
/// <summary> | ||
/// Represents a rule ignore configuration element in the codiga.yml file. | ||
/// <br/> | ||
/// This is the element right under a ruleset name property, e.g.: | ||
/// <code> | ||
/// - rule1: | ||
/// - prefix: /path/to/file/to/ignore | ||
/// </code> | ||
/// or | ||
/// <code> | ||
/// - rule2: | ||
/// - prefix: | ||
/// - /path1 | ||
/// - /path2 | ||
/// </code> | ||
/// </summary> | ||
public class RuleIgnore | ||
{ | ||
public string RuleName { get; } | ||
|
||
/// <summary> | ||
/// The list of prefix values under the <c>prefix</c> property. | ||
/// <br/> | ||
/// In case multiple <c>prefix</c> properties are defined under the same rule config, | ||
/// they are all added to this list. | ||
/// <br/> | ||
/// For example, in case of: | ||
/// <code> | ||
/// ignore: | ||
/// - my-python-ruleset: | ||
/// - rule1: | ||
/// - prefix: | ||
/// - /path1 | ||
/// - /path2 | ||
/// - prefix: /path3 | ||
/// </code> | ||
/// all of <c>/path1</c>, <c>/path2</c> and <c>/path3</c> are stored here. | ||
/// <br/> | ||
/// In case a <c>prefix</c> property contains the same value multiple times, | ||
/// they are deduplicated and only once instance is stored, for example: | ||
/// <code> | ||
/// ignore: | ||
/// - my-python-ruleset: | ||
/// - rule1: | ||
/// - prefix: | ||
/// - /path1 | ||
/// - /path1 | ||
/// </code> | ||
/// </summary> | ||
public List<string> Prefixes { get; } = new List<string>(); | ||
|
||
public RuleIgnore(string ruleName) | ||
{ | ||
RuleName = ruleName; | ||
} | ||
|
||
public RuleIgnore(string ruleName, object ruleIgnore) | ||
{ | ||
RuleName = ruleName; | ||
if (ruleIgnore is List<object> prefixIgnores) | ||
{ | ||
foreach (var prefixIgnore in prefixIgnores) | ||
{ | ||
if (prefixIgnore is Dictionary<object, object> prefixIgnoreDict) | ||
{ | ||
var prefixIgnoreValue = prefixIgnoreDict.Values.FirstOrDefault(); | ||
/* | ||
A 'prefix' property can have a single String value: | ||
- prefix: /path/to/file/to/ignore | ||
*/ | ||
if (prefixIgnoreValue is string value) | ||
Prefixes = new List<string> { value }; | ||
|
||
/* | ||
A 'prefix' property can also have multiple String values as a list: | ||
- prefix: | ||
- /path1 | ||
- /path2 | ||
*/ | ||
else if (prefixIgnoreValue is List<object> prefixes) | ||
//It filters out null and non-String prefix values | ||
Prefixes = prefixes | ||
.Where(prefix => prefix != null) | ||
.OfType<string>() | ||
.Distinct() | ||
.ToList(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.