GithubHelp home page GithubHelp logo

microsoft / sarif-sdk Goto Github PK

View Code? Open in Web Editor NEW
179.0 35.0 83.0 106.87 MB

.NET code and supporting files for working with the 'Static Analysis Results Interchange Format' (SARIF, see https://github.com/oasis-tcs/sarif-spec)

License: Other

C# 85.87% Java 0.10% C 13.12% Shell 0.01% C++ 0.34% Batchfile 0.10% Perl 0.03% PowerShell 0.42% JavaScript 0.01%

sarif-sdk's Introduction

sarif-sdk

Build Status

The SARIF SDK contains .NET code and supporting files for working with the Static Analysis Results Interchange Format (SARIF). For more information about SARIF, see the SARIF Home Page. You can read the SARIF specification, or file issues in the SARIF GitHub repo.

Getting started

To add the SARIF SDK to your project, install the Sarif.Sdk NuGet package. Sarif.Sdk depends on Newtonsoft.Json, which is installed automatically when you install Sarif.Sdk.

The types in the SARIF SDK are in the Microsoft.CodeAnalysis.Sarif namespace.

The SARIF SDK provides a set of classes which represent the elements of the SARIF format. We refer to this as the "SARIF object model". The root type that represents a SARIF log file is SarifLog. Other types in the SARIF object model are Result, PhysicalLocation, etc..

Note: The SARIF SDK's build process automatically generates the SARIF object model classes from the SARIF JSON schema, which you can find at src/Sarif/Schemata/sarif-schema.json. Although these files do exist in the repo (under src/Sarif/Autogenerated), you should never edit them by hand.

In addition to the object model, the SARIF SDK provides a set of helper classes to facilitate using Newtonsoft.Json to read and write SARIF log files.

Building the SDK

If you want to build the SDK from source, rather than consuming the NuGet package, please refer to Devbox Setup for help setting up a compilation environment.

Then you should be able to build in Visual Studio or on the Command Line using BuildAndTest.cmd.

Accomplishing common tasks

To learn how to accomplish common tasks with the SARIF SDK, such as reading and writing files from disk, see the How To page.

Code of conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ, or contact [email protected] with any additional questions or comments.

sarif-sdk's People

Contributors

candrews avatar cfaucon avatar dependabot[bot] avatar easyrhino-gh avatar easyrhinomsft avatar eddynaka avatar harleenkohli avatar jameswinkler avatar jeffersonking avatar jericahuang avatar kathircpp avatar komal436 avatar kschecht avatar lingzhou-gh avatar marmegh avatar michaelcfanning avatar nguerrera avatar nickmarston avatar pascalberger avatar rolstenhouse avatar rscrivens avatar rtaket avatar rwoll avatar scottoneil-ms avatar shaopeng-gh avatar surbhims avatar suvamm avatar tosmolka avatar vinaykapadia avatar yongyan-gh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sarif-sdk's Issues

Create exhaustive sample SARIF file

An exhaustive fictional SARIF file that populates every possible thing. Each thing should have multiple instances where permissible (two may be sufficient). This file will be a useful example, help drive testing for consumers, and help drive design.

Write functional test to detect breaking schema changes

  • Acquire a set of sample SARIF files produced by various tools.
  • Create a test that validates them against the current schema

The idea is that if the test fails, we report the breaking change to our partners so they can update their tools to produce the new format version.

@michaelcfanning, @srivatsn: FYI. I entered this item to track the work I mentioned in today's standup.

Generate rule documentation and helper classes from RuleDescriptors

Create a tool which generates rule documentation and helper classes from RuleDescriptors.

It might ease adoption of the sarif SDK if we had tooling which took the metadata from the RuleDescriptors and created rule documentation, classes for each rule and any associated helper methods (e.g. methods to create result objects for rules.) The adoption workflow would look like this.

  1. Developer authors the RuleDescriptors for the static analysis tool.
  2. Developer runs an SDK tool which consumes the RuleDescriptors and creates help documentation for each rule.
  3. Developer runs an SDK tool (this could be the same tool as in step 2) which consumes the RuleDescriptors and creates C# classes/files for each rule. The rule strings are put into resource files. The classes have helper methods which the developer can use to access the strings or perhaps create Result objects for the rule.

PDB exceptions don't necessarily require stack reporting

For a missing PDB, we don't need to report the full stack. We should alter the core logging utility to accept a string message (which can be a concise 'could not locate PDB' message or a complete stack, a la ex.ToString()', up to the discretion of the caller).

We need complete validation for JSON files

we should have helpers/visitors in the SDK that perform comprehensive, detailed validation.
our JSON schema needs to exercise more validation capabilities, such as oneOf. We don't do this today because we generate the schema from a G4. when we author the JSON schema directly, we should build it out

resultLog.runLogs.runInfo should contain the list the configuration values for the run

It would be nice of the configuration values for the run were stored in resultLog.runLogs.runInfo. While most of the configuration can be gleaned from the command line, if the user specifies the "default" configuration for the run, the person reading the log file might not know what the "default" settings are for the tool. It would be better if run configuration were specifically detailed in the runInfo section.

We need a tagger integrated in the viewer that adds squigglies for all files.

On navigating to an issue in a previously unopened file, the file should open in the editor and squigglies should be overlaid everywhere we see an issue. The squiggly should provide a pop-up tool-tip with the full message text. Ultimately, a right click option on the squiggly that integrates with our up and down vote feature would be good.

Note that when squigglies are enabled, we might not need the navigation code that currently selects the relevant code range associated with a static analysis result on double-click. We should see how this behavior looks when we get to building this feature.

Add an optional property to ruleDescriptor which specifies the location of the online definition of the rule

It would be nice if ruleDescriptor had a URI property which specifies an endpoint where the rule definition can be retrieved from.

In our meeting, we had a deeper conversation about how this property could be used. In general, we thought the URI (and it's contents) can be thought of as a contract for a rule. For example, if the URL was http://sarif.microsoft.com/codedefects/unusedusingstatements, this indicates that the rule professes to validate that there are no unused using statements. The URI describes the defect and the rule verifies the defect does not exist. The relationship between URI(defects)->rules is not 1-to-1. Many rules may profess to verify a defect. This also implies that many tools may profess to verify a defect.

charOffset and byteOffset need to be int? (nullable)

It is easy for log consumers to determine that they need to need to consult charOffset or byteOffset members to determine result location, they only need to consult startColumn, which is 1-indexed (if its value is 0, then charOffset or byteOffset must be consulted).

Because charOffset and byteOffset are 0-indexed, however, we cannot distinguish which property is in play for offset == 0.

The practical impact is that object models (such as provided by the SARIF .NET SDK) must provide nullable values for these properties, that directly express whether the property was present in source JSON.

Provide formattedMessage validation (in release builds)

We have some debug handling for verifying that formattedMessages have appropriate # of arguments. This doesn't help callers who take a dependency on release builds.

Since the generation of a result is a reasonably low-frequency occurrence, we should put this validation into the release path. For now, it probably belongs in the RuleUtilities.BuildResult API (since we are still auto-generating the SDK, otherwise validation could exist in FormattedMessage itself).

Putting validation in the SDK API would allow someone to reauthor their own version if the validation was perceived as not helpful for some reason.

File/Open dialog should validate file existence with every directory change

When attempting to remap a file location, it is nice when the code automatically tries to locate the remapped file, rather than requiring a use to navigate to it completely. Making this improvement would entail getting a callback from File/Open on any directory change. We'd then need to examine all directory suffixes on the target file path to see if any of them resolve via File.Exists.

Viewer should provide simple application of code fixes

We should be able to take a code fix for a test file and to apply it using VS text buffer manipulating capabilities. Complexity here would involve remembering what edits have been made in order to permit subsequent application of other code fixes within the file.

Viewer should automatically invoke converters, if available

We should add new options to File/Open for our tool converters. E.g., we have an entry for Fortify files that would invoke the converter for Fortify, convert to SARIF, and then populate via regular code paths.

When we have this functionality, the viewer is a kind of universal SA results viewer, might warrant some renaming of commands/change of metadata associated with package.

Can't find GeneratedKey.snk in a new enlistment

Repro:

  1. Fork this repo and clone it.
  2. From the root directory, run BuildAndTest.cmd.

Expected: It builds.

Actual:

CSC : error CS7027: Error signing output with public key from file 'GeneratedKey.snk' -- File not found. [e:\Repos\sarif-sdk\src\Sarif\Sarif.csproj]

Cause: The script creates GeneratedKey.snk in the root directory, but the project files don't refer to it at the correct path.

Fix: Modify the project files to refer to the key at the correct path. (The project file Sarif.Viewer.VisualStudio.csproj has it right. Sarif.csproj and Sarif.Driver.csproj have it wrong.)

IsSuppressedInSource needs to be a bool?

In order to express three conditions:

in source suppression information not available (e.g., when CODE_ANALYSIS is not defined)
in-source suppression info available and item is suppressed in source
in-source suppression info available and item is not suppressed in source

ERR0998 should call out the id of the rule that failed

Since ERR0998 is raised for rule exceptions, the rule id of the offending rule should be explicitly stated in the ERR0998 result node. Currently, the rule name is listed in the format args, but the rule id does not exist.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.