diff --git a/README.md b/README.md index 83144165ef8..48b0616aab4 100644 --- a/README.md +++ b/README.md @@ -658,6 +658,7 @@ Configuration is assisted with auto-completion and validation in most commonly u |------------------------------------------------------------|------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | **ADDITIONAL_EXCLUDED_DIRECTORIES** | \[\] | List of additional excluded directory basenames. They are excluded at any nested level. | | [**APPLY_FIXES**](#apply-fixes) | `none` | Activates formatting and auto-fixing [(more info)](#apply-fixes) | +| **CLEAR_REPORT_FOLDER** | `false` | Flag to clear files from report folder (usually megalinter-reports) before starting the linting process | | **DEFAULT_BRANCH** | `HEAD` | Deprecated: The name of the repository's default branch. | | **DEFAULT_WORKSPACE** | `/tmp/lint` | The location containing files to lint if you are running locally. | | **DISABLE_ERRORS** | `false` | Flag to have the linter complete with exit code 0 even if errors were detected. | diff --git a/megalinter/MegaLinter.py b/megalinter/MegaLinter.py index 3f7e236e13a..01a4b051b80 100644 --- a/megalinter/MegaLinter.py +++ b/megalinter/MegaLinter.py @@ -8,6 +8,7 @@ import logging import multiprocessing as mp import os +import shutil import sys import chalk as c @@ -677,6 +678,10 @@ def initialize_output(self): self.report_folder = self.arg_output # Initialize output dir os.makedirs(self.report_folder, exist_ok=True) + # Clear report folder if requested + if config.get("CLEAR_REPORT_FOLDER", "false") == "true": + shutil.rmtree(self.report_folder) + logging.debug(f"Emptied report folder {self.report_folder}") def initialize_logger(self): logging_level_key = config.get("LOG_LEVEL", "INFO").upper()