-
Notifications
You must be signed in to change notification settings - Fork 115
API
Gabe Stocco edited this page Nov 2, 2023
·
14 revisions
DevSkim functionality can be used or extended via .NET library. The very same library is used in Command Line Interface as well as in Visual Studio Extension.
DevSkim library is available on NuGet Microsoft.CST.DevSkim and API documentation is automatically published on GitHub Pages.
PM> Install-Package Microsoft.CST.DevSkim
dotnet add package Microsoft.CST.DevSkim
<ItemGroup>
<PackageReference Include="Microsoft.DevSkim" Version="1.0.23" />
</ItemGroup>
DevSkim library consists of two main classes, DevSkimRuleset
collection which loads and contains rules and DevSkimRuleProcessor
which applies given rule set to a text content and returns results.
The DevSkimRuleset
can be created from a directory, file or free form text or from the default embedded rules.
// verbose way
DevSkimRuleset rules = new DevSkimRuleset();
rules.AddDirectory("/home/user/rules");
// Load the rules
DevSkimRuleset rules = DevSkimRuleset.LoadDefaultRules()
// Create options
DevSkimRuleProcessorOptions opts = new DevSkimRuleProcessorOptions();
// Create DevSkimRuleProcessor and pass the ruleset
DevSkimRuleProcessor processor = new DevSkimRuleProcessor(rules, opts);
// Get content for analysis
string content = File.ReadAllText("main.cpp");
// Analyze content, using rules for C++
IEnumerable<Issue> issues = processor.Analyze(content, "main.cpp");