checkstyle

package module
v0.0.0-...-bfd46e6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2017 License: BSD-3-Clause Imports: 2 Imported by: 1

README

checkstyle

GoDoc Go Report Card Build Status

Read and write checksyle_report.xml files with golang

Checkstyle XML files are a standard file format for reporting errors in source code, and is often generated by static analysis tools.

Example usage:


import "github.com/phayes/checkstyle"

// 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
codingError := checkstyle.NewError(10, "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

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

View Source
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 New

func New() *CheckStyle

New returns a new CheckStyle

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

func NewError

func NewError(line int, column int, severity Severity, message string, source string) *Error

NewError creates a new checkstyle.Error Note that line starts at 0, and column starts at 1

type File

type File struct {
	XMLName xml.Name `xml:"file"`
	Name    string   `xml:"name,attr"`
	Error   []*Error `xml:"error"`
}

File represents a <file> xml element.

func NewFile

func NewFile(filename string) *File

NewFile creates a new checkstyle.File

func (*File) AddError

func (csf *File) AddError(cse *Error)

AddError adds a checkstyle.Error to the file.

type Severity

type Severity string

Severity defines a checkstyle severity code

var (
	SeverityError   Severity = "error"
	SeverityInfo    Severity = "info"
	SeverityWarning Severity = "warning"
	SeverityIgnore  Severity = "ignore"
	SeverityNone    Severity
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL