Skip to content

Commit

Permalink
Merge pull request #26 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 2.3.1
  • Loading branch information
andyone authored Jul 4, 2019
2 parents 61fba18 + 75942e8 commit 05bab11
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 36 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################

# This Makefile generated by GoMakeGen 1.0.0 using next command:
# This Makefile generated by GoMakeGen 1.1.0 using next command:
# gomakegen .
#
# More info: https://kaos.sh/gomakegen
Expand All @@ -17,10 +17,10 @@ all: perfecto ## Build all binaries
perfecto: ## Build perfecto binary
go build perfecto.go

install: ## Install binaries
install: ## Install all binaries
cp perfecto /usr/bin/perfecto

uninstall: ## Uninstall binaries
uninstall: ## Uninstall all binaries
rm -f /usr/bin/perfecto

git-config: ## Configure git redirects for stable import path services
Expand All @@ -29,12 +29,11 @@ git-config: ## Configure git redirects for stable import path services
deps: git-config ## Download dependencies
go get -d -v pkg.re/essentialkaos/ek.v10

deps-test: ## Download dependencies for tests
git config --global http.https://pkg.re.followRedirects true
deps-test: git-config ## Download dependencies for tests
go get -d -v pkg.re/check.v1

test: ## Run tests
go test -covermode=count ./...
go test -covermode=count ./check ./spec

fmt: ## Format source code with gofmt
find . -name "*.go" -exec gofmt -s -w {} \;
Expand All @@ -43,9 +42,10 @@ clean: ## Remove generated files
rm -f perfecto

help: ## Show this info
@echo -e '\nSupported targets:\n'
@echo -e '\n\033[1mSupported targets:\033[0m\n'
@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'

################################################################################
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<p align="center"><a href="#readme"><img src="https://gh.kaos.st/perfecto.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="https://goreportcard.com/report/github.com/essentialkaos/perfecto"><img src="https://goreportcard.com/badge/github.com/essentialkaos/perfecto"></a>
<a href="https://codebeat.co/projects/github-com-essentialkaos-perfecto-master"><img alt="codebeat badge" src="https://codebeat.co/badges/74af2307-8aa2-48eb-afd5-2ae3620a1149" /></a>
Expand All @@ -10,6 +8,10 @@
<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>

<br/>

_perfecto_ is tool for checking perfectly written RPM specs. Currently, _perfecto_ used by default for checking specs for [EK Public Repository](https://yum.kaos.st).

![Screenshot](https://gh.kaos.st/perfecto.png)
Expand Down
2 changes: 1 addition & 1 deletion check/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package check

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2009-2018 ESSENTIAL KAOS //
// Copyright (c) 2009-2019 ESSENTIAL KAOS //
// Essential Kaos Open Source License <https://essentialkaos.com/ekol> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down
9 changes: 5 additions & 4 deletions check/checkers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package check

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2009-2018 ESSENTIAL KAOS //
// Copyright (c) 2009-2019 ESSENTIAL KAOS //
// Essential Kaos Open Source License <https://essentialkaos.com/ekol> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"fmt"
"regexp"
"strings"

"pkg.re/essentialkaos/ek.v10/sliceutil"
Expand Down Expand Up @@ -216,8 +217,8 @@ func checkForNonMacroPaths(s *spec.Spec) []Alert {
text := line.Text

for _, macro := range pathMacroSlice {
if strings.Contains(text, macro.Value) {
text = strings.Replace(text, macro.Value, "", -1)
re := regexp.MustCompile(macro.Value + `(\/|$|%)`)
if re.MatchString(text) {
result = append(result, Alert{LEVEL_WARNING, fmt.Sprintf("Path \"%s\" should be used as macro \"%s\"", macro.Value, macro.Name), line})
}
}
Expand Down Expand Up @@ -295,7 +296,7 @@ func checkForDevNull(s *spec.Spec) []Alert {
for _, section := range s.GetSections(sections...) {
for _, line := range section.Data {
for _, v := range variations {
if strings.Contains(strings.Replace(line.Text, " ", "", -1), strings.Replace(v, " ", "", -1)) {
if strings.Contains(strutil.Exclude(line.Text, " "), strutil.Exclude(v, " ")) {
result = append(result, Alert{LEVEL_NOTICE, fmt.Sprintf("Use \"&>/dev/null || :\" instead of \"%s || :\"", v), line})
}
}
Expand Down
18 changes: 9 additions & 9 deletions check/checkers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package check

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2009-2018 ESSENTIAL KAOS //
// Copyright (c) 2009-2019 ESSENTIAL KAOS //
// Essential Kaos Open Source License <https://essentialkaos.com/ekol> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -96,7 +96,7 @@ func (sc *CheckSuite) TestCheckForBuildRoot(c *chk.C) {
c.Assert(alerts[0].Info, chk.Equals, "Build root path must be used as macro %{buildroot}")
c.Assert(alerts[0].Line.Index, chk.Equals, 41)
c.Assert(alerts[1].Info, chk.Equals, "Slash after %{buildroot} macro is useless")
c.Assert(alerts[1].Line.Index, chk.Equals, 46)
c.Assert(alerts[1].Line.Index, chk.Equals, 48)
}

func (sc *CheckSuite) TestCheckForDevNull(c *chk.C) {
Expand All @@ -109,15 +109,15 @@ func (sc *CheckSuite) TestCheckForDevNull(c *chk.C) {

c.Assert(alerts, chk.HasLen, 5)
c.Assert(alerts[0].Info, chk.Equals, "Use \"&>/dev/null || :\" instead of \">/dev/null 2>&1 || :\"")
c.Assert(alerts[0].Line.Index, chk.Equals, 46)
c.Assert(alerts[0].Line.Index, chk.Equals, 48)
c.Assert(alerts[1].Info, chk.Equals, "Use \"&>/dev/null || :\" instead of \"2>&1 >/dev/null || :\"")
c.Assert(alerts[1].Line.Index, chk.Equals, 47)
c.Assert(alerts[1].Line.Index, chk.Equals, 49)
c.Assert(alerts[2].Info, chk.Equals, "Use \"&>/dev/null || :\" instead of \">/dev/null 2>/dev/null || :\"")
c.Assert(alerts[2].Line.Index, chk.Equals, 48)
c.Assert(alerts[2].Line.Index, chk.Equals, 50)
c.Assert(alerts[3].Info, chk.Equals, "Use \"&>/dev/null || :\" instead of \"2>/dev/null >/dev/null || :\"")
c.Assert(alerts[3].Line.Index, chk.Equals, 49)
c.Assert(alerts[3].Line.Index, chk.Equals, 51)
c.Assert(alerts[4].Info, chk.Equals, "Use \" || :\" instead of \" || exit 0\"")
c.Assert(alerts[4].Line.Index, chk.Equals, 49)
c.Assert(alerts[4].Line.Index, chk.Equals, 51)
}

func (sc *CheckSuite) TestCheckChangelogHeaders(c *chk.C) {
Expand All @@ -130,9 +130,9 @@ func (sc *CheckSuite) TestCheckChangelogHeaders(c *chk.C) {

c.Assert(alerts, chk.HasLen, 2)
c.Assert(alerts[0].Info, chk.Equals, "Changelog record header must contain release")
c.Assert(alerts[0].Line.Index, chk.Equals, 72)
c.Assert(alerts[0].Line.Index, chk.Equals, 74)
c.Assert(alerts[1].Info, chk.Equals, "Misformatted changelog record header")
c.Assert(alerts[1].Line.Index, chk.Equals, 75)
c.Assert(alerts[1].Line.Index, chk.Equals, 77)
}

func (sc *CheckSuite) TestCheckForMakeMacro(c *chk.C) {
Expand Down
6 changes: 4 additions & 2 deletions check/rpmlint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package check

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2009-2018 ESSENTIAL KAOS //
// Copyright (c) 2009-2019 ESSENTIAL KAOS //
// Essential Kaos Open Source License <https://essentialkaos.com/ekol> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand All @@ -12,6 +12,8 @@ import (
"strconv"
"strings"

"pkg.re/essentialkaos/ek.v10/strutil"

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

Expand Down Expand Up @@ -65,7 +67,7 @@ func parseAlertLine(text string, s *spec.Spec) (Alert, bool) {

if strings.Contains(desc, "specfile-error warning") {
level = "W"
desc = strings.Replace(desc, "specfile-error warning: ", "", -1)
desc = strutil.Exclude(desc, "specfile-error warning: ")
}

desc = "[rpmlint] " + desc
Expand Down
4 changes: 2 additions & 2 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cli

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2009-2018 ESSENTIAL KAOS //
// Copyright (c) 2009-2019 ESSENTIAL KAOS //
// Essential Kaos Open Source License <https://essentialkaos.com/ekol> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand All @@ -28,7 +28,7 @@ import (
// App info
const (
APP = "Perfecto"
VER = "2.3.0"
VER = "2.3.1"
DESC = "Tool for checking perfectly written RPM specs"
)

Expand Down
4 changes: 2 additions & 2 deletions cli/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cli

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2009-2018 ESSENTIAL KAOS //
// Copyright (c) 2009-2019 ESSENTIAL KAOS //
// Essential Kaos Open Source License <https://essentialkaos.com/ekol> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -69,7 +69,7 @@ var fallbackLevel = map[uint8]string{

// renderError render error for given format
func renderError(format, file string, err error) {
filename := strings.Replace(path.Base(file), ".spec", "", -1)
filename := strutil.Exclude(path.Base(file), ".spec")

switch format {
case FORMAT_TINY:
Expand Down
2 changes: 1 addition & 1 deletion cli/render_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cli

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2009-2018 ESSENTIAL KAOS //
// Copyright (c) 2009-2019 ESSENTIAL KAOS //
// Essential Kaos Open Source License <https://essentialkaos.com/ekol> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down
2 changes: 1 addition & 1 deletion cli/render_xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cli

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2009-2018 ESSENTIAL KAOS //
// Copyright (c) 2009-2019 ESSENTIAL KAOS //
// Essential Kaos Open Source License <https://essentialkaos.com/ekol> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down
5 changes: 4 additions & 1 deletion common/perfecto.spec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

Summary: Tool for checking perfectly written RPM specs
Name: perfecto
Version: 2.3.0
Version: 2.3.1
Release: 0%{?dist}
Group: Development/Tools
License: EKOL
Expand Down Expand Up @@ -59,6 +59,9 @@ rm -rf %{buildroot}
################################################################################

%changelog
* Fri Jul 05 2019 Anton Novojilov <[email protected]> - 2.3.1-0
- Fixed bug with checking default paths without macro

* Mon Jun 10 2019 Anton Novojilov <[email protected]> - 2.3.0-0
- Added new checker for checking the number of empty lines at the end of
the spec
Expand Down
2 changes: 1 addition & 1 deletion perfecto.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2009-2018 ESSENTIAL KAOS //
// Copyright (c) 2009-2019 ESSENTIAL KAOS //
// Essential Kaos Open Source License <https://essentialkaos.com/ekol> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down
4 changes: 2 additions & 2 deletions spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package spec

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2009-2018 ESSENTIAL KAOS //
// Copyright (c) 2009-2019 ESSENTIAL KAOS //
// Essential Kaos Open Source License <https://essentialkaos.com/ekol> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -181,7 +181,7 @@ func (s *Spec) GetLine(index int) Line {

// GetFileName return spec file name without extension
func (s *Spec) GetFileName() string {
return strings.Replace(path.Base(s.File), ".spec", "", -1)
return strutil.Exclude(path.Base(s.File), ".spec")
}

// GetPackageName return package name if section is package specific
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package spec

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2009-2018 ESSENTIAL KAOS //
// Copyright (c) 2009-2019 ESSENTIAL KAOS //
// Essential Kaos Open Source License <https://essentialkaos.com/ekol> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down
2 changes: 2 additions & 0 deletions testdata/test_2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export PATH="$PATH:/usr/sbin/test"
install -pm file $RPM_BUILD_ROOT/usr/
install -pm file %{buildroot}/etc/

wget github.com/etcd-io/etcd/Documentation

%{__sed} -i -e 's|/usr/bin/traceroute|/bin/traceroute|' %{buildroot}%{_sysconfdir}/file

rm -f %{buildroot}/%{_usr}/file >/dev/null 2>&1 || :
Expand Down

0 comments on commit 05bab11

Please sign in to comment.