上传新的package
This commit is contained in:
38
Assets/09.CodeChecker/Editor/Rules/CheckNamespace.cs
Normal file
38
Assets/09.CodeChecker/Editor/Rules/CheckNamespace.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
|
||||
namespace wvdet.CodeChecker
|
||||
{
|
||||
public class CheckNamespace : ICheckable
|
||||
{
|
||||
private static List<string> Forbiddens = new List<string>()
|
||||
{
|
||||
//针对于禁用的命名空间放在此处
|
||||
// "System.Linq",
|
||||
|
||||
};
|
||||
|
||||
public List<Detail> Check(string filepath, CompilationUnitSyntax root)
|
||||
{
|
||||
var results = new List<Detail>();
|
||||
|
||||
var usings = root.DescendantNodes().OfType<UsingDirectiveSyntax>();
|
||||
foreach (var us in usings)
|
||||
{
|
||||
var ns = us.Name.ToString();
|
||||
if (Forbiddens.Contains(ns))
|
||||
{
|
||||
results.Add(new Detail
|
||||
{
|
||||
level = Level.Error,
|
||||
line = us.GetLocation().GetLineSpan().StartLinePosition.Line + 1,
|
||||
guideline = $"禁用此命名空间:{ns}",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user