Skip to content

Commit

Permalink
feat!: big refactoring of internals
Browse files Browse the repository at this point in the history
* Refactored the way the library does validation: now we use
  github.com/go-playground/validator/v10 instead of custom ones.
* Now Parse() always return ValidationErrors containing one or more
  ValidationError if any validation error is present.
* The parser tries not to stop the validation early and give as many
  errors as possible immediately.
* The strict mode was removed
* The default output is now errorformat friendly
  (https://vim-jp.org/vimdoc-en/quickfix.html#error-file-format)
* pcvalidate learned the -json switch to ouput the report as JSON
* Specify the errored keys as a subset of JSONPath
  (fe. documentation.eng.features[3])

Fix italia#76, Fix italia#19, Fix italia#74, Fix italia#60.
  • Loading branch information
bfabio committed Feb 14, 2021
1 parent 2a6dd3e commit 3f826c6
Show file tree
Hide file tree
Showing 131 changed files with 6,313 additions and 3,670 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ This parser performs syntactic and semantic validation according to the
- Validate oembed video links and retrieve HTML for easy embedding
- Validate SPDX licenses. Without WITH keyword.
- Check tags
- Strict and non-strict modes (use non-strict when you want to be tolerant, such as in a crawler, but use strict in editors and validators)

## Example

Expand Down
21 changes: 8 additions & 13 deletions check_amministrazioni.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package publiccode

import (
"bufio"
"fmt"
"strings"
)

Expand Down Expand Up @@ -41,17 +42,13 @@ type Amministrazione struct {
LivAccessibili string
}

// checkCodiceIPA tells whether the codiceIPA is registered into amministrazioni.txt
// isCodiceIPA returns an error if codiceIPA is not registered into amministrazioni.txt
// Reference: http://www.indicepa.gov.it/documentale/n-opendata.php.
func (p *Parser) checkCodiceIPA(key string, codiceiPA string) (string, error) {
if codiceiPA == "" {
return codiceiPA, newErrorInvalidValue(key, "empty codiceIPA key")
}

// Load adminisrations data from amministrazoni.txt
func (p *Parser) isCodiceIPA(codiceiPA string) error {
// Load Public Aministrations data from amministrazioni.txt
dataFile, err := Asset("data/amministrazioni.txt")
if err != nil {
return "", err
return err
}
input := string(dataFile)

Expand All @@ -61,17 +58,15 @@ func (p *Parser) checkCodiceIPA(key string, codiceiPA string) (string, error) {
amm := manageLine(scanner.Text())
// The iPA codes should be validated as case-insensitive, according
// to the IndicePA guidelines.
// We always fold it to lower case so that users of this library can rely
// on a consistent case.
if strings.EqualFold(amm.CodAmm, codiceiPA) {
return strings.ToLower(codiceiPA), nil
return nil
}
}
if err := scanner.Err(); err != nil {
return "", newErrorInvalidValue(key, "error validating Codice IPA: %s", err)
return fmt.Errorf("error validating Codice IPA: %s", err)
}

return "", newErrorInvalidValue(key, "this is not a valid Codice IPA: %s", codiceiPA)
return fmt.Errorf("not a valid Codice IPA: %s", codiceiPA)
}

// manageLine populate an Amministrazione with the values read.
Expand Down
114 changes: 0 additions & 114 deletions check_categories.go

This file was deleted.

Loading

0 comments on commit 3f826c6

Please sign in to comment.