-1

Given a large, legacy Python codebase in GitLab, it is unreasonable to fail the CI/CD pipeline on flake8 violations, because solving problems in such an amount of legacy code would completely stall development. Is there instead a way to configure the "code quality" CI/CD pipeline for it to fail on added flake8 violations (or another free static code analyzer), so as to ensure ongoing development improves code rather than degrades it? Thanks!

GabCaz
  • 99
  • 1
  • 11

1 Answers1

0

The more important is the number of violations in the new code.

If your flake8 report is like

flake8                          
.\main.py:4:1: E302 expected 2 blank lines, found 1
.\main.py:4:4: E271 multiple spaces after keyword
.\main.py:4:14: E203 whitespace before ':'
.\main.py:5:3: E111 indentation is not a multiple of 4
.\main.py:7:1: E302 expected 2 blank lines, found 1
.\main.py:7:4: E271 multiple spaces after keyword
.\main.py:7:20: E203 whitespace before ':'
.\main.py:8:3: E111 indentation is not a multiple of 4
.\main.py:8:11: W291 trailing whitespace
.\main.py:8:13: W292 no newline at end of file

Analyzing only a diff with the legacy code. Add a git tag 'legacy' on the legacy base.

git diff -U0 legacy                  
diff --git a/main.py b/main.py
index 39722c7..aeff3ad 100755
--- a/main.py
+++ b/main.py
@@ -5 +5,4 @@ def  Test11() :
-  return 5
\ No newline at end of file
+  return 5
+
+def  TestNewCode()  :
+  return 5  
\ No newline at end of file

and compute violations only on the diff with that tag.

git diff -U0 legacy | flake8 --diff - 
main.py:5:3: E111 indentation is not a multiple of 4
main.py:7:1: E302 expected 2 blank lines, found 1
main.py:7:4: E271 multiple spaces after keyword
main.py:7:20: E203 whitespace before ':'
main.py:8:3: E111 indentation is not a multiple of 4
main.py:8:11: W291 trailing whitespace
main.py:8:13: W292 no newline at end of file
Youen
  • 41
  • 3