Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/Lint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public Lint ()
{ "MissingSuperCall", new Version (26, 1, 1) },
};

static readonly Regex lintVersionRegex = new Regex (@"version[\t\s]+(?<version>[\d\.]+)");
static readonly Regex lintVersionRegex = new Regex (@"version[\t\s]+(?<version>[\d\.]+)", RegexOptions.Compiled);

public override bool Execute ()
{
Expand Down Expand Up @@ -205,11 +205,31 @@ public override bool Execute ()
Log.LogDebugTaskItems (" LibraryDirectories:", LibraryDirectories);
Log.LogDebugTaskItems (" LibraryJars:", LibraryJars);

foreach (var issue in DisabledIssuesByVersion) {
if (lintToolVersion < issue.Value) {
DisabledIssues = CleanIssues (issue.Key, lintToolVersion, DisabledIssues, nameof (DisabledIssues));
EnabledIssues = CleanIssues (issue.Key, lintToolVersion, EnabledIssues, nameof (EnabledIssues) );
}
}

base.Execute ();

return !Log.HasLoggedErrors;
}

string CleanIssues (string issueToRemove, Version lintToolVersion, string issues, string issuePropertyName)
{
Regex issueReplaceRegex = new Regex ($"\b{issueToRemove}\b(,)?");
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need the ,. The \b word boundary will still be triggered at a comma.

var r = new Regex(@"\bFoo\b");
r.Match ("Foo").Success;     // true
r.Match ("Foo,").Success;    // true
r.Match ("Foo,Bar").Success; // true
r.Match ("FooBar").Success;  // false

if (!string.IsNullOrEmpty (issues) && issues.Contains (issueToRemove)) {
var match = issueReplaceRegex.Match (DisabledIssues);
if (match.Success) {
issues = issues.Replace (match.Value, string.Empty);
Log.LogWarning ($"Removing {issueToRemove} from {issuePropertyName}. Lint {lintToolVersion} does not support this check.");
}
}
return issues;
}

protected override string GenerateCommandLineCommands ()
{
var cmd = new CommandLineBuilder ();
Expand Down