From 649b267f6b22d5e605a4a8a4b0cdc1c3f56a64de Mon Sep 17 00:00:00 2001
From: nathanmartinszup <63246935+nathanmartinszup@users.noreply.github.com>
Date: Thu, 10 Mar 2022 13:01:54 -0300
Subject: [PATCH] formatters/ruby:chore - removing unnecessary error messages
 (#1024)

Previously if the project had ruby between programming languages but is
not a ruby on rails project or does not have a Gemfile.lock an error
would be reported for each scenario.

This pull request changes these error messages introduced in commits
cd839ef and 9245d7d to be considered just warnings, as there is no
need to point them out as errors, since it is only intended to
inform the user.

Signed-off-by: Nathan Martins <nathan.martins@zup.com.br>
(cherry picked from commit 358fd4a5cd42118c442241155726a5dc385e0181)
---
 internal/controllers/analyzer/analyzer.go               | 5 ++++-
 internal/helpers/messages/warn.go                       | 4 +++-
 internal/services/formatters/ruby/brakeman/formatter.go | 2 +-
 internal/services/formatters/ruby/bundler/formatter.go  | 2 +-
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/internal/controllers/analyzer/analyzer.go b/internal/controllers/analyzer/analyzer.go
index f1998134f..c325370bc 100644
--- a/internal/controllers/analyzer/analyzer.go
+++ b/internal/controllers/analyzer/analyzer.go
@@ -448,9 +448,12 @@ func (a *Analyzer) removeWarningsFromErrors() {
 }
 
 // isWarning workaround to check if the message it's form a warning until the formatters are refactored
+// nolint:gocyclo // necessary complexity, but will be removed in the future
 func (a *Analyzer) isWarning(err string) bool {
 	return strings.Contains(err, messages.MsgErrorPackageLockJSONNotFound) ||
 		strings.Contains(err, messages.MsgErrorYarnLockNotFound) ||
 		strings.Contains(err, messages.MsgErrorNotFoundRequirementsTxt) ||
-		strings.Contains(err, messages.MsgWarnPathIsInvalidGitRepository)
+		strings.Contains(err, messages.MsgWarnPathIsInvalidGitRepository) ||
+		strings.Contains(err, messages.MsgWarnBrakemanNotRubyOnRailsProject) ||
+		strings.Contains(err, messages.MsgWarnGemfileIsRequiredForBundler)
 }
diff --git a/internal/helpers/messages/warn.go b/internal/helpers/messages/warn.go
index 4d7ed341b..7689c0dba 100644
--- a/internal/helpers/messages/warn.go
+++ b/internal/helpers/messages/warn.go
@@ -55,5 +55,7 @@ const (
 	// TODO: Remove MsgWarnAnalysisContainsOutdatedHash before release v2.10.0
 	MsgWarnAnalysisContainsOutdatedHash = "{HORUSEC_CLI} YOUR CONFIGURATION FILE CONTAINS SOME HASHES THAT WILL NO " +
 		"LONGER BE VALID AS OF v2.10.0 IS RELEASED. PLEASE UPDATE YOUR CONFIGURATION FILE WITH THE FOLLOWING HASHES:"
-	MsgWarnPathIsInvalidGitRepository = "{HORUSEC_CLI} The current path it's not a valid git repository"
+	MsgWarnPathIsInvalidGitRepository    = "{HORUSEC_CLI} The current path it's not a valid git repository"
+	MsgWarnBrakemanNotRubyOnRailsProject = "brakeman only works on Ruby On Rails project"
+	MsgWarnGemfileIsRequiredForBundler   = "Gemfile.lock file is required to execute Bundler analysis"
 )
diff --git a/internal/services/formatters/ruby/brakeman/formatter.go b/internal/services/formatters/ruby/brakeman/formatter.go
index af1cf31fd..3ad389f0d 100644
--- a/internal/services/formatters/ruby/brakeman/formatter.go
+++ b/internal/services/formatters/ruby/brakeman/formatter.go
@@ -42,7 +42,7 @@ const (
 	notFoundError = "please supply the path to a rails application"
 )
 
-var ErrNotFoundRailsProject = errors.New("brakeman only works on Ruby On Rails project")
+var ErrNotFoundRailsProject = errors.New(messages.MsgWarnBrakemanNotRubyOnRailsProject)
 
 type Formatter struct {
 	formatters.IService
diff --git a/internal/services/formatters/ruby/bundler/formatter.go b/internal/services/formatters/ruby/bundler/formatter.go
index 55d56fab2..29f921f3d 100644
--- a/internal/services/formatters/ruby/bundler/formatter.go
+++ b/internal/services/formatters/ruby/bundler/formatter.go
@@ -41,7 +41,7 @@ import (
 // nolint: stylecheck
 // We actually want that this error message be capitalized since the file name that was
 // not found is capitalized.
-var ErrGemLockNotFound = errors.New("Gemfile.lock file is required to execute Bundler analysis")
+var ErrGemLockNotFound = errors.New(messages.MsgWarnGemfileIsRequiredForBundler)
 
 type Formatter struct {
 	formatters.IService