Skip to content

Commit

Permalink
fix for issue #3963
Browse files Browse the repository at this point in the history
  • Loading branch information
llaville committed Sep 10, 2024
1 parent 64261ae commit fb1510a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .automation/test/php/.mega-linter.yml.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ENABLE:
- PHP
DISABLE_LINTERS:
- PHP_PSALM
- PHP_PHPLINT
- PHP_PHPCS
- PHP_PHPSTAN
LOG_LEVEL: debug
PARALLEL: false
UPDATED_SOURCES_REPORTER: true
APPLY_FIXES: PHP_PHPCSFIXER
PHP_PHPCSFIXER_CONFIG_FILE: .php-cs-fixer.risky.php
PHP_PHPCSFIXER_ARGUMENTS:
- "--allow-risky=yes"
- "--diff"
13 changes: 13 additions & 0 deletions .automation/test/php/.php-cs-fixer.risky.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in('.')
;

return (new PhpCsFixer\Config())
->setRules([
'@PER-CS' => true,
'@PhpCsFixer:risky' => true,
])
->setFinder($finder)
;
3 changes: 3 additions & 0 deletions .automation/test/php/php_fix_1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$x[] = $y;
6 changes: 5 additions & 1 deletion megalinter/Linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ def __init__(self, params=None, linter_config=None):
# No fixing config on linter descriptor
if self.cli_lint_fix_arg_name is None:
self.apply_fixes = False
if len(self.cli_lint_fix_remove_args) == 0:
self.apply_fixes = False
# APPLY_FIXES is "all"
elif param_apply_fixes == "all" or (
isinstance(param_apply_fixes, bool) and param_apply_fixes is True
Expand Down Expand Up @@ -1260,12 +1262,14 @@ def build_lint_command(self, file=None) -> list:
# Add fix argument if defined
if self.apply_fixes is True and (
self.cli_lint_fix_arg_name is not None
or len(self.cli_lint_fix_remove_args) > 0
or str(self.cli_executable_fix) != str(self.cli_executable)
):
args_pos = len(self.cli_executable)
cmd = cmd[args_pos:] # Remove executable elements
cmd = self.cli_executable_fix + cmd
cmd += [self.cli_lint_fix_arg_name]
if self.cli_lint_fix_arg_name is not None:
cmd += [self.cli_lint_fix_arg_name]
self.try_fix = True

# Add user-defined extra arguments if defined
Expand Down

0 comments on commit fb1510a

Please sign in to comment.