Repository: astral-sh/ruff
File: crates/ruff/tests/integration_test.rs (Rust)

Code before:
    success: false
    exit_code: 1
    ----- stdout -----
    F401 [*] `os` imported but unused
     --> F401.ipynb:1:8
      |
    1 | import os
      |        ^^
      |
    help: Remove unused import: `os`

    Found 1 error.
    [*] 1 fixable with the `--fix` option.

    ----- stderr -----
    ");
}

#[test]
fn stdin_override_parser_py_config() -> Result<()> {
    let tempdir = TempDir::new()?;
    let pyproject_toml = tempdir.path().join("pyproject.toml");
    fs::write(
        &pyproject_toml,
        r#"
[tool.ruff]
extension = {"ipynb"="python"}
"#,
    )?;
    let mut cmd = RuffCheck::default()
        .config(&pyproject_toml)
        .args(["--stdin-filename", "F401.ipynb"])
        .build();
    assert_cmd_snapshot!(cmd
        .pass_stdin("import os\n"), @"
    success: false
    exit_code: 1
    ----- stdout -----
    F401 [*] `os` imported but unused
     --> F401.ipynb:1:8
      |
    1 | import os
      |        ^^
      |
    help: Remove unused import: `os`

    Found 1 error.
    [*] 1 fixable with the `--fix` option.

    ----- stderr -----
    ");

Review comment (suggestion):
Can you say a bit more about why this is a global option? I think it should be scoped to the linter and the formatter such that it can be configured individually for `tool.ruff.lint` and `tool.ruff.format`. The CLI option is also scoped to individual subcommands.

```console
$ ruff check --extension ipynb:python ~/playground/ruff/notebooks/extension.ipynb 
I002 [*] Missing required import: `from __future__ import annotations`
--> /Users/dhruv/playground/ruff/notebooks/extension.ipynb:1:1
help: Insert required import: `from __future__ import annotations`

F401 [*] `os` imported but unused
 --> /Users/dhruv/playground/ruff/notebooks/extension.ipynb:1:8
  |
1 | import os
  |        ^^
  |
help: Remove unused import: `os`

Found 2 errors.
[*] 2 fixable with the `--fix` option.

$ ruff --extension ipynb:python check ~/playground/ruff/notebooks/extension.ipynb
error: unexpected argument '--extension' found

  tip: 'check --extension' exists

Usage: ruff [OPTIONS] <COMMAND>

For more information, try '--help'.
```

Code after:
    success: false
    exit_code: 1
    ----- stdout -----
    F401 [*] `os` imported but unused
     --> F401.ipynb:1:8
      |
    1 | import os
      |        ^^
      |
    help: Remove unused import: `os`

    Found 1 error.
    [*] 1 fixable with the `--fix` option.

    ----- stderr -----
    ");
}

#[test]
fn stdin_override_parser_py_config() -> Result<()> {
    let tempdir = TempDir::new()?;
    let pyproject_toml = tempdir.path().join("pyproject.toml");
    fs::write(
        &pyproject_toml,
        r#"
[tool.ruff]
extension = {ipynb="python"}
"#,
    )?;
    let mut cmd = RuffCheck::default()
        .config(&pyproject_toml)
        .args(["--stdin-filename", "F401.ipynb"])
        .build();
    assert_cmd_snapshot!(cmd
        .pass_stdin("import os\n"), @"
    success: false
    exit_code: 1
    ----- stdout -----
    F401 [*] `os` imported but unused
     --> F401.ipynb:1:8
      |
    1 | import os
      |        ^^
      |
    help: Remove unused import: `os`

    Found 1 error.
    [*] 1 fixable with the `--fix` option.

    ----- stderr -----
    ");