From c507c6160244b4c8ebc0ef232f54358d841ec007 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Fri, 5 Jul 2019 01:42:18 +0300 Subject: [PATCH 1/3] Fixed bug with checking default paths without macro --- Makefile | 14 +++++++------- README.md | 6 ++++-- check/checkers.go | 5 +++-- check/checkers_test.go | 16 ++++++++-------- cli/cli.go | 2 +- common/perfecto.spec | 5 ++++- testdata/test_2.spec | 2 ++ 7 files changed, 29 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index d091d20..36bca0f 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 @@ -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 {} \; @@ -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' ################################################################################ diff --git a/README.md b/README.md index 7edb495..f8f60a5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@

-

InstallingUsing on TravisCIUsing with DockerUsageBuild StatusLicense

-

codebeat badge @@ -10,6 +8,10 @@

+

InstallingUsing on TravisCIUsing with DockerUsageBuild StatusLicense

+ +
+ _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) diff --git a/check/checkers.go b/check/checkers.go index 73383f0..a970ed0 100644 --- a/check/checkers.go +++ b/check/checkers.go @@ -9,6 +9,7 @@ package check import ( "fmt" + "regexp" "strings" "pkg.re/essentialkaos/ek.v10/sliceutil" @@ -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}) } } diff --git a/check/checkers_test.go b/check/checkers_test.go index f8af473..52ee503 100644 --- a/check/checkers_test.go +++ b/check/checkers_test.go @@ -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) { @@ -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) { @@ -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) { diff --git a/cli/cli.go b/cli/cli.go index fd3f300..b862180 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -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" ) diff --git a/common/perfecto.spec b/common/perfecto.spec index 86b183b..626ec22 100644 --- a/common/perfecto.spec +++ b/common/perfecto.spec @@ -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 @@ -59,6 +59,9 @@ rm -rf %{buildroot} ################################################################################ %changelog +* Fri Jul 05 2019 Anton Novojilov - 2.3.1-0 +- Fixed bug with checking default paths without macro + * Mon Jun 10 2019 Anton Novojilov - 2.3.0-0 - Added new checker for checking the number of empty lines at the end of the spec diff --git a/testdata/test_2.spec b/testdata/test_2.spec index a9c8d14..a082f18 100644 --- a/testdata/test_2.spec +++ b/testdata/test_2.spec @@ -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 || : From 2c2297eda04c78791d0b429a17790f10e06439f5 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Fri, 5 Jul 2019 01:50:07 +0300 Subject: [PATCH 2/3] Code refactoring --- check/checkers.go | 2 +- check/rpmlint.go | 4 +++- cli/render.go | 2 +- spec/spec.go | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/check/checkers.go b/check/checkers.go index a970ed0..a703640 100644 --- a/check/checkers.go +++ b/check/checkers.go @@ -296,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}) } } diff --git a/check/rpmlint.go b/check/rpmlint.go index ee589e2..91308a8 100644 --- a/check/rpmlint.go +++ b/check/rpmlint.go @@ -12,6 +12,8 @@ import ( "strconv" "strings" + "pkg.re/essentialkaos/ek.v10/strutil" + "github.com/essentialkaos/perfecto/spec" ) @@ -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 diff --git a/cli/render.go b/cli/render.go index c5c1e3c..62c5024 100644 --- a/cli/render.go +++ b/cli/render.go @@ -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: diff --git a/spec/spec.go b/spec/spec.go index f11f3fc..4bc3ea2 100644 --- a/spec/spec.go +++ b/spec/spec.go @@ -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 From 75942e876e43d7ad03046890da4331ade10613dd Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Fri, 5 Jul 2019 01:50:43 +0300 Subject: [PATCH 3/3] Updated copyright header --- check/check.go | 2 +- check/checkers.go | 2 +- check/checkers_test.go | 2 +- check/rpmlint.go | 2 +- cli/cli.go | 2 +- cli/render.go | 2 +- cli/render_json.go | 2 +- cli/render_xml.go | 2 +- perfecto.go | 2 +- spec/spec.go | 2 +- spec/spec_test.go | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/check/check.go b/check/check.go index b321cb4..bbead5c 100644 --- a/check/check.go +++ b/check/check.go @@ -2,7 +2,7 @@ package check // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2009-2018 ESSENTIAL KAOS // +// Copyright (c) 2009-2019 ESSENTIAL KAOS // // Essential Kaos Open Source License // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/check/checkers.go b/check/checkers.go index a703640..7d2320e 100644 --- a/check/checkers.go +++ b/check/checkers.go @@ -2,7 +2,7 @@ package check // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2009-2018 ESSENTIAL KAOS // +// Copyright (c) 2009-2019 ESSENTIAL KAOS // // Essential Kaos Open Source License // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/check/checkers_test.go b/check/checkers_test.go index 52ee503..c4ac0ce 100644 --- a/check/checkers_test.go +++ b/check/checkers_test.go @@ -2,7 +2,7 @@ package check // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2009-2018 ESSENTIAL KAOS // +// Copyright (c) 2009-2019 ESSENTIAL KAOS // // Essential Kaos Open Source License // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/check/rpmlint.go b/check/rpmlint.go index 91308a8..f81c22b 100644 --- a/check/rpmlint.go +++ b/check/rpmlint.go @@ -2,7 +2,7 @@ package check // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2009-2018 ESSENTIAL KAOS // +// Copyright (c) 2009-2019 ESSENTIAL KAOS // // Essential Kaos Open Source License // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/cli/cli.go b/cli/cli.go index b862180..3df233d 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -2,7 +2,7 @@ package cli // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2009-2018 ESSENTIAL KAOS // +// Copyright (c) 2009-2019 ESSENTIAL KAOS // // Essential Kaos Open Source License // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/cli/render.go b/cli/render.go index 62c5024..34c3d23 100644 --- a/cli/render.go +++ b/cli/render.go @@ -2,7 +2,7 @@ package cli // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2009-2018 ESSENTIAL KAOS // +// Copyright (c) 2009-2019 ESSENTIAL KAOS // // Essential Kaos Open Source License // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/cli/render_json.go b/cli/render_json.go index db2c488..51a3647 100644 --- a/cli/render_json.go +++ b/cli/render_json.go @@ -2,7 +2,7 @@ package cli // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2009-2018 ESSENTIAL KAOS // +// Copyright (c) 2009-2019 ESSENTIAL KAOS // // Essential Kaos Open Source License // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/cli/render_xml.go b/cli/render_xml.go index 6386765..7e279d9 100644 --- a/cli/render_xml.go +++ b/cli/render_xml.go @@ -2,7 +2,7 @@ package cli // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2009-2018 ESSENTIAL KAOS // +// Copyright (c) 2009-2019 ESSENTIAL KAOS // // Essential Kaos Open Source License // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/perfecto.go b/perfecto.go index 92090e9..ce4cf55 100644 --- a/perfecto.go +++ b/perfecto.go @@ -2,7 +2,7 @@ package main // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2009-2018 ESSENTIAL KAOS // +// Copyright (c) 2009-2019 ESSENTIAL KAOS // // Essential Kaos Open Source License // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/spec/spec.go b/spec/spec.go index 4bc3ea2..e4437ff 100644 --- a/spec/spec.go +++ b/spec/spec.go @@ -2,7 +2,7 @@ package spec // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2009-2018 ESSENTIAL KAOS // +// Copyright (c) 2009-2019 ESSENTIAL KAOS // // Essential Kaos Open Source License // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/spec/spec_test.go b/spec/spec_test.go index 664a37f..db6007f 100644 --- a/spec/spec_test.go +++ b/spec/spec_test.go @@ -2,7 +2,7 @@ package spec // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2009-2018 ESSENTIAL KAOS // +// Copyright (c) 2009-2019 ESSENTIAL KAOS // // Essential Kaos Open Source License // // // // ////////////////////////////////////////////////////////////////////////////////// //