Skip to content
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

Unable to parse '.ruff.toml' when configured for Ruff linter. #2995

Closed
fawazsalah opened this issue Oct 9, 2023 · 9 comments
Closed

Unable to parse '.ruff.toml' when configured for Ruff linter. #2995

fawazsalah opened this issue Oct 9, 2023 · 9 comments
Labels
bug Something isn't working

Comments

@fawazsalah
Copy link

Describe the bug
A clear and concise description of what the bug is.

I configured '.ruff.toml' with additional parameters for Ruff linter, and when running locally or GHA I encounter parsing error:

--Error detail:
<jemalloc>: MADV_DONTNEED does not work (memset will be used instead)
<jemalloc>: (This is the expected behaviour if you are running under QEMU)
ruff failed
  Cause: Failed to parse `/tmp/lint/.ruff.toml`: TOML parse error at line 1, column 1
  |
1 | [format]
  | ^^^^^^^^
wanted exactly 1 element, more than 1 element

To Reproduce
Steps to reproduce the behavior:

  1. enable Ruff linter and Create .ruff.toml
  2. Provide the following parameters in .ruff.toml:
[format]
indent-style = "tab"
quote-style = "single"
  1. Run locally 'mega-linter-runner --flavor python' (or) via GH Actions.
  2. See error:
--Error detail:
<jemalloc>: MADV_DONTNEED does not work (memset will be used instead)
<jemalloc>: (This is the expected behaviour if you are running under QEMU)
ruff failed
  Cause: Failed to parse `/tmp/lint/.ruff.toml`: TOML parse error at line 1, column 1
  |
1 | [format]
  | ^^^^^^^^
wanted exactly 1 element, more than 1 element

Expected behavior
Script expected to be tab indented and quote style be single quote.

Screenshots
N/A

Additional context
When running Ruff as-is it works well with:

ruff format "myScript.py"

Megalinter's ruff ver :

 "ruff": "0.0.291",

My local Stand-alone Ruff ver: ruff 0.0.291

Python flavor: oxsecurity/megalinter/flavors/[email protected]

@fawazsalah fawazsalah added the bug Something isn't working label Oct 9, 2023
@echoix
Copy link
Collaborator

echoix commented Oct 9, 2023

I'm not completely sure how it could come from a Megalinter problem. Could you test locally, or with GitHub actions to use ruff directly to see if it happens without Megalinter involved? I look through ruff's issues and didn't find something related.

The two jemalloc warning lines are unrelated to your problem, see astral-sh/ruff#3088

I also looked at the docs for ruff, and you don't seem to have made an error in theory. So if there is a problem that happens even with only ruff, I encourage you to copy your nice and simple bug report issue to the ruff's repo, since your reproduction steps are easy to follow.

Following the error message, I would also test your reproduction steps, but keeping only the [format] and either the indent-style line or the quote-style line (one at a time). If that makes it work, that's a serious ruff bug or regression.

Since the message also talks about being at the first line, first column, I might also want to check the text encoding of your file, for example, if there is a BOM in a UTF-8 with BOM encoding, or if it's UTF-8 or something else. If you are on Windows, I usually use Notepad++ for quickly checking this. If it is UTF-8 with BOM that fails, and saved as UTF-8 (only, without BOM) works, that's another bug to file, and I might try to adding something else, like comments or extra empty lines before, so the first parsed section doesn't include the BOM.

Hope that helps you investigate, and come back to us! If with the extra tests it turns out it is really MegaLinter involved, we'll take a deeper look as it seems an important issue. (I know the formatting support of Rust is new and was only in alpha last month, see astral-sh/ruff#7310)

@Kurt-von-Laven
Copy link
Collaborator

Since the error occurs when running Ruff through MegaLinter but not when running Ruff directly, and MegaLinter v7.4.0 is on Ruff 0.0.290, I would try running Ruff directly at 0.0.290.

@fawazsalah
Copy link
Author

Since the error occurs when running Ruff through MegaLinter but not when running Ruff directly, and MegaLinter v7.4.0 is on Ruff 0.0.290, I would try running Ruff directly at 0.0.290.

Thanks @Kurt-von-Laven and @echoix for the support.

Bingo Good catch; I can confirm similar error with 0.0.290 locally.

However I can see in the change logs linter upgrades that Ruff was upgradeed from 0.0290 to 0.0.291, but seems still on 0.0.290 in MegaLinter:

- Linter versions upgrades
  - [cfn-lint](https://github.com/aws-cloudformation/cfn-lint) from 0.80.2 to **0.80.3** on 2023-09-24
  - [eslint](https://eslint.org) from 8.49.0 to **8.50.0** on 2023-09-24
  - [ruff](https://github.com/charliermarsh/ruff) from 0.0.290 to **0.0.291** on 2023-09-24
  - [trufflehog](https://github.com/trufflesecurity/trufflehog) from 3.56.1 to **3.57.0** on 2023-09-24
  - [pylint](https://pylint.pycqa.org) from 2.17.5 to **2.17.6** on 2023-09-26

@nvuillam can we check and bump ruff version to the latest 0.0.292 , as 0.0.290 was released on Sep 15, 2023 and 0.0.292 was on released on Oct 2, 2023 ?

@Kurt-von-Laven
Copy link
Collaborator

You can try out the MegaLinter beta release for Ruff 0.0.291, try configuring Ruff via pyproject.toml, or look into the BOM issue. There is automation that keeps the linter versions up-to-date with each MegaLinter update, so probably not worth worrying about unless a specific linter falls further behind.

@echoix
Copy link
Collaborator

echoix commented Oct 10, 2023

I looked at the release notes, and there some changes in 0.292 and 0.291 that relate to format, experimental linting and the configuration settings for these. So that's why I wanted to know with what version you ran locally, and didn't emphasize to use a beta Megalinter release, since at 0.290 I didn't see why it wouldn't work. But I think I saw commits yesterday that we are about to include 0.292 for the next Megalinter release.

@fawazsalah
Copy link
Author

I looked at the release notes, and there some changes in 0.292 and 0.291 that relate to format, experimental linting and the configuration settings for these. So that's why I wanted to know with what version you ran locally, and didn't emphasize to use a beta Megalinter release, since at 0.290 I didn't see why it wouldn't work. But I think I saw commits yesterday that we are about to include 0.292 for the next Megalinter release.

Yes as I documented above locally I used ruff 0.0.291 in sync with MegaLinter's 0.0.291, however as @Kurt-von-Laven confirmed MegaLinter uses 0.0.290. I'm certainly not in a rush with the beta, so I'm looking forward to the Sable release and wanted to tinker more with the Ruff formatting for my specific needs.

@echoix
Copy link
Collaborator

echoix commented Oct 10, 2023

Ok, so the result of astral-sh/ruff#7899 is that the format section was only recently added, and is supported from ruff version 0.291+, probably working correctly in 0.292.

So since that new version isn't in the latest Megalinter release, you could use the beta version (with your same flavor) waiting for the next Megalinter release. The Megalinter beta has 0.291, and 0.292 is still in #2988

@echoix echoix closed this as completed Oct 10, 2023
@nvuillam
Copy link
Member

@fawazsalah we currently have some issues with KICS so we can't make a new release of MegaLinter until it's solved, but it should be soon :)

Meanwhile you can use PRE_COMMANDS to upgrade ruff before running it :)

@fawazsalah
Copy link
Author

@nvuillam I updated Ruff with PRE_COMMANDS and worked well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants