Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

[Gendarme] Improve finding included .ignore files #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 16 additions & 5 deletions gendarme/console/IgnoreFileList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace Gendarme {
public class IgnoreFileList : BasicIgnoreList {

private string current_rule;
private string currentFileName;
private Dictionary<string, HashSet<string>> assemblies = new Dictionary<string, HashSet<string>> ();
private Dictionary<string, HashSet<string>> types = new Dictionary<string, HashSet<string>> ();
private Dictionary<string, HashSet<string>> methods = new Dictionary<string, HashSet<string>> ();
Expand All @@ -54,24 +55,34 @@ public IgnoreFileList (IRunner runner, string fileName)

private void Push (string fileName)
{
if (!String.IsNullOrEmpty (fileName) && File.Exists (fileName) && !files.Contains (fileName)) {
if (String.IsNullOrEmpty (fileName))
return;

if (File.Exists (fileName) && !files.Contains (fileName)) {
files.Push (fileName);
}
else {
var directory = Path.GetDirectoryName (currentFileName);
if (!string.IsNullOrEmpty (directory) && !fileName.StartsWith (directory)){
Push (Path.Combine (directory, fileName));
}
}
}

private void Parse ()
{
char [] buffer = new char [4096];
while (files.Count > 0) {
string fileName = files.Pop ();
using (StreamLineReader sr = new StreamLineReader (fileName)) {
currentFileName = files.Pop ();
using (StreamLineReader sr = new StreamLineReader (currentFileName)) {
while (!sr.EndOfStream) {
int length = sr.ReadLine (buffer, 0, buffer.Length);
ProcessLine (buffer, length);
}
}
}
Resolve ();
currentFileName = null;
Resolve();
TearDown ();
}

Expand Down Expand Up @@ -132,7 +143,7 @@ private void ProcessLine (char [] buffer, int length)
base.Add (current_rule, NamespaceDefinition.GetDefinition (GetString (buffer, length)));
break;
case '@': // include file
files.Push (GetString (buffer, length));
Push (GetString (buffer, length));
break;
default:
Console.Error.WriteLine ("Bad ignore entry : '{0}'", new string (buffer));
Expand Down