Documentation
¶
Overview ¶
Package checkstyle allows the parsing of generation of checkstyle XML files.
Checkstyle XML files are a standard file format for reporting errors in source code, and is often generated by static analysis tools.
Example usage:
// Print XML into human readable format checkSyle, err := checkstyle.ReadFile("checkstyle_report.xml") if err != nil { log.Fatal(err) } for _, file := range checkStyle.File { fmt.Println(File.Name) for _, codingError := range file.Error { fmt.Println("\t", codingError.Line, codingError.Message) } } // Create a new XML file from scratch check := checkstyle.New() // Ensure that a file has been added file := check.EnsureFile("/path/to/file") // Create an error on line 10, column 5 codingError := checkstyle.NewError(10, 5, checkstyle.SeverityWarning, "format", "line must end with a full stop") // Add the error to the file file.AddError(codingError) // Output XML fmt.Print(check)
For more information on checkstyle XML see: http://checkstyle.sourceforge.net/checks.html
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultCheckStyleVersion = "1.0.0"
DefaultCheckStyleVersion defines the default "version" attribute on "<checkstyle>" lememnt
Functions ¶
This section is empty.
Types ¶
type CheckStyle ¶
type CheckStyle struct { XMLName xml.Name `xml:"checkstyle"` Version string `xml:"version,attr"` File []*File `xml:"file"` }
CheckStyle represents a <checkstyle> xml element found in a checkstyle_report.xml file.
func ReadFile ¶
func ReadFile(filename string) (*CheckStyle, error)
ReadFile reads a checkfile.xml file and returns a CheckStyle object.
func (*CheckStyle) AddFile ¶
func (cs *CheckStyle) AddFile(csf *File)
AddFile adds a checkstyle.File with the given filename.
func (*CheckStyle) EnsureFile ¶
func (cs *CheckStyle) EnsureFile(filename string) (csf *File)
EnsureFile ensures that a CheckStyleFile with the given name exists Returns either an exiting CheckStyleFile (if a file with that name exists) or a new CheckStyleFile (if a file with that name does not exists)
func (*CheckStyle) GetFile ¶
func (cs *CheckStyle) GetFile(filename string) (csf *File, ok bool)
GetFile gets a CheckStyleFile with the given filename.
func (*CheckStyle) String ¶
func (cs *CheckStyle) String() string
String implements Stringer. Returns as xml.
type Error ¶
type Error struct { XMLName xml.Name `xml:"error"` Line int `xml:"line,attr"` Column int `xml:"column,attr,omitempty"` Severity Severity `xml:"severity,attr,omitempty"` Message string `xml:"message,attr"` Source string `xml:"source,attr"` }
Error represents a <error> xml element