Skip to content

Commit

Permalink
Merge pull request #29 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 2.5.0
  • Loading branch information
andyone authored Oct 25, 2019
2 parents 489c0bc + 4751b41 commit 7d5451c
Show file tree
Hide file tree
Showing 15 changed files with 440 additions and 153 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go:
- 1.10.x
- 1.11.x
- 1.12.x
- 1.13.x
- tip

os:
Expand All @@ -23,7 +24,7 @@ cache: apt

before_install:
- wget https://storage.googleapis.com/shellcheck/shellcheck-latest.linux.x86_64.tar.xz
- wget -O hadolint https://github.com/hadolint/hadolint/releases/download/v1.15.0/hadolint-Linux-x86_64
- wget -O hadolint https://github.com/hadolint/hadolint/releases/download/v1.17.2/hadolint-Linux-x86_64
- tar xf shellcheck-latest.linux.x86_64.tar.xz
- echo "deb http://us.archive.ubuntu.com/ubuntu xenial main universe" | sudo tee -a /etc/apt/sources.list
- sudo apt-get update -qq
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################

# This Makefile generated by GoMakeGen 1.1.0 using next command:
# This Makefile generated by GoMakeGen 1.2.0 using next command:
# gomakegen .
#
# More info: https://kaos.sh/gomakegen
Expand All @@ -27,7 +27,7 @@ git-config: ## Configure git redirects for stable import path services
git config --global http.https://pkg.re.followRedirects true

deps: git-config ## Download dependencies
go get -d -v pkg.re/essentialkaos/ek.v10
go get -d -v pkg.re/essentialkaos/ek.v11

deps-test: git-config ## Download dependencies for tests
go get -d -v pkg.re/check.v1
Expand All @@ -46,6 +46,6 @@ help: ## Show this info
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-12s\033[0m %s\n", $$1, $$2}'
@echo -e ''
@echo -e '\033[90mGenerated by GoMakeGen 1.1.0\033[0m\n'
@echo -e '\033[90mGenerated by GoMakeGen 1.2.0\033[0m\n'

################################################################################
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<a href="#license"><img src="https://gh.kaos.st/ekol.svg"></a>
</p>

<p align="center"><a href="#installing">Installing</a> • <a href="#using-on-travisci">Using on TravisCI</a> • <a href="#using-with-docker">Using with Docker</a> • <a href="#usage">Usage</a> • <a href="#build-status">Build Status</a> • <a href="#license">License</a></p>
<p align="center"><a href="#checks">Checks</a> • <a href="#installing">Installing</a> • <a href="#using-on-travisci">Using on TravisCI</a> • <a href="#using-with-docker">Using with Docker</a> • <a href="#usage">Usage</a> • <a href="#build-status">Build Status</a> • <a href="#license">License</a></p>

<br/>

Expand All @@ -18,6 +18,29 @@ _perfecto_ is tool for checking perfectly written RPM specs. Currently, _perfect

![Screenshot](https://gh.kaos.st/perfecto2.png)

### Checks

* `PF1` Checks all spec data for useless spaces;
* `PF2` Checks all spec data for lines longer than 80 symbols;
* `PF3` Checks release tag for using `%{?dist}` macro;
* `PF4` Checks all scriptlets for using paths instead of macroses;
* `PF5` Checks `install` and `clean` scriptlets for problems with `%{buildroot}` macro;
* `PF6` Checks all scriptlets for dissimilar redirect to `/dev/null`;
* `PF7` Checks changelog for misformatted records;
* `PF8` Checks `build`, `install` and `check` scriptlets for using `make` which can be simplified;
* `PF9` Checks header for required tags;
* `PF10` Checks all spec data for unescaped percentage symbol;
* `PF11` Checks position of `%global` and `%define` keywords;
* `PF12` Checks length of separator comments;
* `PF13` Checks `files` section for `%defattr`;
* `PF14` Checks all spec data for useless binaries macroses;
* `PF15` Checks all spec data for empty sections;
* `PF16` Checks `files` section for indentations;
* `PF17` Checks `setup` section options;
* `PF18` Checks all spec data for empty lines at the end;
* `PF19` Checks bash loops formatting;
* `PF20` Checks sources URLs for HTTPS support.

### Installing

#### From sources
Expand Down Expand Up @@ -141,6 +164,7 @@ Usage: perfecto {options} file…
Options
--absolve, -A id… Disable some checks by their ID
--format, -f format Output format (summary|tiny|short|json|xml)
--lint-config, -c file Path to rpmlint configuration file
--error-level, -e level Return non-zero exit code if alert level greater than given (notice|warning|error|critical)
Expand Down
33 changes: 24 additions & 9 deletions check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ package check
import (
"sort"

"pkg.re/essentialkaos/ek.v11/sliceutil"

"github.com/essentialkaos/perfecto/spec"
)

Expand All @@ -35,9 +37,10 @@ type Report struct {

// Alert contain basic alert info
type Alert struct {
Level uint8 `json:"level"`
Info string `json:"info"`
Line spec.Line `json:"line"`
Level uint8 `json:"level"`
Info string `json:"info"`
Line spec.Line `json:"line"`
Absolve bool `json:"absolve"`
}

// ////////////////////////////////////////////////////////////////////////////////// //
Expand All @@ -53,6 +56,13 @@ func (s AlertSlice) Less(i, j int) bool {

// ////////////////////////////////////////////////////////////////////////////////// //

// NewAlert creates new alert
func NewAlert(level uint8, info string, line spec.Line) Alert {
return Alert{level, info, line, false}
}

// ////////////////////////////////////////////////////////////////////////////////// //

// IsPerfect return true if report doesn't have any alerts
func (r *Report) IsPerfect() bool {
switch {
Expand All @@ -72,22 +82,29 @@ func (r *Report) IsPerfect() bool {
// ////////////////////////////////////////////////////////////////////////////////// //

// Check check spec
func Check(s *spec.Spec, lint bool, linterConfig string) *Report {
func Check(s *spec.Spec, lint bool, linterConfig string, absolved []string) *Report {
report := &Report{}
checkers := getCheckers()

if lint {
appendLinterAlerts(s, report, linterConfig)
alerts := Lint(s, linterConfig)
appendLinterAlerts(report, alerts)
}

for _, checker := range checkers {
for id, checker := range checkers {
alerts := checker(s)

if len(alerts) == 0 {
continue
}

absolve := sliceutil.Contains(absolved, id)

for _, alert := range alerts {
if absolve || alert.Line.Skip {
alert.Absolve = true
}

switch alert.Level {
case LEVEL_NOTICE:
report.Notices = append(report.Notices, alert)
Expand All @@ -110,9 +127,7 @@ func Check(s *spec.Spec, lint bool, linterConfig string) *Report {
// ////////////////////////////////////////////////////////////////////////////////// //

// appendLinterAlerts append rpmlint alerts to report
func appendLinterAlerts(s *spec.Spec, r *Report, linterConfig string) {
alerts := Lint(s, linterConfig)

func appendLinterAlerts(r *Report, alerts []Alert) {
if len(alerts) == 0 {
return
}
Expand Down
Loading

0 comments on commit 7d5451c

Please sign in to comment.