Skip to content

Commit

Permalink
Note about risky rules and how to fix rule violations with PHP-CS-F…
Browse files Browse the repository at this point in the history
…ixer (#4249)

* a note about risky rules and how to fix rule violations with PHP-CS-Fixer

* [MegaLinter] Apply linters fixes

---------

Co-authored-by: llaville <[email protected]>
  • Loading branch information
llaville and llaville authored Nov 11, 2024
1 parent a01f80f commit 630c0ea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
5 changes: 5 additions & 0 deletions megalinter/descriptors/php.megalinter-descriptor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ linters:
# PHP-CS-Fixer
- linter_name: php-cs-fixer
name: PHP_PHPCSFIXER
linter_text: |
PHP-CS-Fixer is able to fix rule violations detected, and even those marked as (risky)
- Enable **autofixes** by adding `PHP_PHPCSFIXER` in [APPLY_FIXES variable](https://megalinter.io/beta/configuration/#apply-fixes)
- Add "--allow-risky=yes" option in PHP_PHPCSFIXER_ARGUMENTS variable
linter_url: https://cs.symfony.com/
linter_repo: https://github.com/PHP-CS-Fixer/PHP-CS-Fixer
linter_image_url: https://cs.symfony.com/_static/images/logo.png
Expand Down
23 changes: 15 additions & 8 deletions megalinter/reporters/UpdatedSourcesReporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import logging
import os
import shutil

import chalk as c
import git

from megalinter import Reporter, config, utils


Expand Down Expand Up @@ -87,16 +87,23 @@ def produce_report(self):
)
else:
try:
repo = git.Repo(os.path.realpath(self.master.github_workspace))
repo.config_writer().set_value("user", "name", "MegaLinter").release()
repo.config_writer().set_value("user", "email", "[email protected]").release()
repo = git.Repo(
os.path.realpath(self.master.github_workspace)
)
repo.config_writer().set_value(
"user", "name", "MegaLinter"
).release()
repo.config_writer().set_value(
"user", "email", "[email protected]"
).release()
repo.git.add(update=True)
repo.git.commit('-m', '[MegaLinter] Apply linters fixes')
repo.git.push('origin', f'HEAD:{remote_branch}')
repo.git.commit("-m", "[MegaLinter] Apply linters fixes")
repo.git.push("origin", f"HEAD:{remote_branch}")
except git.GitCommandError as git_err:
logging.error(
c.red(
"❌ [Updated Sources Reporter] Failed to git push auto fixes: " + str(git_err.stderr)
"❌ [Updated Sources Reporter] Failed to git push auto fixes: "
+ str(git_err.stderr)
)
)
logging.warning(
Expand All @@ -107,7 +114,7 @@ def produce_report(self):
)
else:
logging.info(
"[Updated Sources Reporter] Fixed source files have automatically "
"[Updated Sources Reporter] Fixed source files have automatically "
"been pushed to the source branch"
)
else:
Expand Down

0 comments on commit 630c0ea

Please sign in to comment.