-
-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What's the best practice for a linter's custom args in CLI call to process the listed files for linting ? #3000
Comments
I'm not sure to fully understand your question, but I understand it relates to the Usually a linter is configured by its descriptor. Here, ruff was defined in the https://github.com/oxsecurity/megalinter/blob/7e19651f1b8c0d67a0332fadf9d45b1c49d95c69/megalinter/descriptors/python.megalinter-descriptor.yml file, near the end. Usually, the argument is defined there, and Megalinter adds the list of files (already filtered, applying rules to include exclude files, so the search for all files is only done once for all the linters). I don't remember if it is possible to override every field from the descriptor as an runtime variable, you could check it out. When a linter is too complex to handle using these, then a Python class is used to interface the linter. I think what you're trying to do is integrate the ruff tool as a formater instead of a linter, that isn't officially announced yet. Look at this PR for the updates of their docs, since the latest published docs don't apply yet for this mode. I'm not sure we had another linter that works in that way yet, so that change might be harder than usual to make use of. The problems I expect to arise include, "will the |
Since |
Hi @echoix thanks for the feedback, My intention is to format files using the "ruff format" on the list_of_files, as "ruff format" (as of now) works either by specifying a file path or dir path. In the local run, I was able to do that with "ruff format '/tmp/lint' ", where that's the dir for list_of_files (?) In GitHub Actions that's a different story as the workspace now is the repo itself, hence '/tmp/lint' isn't found (again based on my tests.) . So that was the obstacle.
Correct.
Valid questions. As of now, it seems both formatting and fix args in one command line not working as expected. I think the formula that I reached so far is, formatting, then fixing, is decent (I benchmarked the errors post-formatting-fixing with flake8 errors so I'm satisfied with the result.) |
That's what I expected at first, however ruff (as of now) expects either a file path or dir to format. So "format" alone will throw errors. However, I found a workaround with PYTHON_RUFF_PRE_COMMANDS :
Closing this issue as I believe I found my answer, yet feel free to discuss it further if it can be improved. |
As MegaLinter doesn't specifically support running the same linter twice, my understanding is that it behaves as expected currently. Your workaround seems reasonable and creative. Other approaches would be to run
If you can reproduce that at the latest version of |
@fawazsalah very creative workaround indeed, congrats :) |
For example in Ruff linter with its "format" feature, I'd like to call:
PYTHON_RUFF_ARGUMENTS: "format 'Dir/ListedFilesForLint/' "
I'm not referring to the workspace/repo dirs, rather than to the files detected by MegaLinter.
The text was updated successfully, but these errors were encountered: