Skip to content

Commit

Permalink
Manage FAIL_IF_UPDATED_SOURCES option
Browse files Browse the repository at this point in the history
  • Loading branch information
nvuillam committed Apr 13, 2022
1 parent 5cc0765 commit 6250e4e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .automation/generated/megalinter-users.json
Original file line number Diff line number Diff line change
Expand Up @@ -8332,6 +8332,9 @@
},
"repo_url": "https://github.com/thomaseolsen/archaeology_rust_api",
"stargazers": 0
},
{
"repo_url": "https://github.com/theodore-s-beers/muqawwim"
}
]
}
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ Configuration is assisted with auto-completion and validation in most commonly u
| **EXCLUDED_DIRECTORIES** | \[...many values...\] | List of excluded directory basenames. They are excluded at any nested level. |
| **EXTENDS** | <!-- --> | Base `mega-linter.yml` config file(s) to extend local configuration from. Can be a single URL or a list of `.mega-linter.yml` config files URLs |
| **FAIL_IF_MISSING_LINTER_IN_FLAVOR** | `false` | If set to `true`, MegaLinter fails if a linter is missing in the selected flavor |
| **FAIL_IF_UPDATED_SOURCES** | `false` | If set to `true`, MegaLinter fails if a linter or formatter has auto-fixed sources, even if there are no errors |
| [**FILTER_REGEX_EXCLUDE**](#filter-linted-files) | `none` | Regular expression defining which files will be excluded from linting [(more info)](#filter-linted-files) .ex: `.*src/test.*`) |
| [**FILTER_REGEX_INCLUDE**](#filter-linted-files) | `all` | Regular expression defining which files will be processed by linters [(more info)](#filter-linted-files) .ex: `.*src/.*`) |
| **FLAVOR_SUGGESTIONS** | `true` | Provides suggestions about different MegaLinter flavors to use to improve runtime performances |
Expand Down
10 changes: 10 additions & 0 deletions megalinter/MegaLinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def __init__(self, params=None):
self.return_code = 0
self.has_git_extraheader = False
self.has_updated_sources = 0
self.fail_if_updated_sources = (
config.get("FAIL_IF_UPDATED_SOURCES", "false") == "true"
)
self.flavor_suggestions = None
# Initialize plugins
plugin_factory.initialize_plugins()
Expand Down Expand Up @@ -635,11 +638,13 @@ def check_results(self):
if self.status == "success":
logging.info(c.green("✅ Successfully linted all files without errors"))
config.delete()
self.check_updated_sources_failure()
elif self.status == "warning":
logging.warning(
c.yellow("◬ Successfully linted all files, but with ignored errors")
)
config.delete()
self.check_updated_sources_failure()
else:
logging.error(c.red("❌ Error(s) have been found during linting"))
logging.warning(
Expand All @@ -656,6 +661,11 @@ def check_results(self):
sys.exit(self.return_code)
config.delete()

def check_updated_sources_failure(self):
if self.has_updated_sources > 0 and self.fail_if_updated_sources is True:
logging.error(c.red("❌ Sources has been updated by linter auto-fixes, and FAIL_IF_UPDATED_SOURCES has been set to true"))
sys.exit(1)

def before_exit(self):
# Clean git repository
self.manage_clean_git_repo()
Expand Down

0 comments on commit 6250e4e

Please sign in to comment.