Bug: CSS_STYLELINT_COMMAND_REMOVE_ARGUMENTS cannot remove --config-basedir
Environment
MegaLinter: 9.6.0
Stylelint: 17.14.0
Summary
StyleLintLinter unconditionally appends --config-basedir /node-deps to the Stylelint command.
However, CSS_STYLELINT_COMMAND_REMOVE_ARGUMENTS cannot be used to remove this argument because the argument is appended after the base linter has already processed the removal list. Attempting to remove it results in a Python exception.
Steps to reproduce
Configure MegaLinter with:
CSS_STYLELINT_COMMAND_REMOVE_ARGUMENTS: --config-basedir
Actual behaviour
Traceback (most recent call last):
...
File "/megalinter/Linter.py", line 1497, in build_lint_command
cmd.remove(arg)
ValueError: list.remove(x): x not in list
Expected behaviour
One of the following should happen:
CSS_STYLELINT_COMMAND_REMOVE_ARGUMENTS successfully removes --config-basedir, or
missing arguments are ignored instead of raising ValueError.
At a minimum, the command removal feature should not crash when an argument is absent.
Root cause
From the current implementation:
class StyleLintLinter(Linter):
def build_lint_command(self, file=None) -> list:
cmd = super().build_lint_command(file)
if os.path.isdir(NODE_DEPS_DIR):
cmd += ["--config-basedir", NODE_DEPS_DIR]
return cmd
super().build_lint_command() is where CSS_STYLELINT_COMMAND_REMOVE_ARGUMENTS is processed.
--config-basedir is appended afterwards, so it is impossible for users to remove it using the documented configuration option.
Additional context
The reason I wanted to remove --config-basedir is that it changes Stylelint's behaviour.
With the same Stylelint configuration:
pnpm exec stylelint
--config stylelint.config.js
"apps/z_archive/**/*.{css,scss}"
my overrides.files glob matches correctly.
However, adding only --config-basedir /tmp causes the same overrides.files glob to stop matching.
This appears to be a Stylelint issue, but because MegaLinter always injects --config-basedir there is currently no way to work around it using CSS_STYLELINT_COMMAND_REMOVE_ARGUMENTS.
Suggested fixes
Possible solutions include:
Apply CSS_STYLELINT_COMMAND_REMOVE_ARGUMENTS after descriptor-specific arguments have been added.
Make cmd.remove() tolerant of missing arguments.
Make --config-basedir optional or configurable for the Stylelint descriptor.
Bug: CSS_STYLELINT_COMMAND_REMOVE_ARGUMENTS cannot remove --config-basedir
Environment
MegaLinter: 9.6.0
Stylelint: 17.14.0
Summary
StyleLintLinter unconditionally appends
--config-basedir /node-depsto the Stylelint command.However, CSS_STYLELINT_COMMAND_REMOVE_ARGUMENTS cannot be used to remove this argument because the argument is appended after the base linter has already processed the removal list. Attempting to remove it results in a Python exception.
Steps to reproduce
Configure MegaLinter with:
CSS_STYLELINT_COMMAND_REMOVE_ARGUMENTS: --config-basedir
Actual behaviour
Traceback (most recent call last):
...
File "/megalinter/Linter.py", line 1497, in build_lint_command
cmd.remove(arg)
ValueError: list.remove(x): x not in list
Expected behaviour
One of the following should happen:
CSS_STYLELINT_COMMAND_REMOVE_ARGUMENTS successfully removes --config-basedir, or
missing arguments are ignored instead of raising ValueError.
At a minimum, the command removal feature should not crash when an argument is absent.
Root cause
From the current implementation:
super().build_lint_command() is where CSS_STYLELINT_COMMAND_REMOVE_ARGUMENTS is processed.
--config-basedir is appended afterwards, so it is impossible for users to remove it using the documented configuration option.
Additional context
The reason I wanted to remove
--config-basediris that it changes Stylelint's behaviour.With the same Stylelint configuration:
pnpm exec stylelint
--config stylelint.config.js
"apps/z_archive/**/*.{css,scss}"
my overrides.files glob matches correctly.
However, adding only
--config-basedir /tmpcauses the same overrides.files glob to stop matching.This appears to be a Stylelint issue, but because MegaLinter always injects
--config-basedirthere is currently no way to work around it using CSS_STYLELINT_COMMAND_REMOVE_ARGUMENTS.Suggested fixes
Possible solutions include:
Apply CSS_STYLELINT_COMMAND_REMOVE_ARGUMENTS after descriptor-specific arguments have been added.
Make cmd.remove() tolerant of missing arguments.
Make --config-basedir optional or configurable for the Stylelint descriptor.