Your Task
1. Implement a Python script analyze.py
The script should:
- Find all
.py
files in the src/
directory.
- Detects the following types of violations:
Violations to Detect:
- Line Length Violation:
Any line exceeding 80 characters (excluding trailing whitespace).
- Forbidden Keywords:
Use of any of the following: print
, eval
, or exec
.
These must be ignored if they appear in:
- Full-line comments (lines starting with
#
)
- Inline comments (i.e., anything after
#
)
- Unclosed String Literals:
Detect unclosed '
or "
string literals in any line.
2. Classify each file
Based on the number and type of violations:
CLEAN
: 0 violations
LOW RISK
: 1-5 violations and no forbidden keywords
HIGH RISK
: more than 5 violations or any forbidden keyword used (even once)
3. Output format
One line per file:
<file_path>: CLEAN / LOW RISK / HIGH RISK
Example:
src/file1.py: HIGH RISK
src/file2.py: CLEAN
src/file3.py: LOW RISK
4. Create a GitHub Actions workflow
It should:
- Trigger on every push and pull request
- Automatically run
analyze.py
- Print the results of your analysis in the CI logs