Add linter workflow as GitHub action (#325)

* Add linter workflow as GitHub action

* Fix linter issues

* More fixes
This commit is contained in:
Joona Hoikkala 2020-10-03 11:29:18 +03:00 committed by GitHub
parent 2abc72018d
commit 99100e0608
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 66 additions and 19 deletions

28
.github/workflows/golangci-lint.yml vendored Normal file
View file

@ -0,0 +1,28 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- master
pull_request:
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.29
# Optional: working directory, useful for monorepos
# working-directory: somedir
# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

View file

@ -35,7 +35,7 @@ type InternalInputProvider interface {
//OutputProvider is responsible of providing output from the RunnerProvider //OutputProvider is responsible of providing output from the RunnerProvider
type OutputProvider interface { type OutputProvider interface {
Banner() error Banner()
Finalize() error Finalize() error
Progress(status Progress) Progress(status Progress)
Info(infostring string) Info(infostring string)

View file

@ -119,7 +119,10 @@ func (j *Job) Start() {
j.startExecution() j.startExecution()
} }
j.Output.Finalize() err := j.Output.Finalize()
if err != nil {
j.Output.Error(err.Error())
}
} }
func (j *Job) jobsInQueue() bool { func (j *Job) jobsInQueue() bool {

View file

@ -12,7 +12,7 @@ type ValueRange struct {
func ValueRangeFromString(instr string) (ValueRange, error) { func ValueRangeFromString(instr string) (ValueRange, error) {
// is the value a range // is the value a range
minmax := regexp.MustCompile("^(\\d+)\\-(\\d+)$").FindAllStringSubmatch(instr, -1) minmax := regexp.MustCompile(`^(\d+)-(\d+)$`).FindAllStringSubmatch(instr, -1)
if minmax != nil { if minmax != nil {
// yes // yes
minval, err := strconv.ParseInt(minmax[0][1], 10, 0) minval, err := strconv.ParseInt(minmax[0][1], 10, 0)

View file

@ -58,6 +58,7 @@ func AddMatcher(conf *ffuf.Config, name string, option string) error {
//CalibrateIfNeeded runs a self-calibration task for filtering options (if needed) by requesting random resources and acting accordingly //CalibrateIfNeeded runs a self-calibration task for filtering options (if needed) by requesting random resources and acting accordingly
func CalibrateIfNeeded(j *ffuf.Job) error { func CalibrateIfNeeded(j *ffuf.Job) error {
var err error
if !j.Config.AutoCalibration { if !j.Config.AutoCalibration {
return nil return nil
} }
@ -67,12 +68,12 @@ func CalibrateIfNeeded(j *ffuf.Job) error {
return err return err
} }
if len(responses) > 0 { if len(responses) > 0 {
calibrateFilters(j, responses) err = calibrateFilters(j, responses)
} }
return nil return err
} }
func calibrateFilters(j *ffuf.Job, responses []ffuf.Response) { func calibrateFilters(j *ffuf.Job, responses []ffuf.Response) error {
sizeCalib := make([]string, 0) sizeCalib := make([]string, 0)
wordCalib := make([]string, 0) wordCalib := make([]string, 0)
lineCalib := make([]string, 0) lineCalib := make([]string, 0)
@ -97,14 +98,24 @@ func calibrateFilters(j *ffuf.Job, responses []ffuf.Response) {
lineCalib = ffuf.UniqStringSlice(lineCalib) lineCalib = ffuf.UniqStringSlice(lineCalib)
if len(sizeCalib) > 0 { if len(sizeCalib) > 0 {
AddFilter(j.Config, "size", strings.Join(sizeCalib, ",")) err := AddFilter(j.Config, "size", strings.Join(sizeCalib, ","))
if err != nil {
return err
}
} }
if len(wordCalib) > 0 { if len(wordCalib) > 0 {
AddFilter(j.Config, "word", strings.Join(wordCalib, ",")) err := AddFilter(j.Config, "word", strings.Join(wordCalib, ","))
if err != nil {
return err
}
} }
if len(lineCalib) > 0 { if len(lineCalib) > 0 {
AddFilter(j.Config, "line", strings.Join(lineCalib, ",")) err := AddFilter(j.Config, "line", strings.Join(lineCalib, ","))
if err != nil {
return err
} }
}
return nil
} }
func SetupFilters(parseOpts *ffuf.ConfigOptions, conf *ffuf.Config) error { func SetupFilters(parseOpts *ffuf.ConfigOptions, conf *ffuf.Config) error {

View file

@ -19,7 +19,7 @@ func NewStatusFilter(value string) (ffuf.FilterProvider, error) {
var intranges []ffuf.ValueRange var intranges []ffuf.ValueRange
for _, sv := range strings.Split(value, ",") { for _, sv := range strings.Split(value, ",") {
if sv == "all" { if sv == "all" {
intranges = append(intranges, ffuf.ValueRange{AllStatuses, AllStatuses}) intranges = append(intranges, ffuf.ValueRange{Min: AllStatuses, Max: AllStatuses})
} else { } else {
vr, err := ffuf.ValueRangeFromString(sv) vr, err := ffuf.ValueRangeFromString(sv)
if err != nil { if err != nil {

View file

@ -188,7 +188,10 @@ func writeHTML(config *ffuf.Config, results []Result) error {
templateName := "output.html" templateName := "output.html"
t := template.New(templateName).Delims("{{", "}}") t := template.New(templateName).Delims("{{", "}}")
t.Parse(htmlTemplate) _, err = t.Parse(htmlTemplate)
t.Execute(f, outHTML) if err != nil {
return nil return err
}
err = t.Execute(f, outHTML)
return err
} }

View file

@ -44,7 +44,10 @@ func writeMarkdown(config *ffuf.Config, res []Result) error {
templateName := "output.md" templateName := "output.md"
t := template.New(templateName).Delims("{{", "}}") t := template.New(templateName).Delims("{{", "}}")
t.Parse(markdownTemplate) _, err = t.Parse(markdownTemplate)
t.Execute(f, outMD) if err != nil {
return nil return err
}
err = t.Execute(f, outMD)
return err
} }

View file

@ -50,8 +50,8 @@ func NewStdoutput(conf *ffuf.Config) *Stdoutput {
return &outp return &outp
} }
func (s *Stdoutput) Banner() error { func (s *Stdoutput) Banner() {
fmt.Fprintf(os.Stderr ,"%s\n v%s\n%s\n\n", BANNER_HEADER, ffuf.VERSION, BANNER_SEP) fmt.Fprintf(os.Stderr, "%s\n v%s\n%s\n\n", BANNER_HEADER, ffuf.VERSION, BANNER_SEP)
printOption([]byte("Method"), []byte(s.config.Method)) printOption([]byte("Method"), []byte(s.config.Method))
printOption([]byte("URL"), []byte(s.config.Url)) printOption([]byte("URL"), []byte(s.config.Url))
@ -141,7 +141,6 @@ func (s *Stdoutput) Banner() error {
printOption([]byte("Filter"), []byte(f.Repr())) printOption([]byte("Filter"), []byte(f.Repr()))
} }
fmt.Fprintf(os.Stderr, "%s\n\n", BANNER_SEP) fmt.Fprintf(os.Stderr, "%s\n\n", BANNER_SEP)
return nil
} }
func (s *Stdoutput) Progress(status ffuf.Progress) { func (s *Stdoutput) Progress(status ffuf.Progress) {