Skip to content

Add extension mapping to configuration file options#23384

Merged
amyreese merged 5 commits intomainfrom
amy/extension-mapping-config
Feb 19, 2026
Merged

Add extension mapping to configuration file options#23384
amyreese merged 5 commits intomainfrom
amy/extension-mapping-config

Conversation

@amyreese
Copy link
Member

Issue #23204

@amyreese amyreese requested review from ntBre and removed request for ntBre February 17, 2026 22:28
@astral-sh-bot
Copy link

astral-sh-bot bot commented Feb 17, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@amyreese amyreese requested a review from ntBre February 18, 2026 02:08
@amyreese amyreese marked this pull request as ready for review February 18, 2026 02:08
fs::write(
&pyproject_toml,
r#"
[tool.ruff]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

$ 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'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few reasons:

  • It's already defined as a global value on the Configuration struct, and that value gets cloned to both the formatter and linter settings.
  • AFAICT passing --extension, even though it's arguments to check/format commands, still sets the global value before creating the final Configuration object, meaning both linter and formatter settings objects will have identical ExtensionMapping objects.
  • I believe it would be rare (and very weird) for a user to want the checker and formatter to each treat the same file/extension as a different "language".
  • I think the UX would be worse for the normal case, requiring users to duplicate this config value in two places (and make sure they stay in sync) in order to make ruff work with their custom file extensions.

Copy link
Member Author

@amyreese amyreese Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more reason: to potentially include configured file extensions in discovery, this needs to be global because the FileResolverSettings are global and file discovery happens without knowing or caring whether ruff is being run for linting or formatting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the context! I think those are reasonable 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I think the UX would be worse for the normal case, requiring users to duplicate this config value in two places (and make sure they stay in sync) in order to make ruff work with their custom file extensions.

Yeah, definitely, I didn't think of this. And, I think this use-case far outweigh duplicating it.

@dhruvmanila dhruvmanila added the configuration Related to settings and configuration label Feb 18, 2026
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me once Dhruv's concerns are resolved.

@amyreese amyreese merged commit d1b5443 into main Feb 19, 2026
42 checks passed
@amyreese amyreese deleted the amy/extension-mapping-config branch February 19, 2026 20:21
knutwannheden pushed a commit to openrewrite/ruff that referenced this pull request Feb 20, 2026
New `extension` configuration option takes a dictionary mapping custom file extensions (keys) to languages by name (values). Eg,

```toml
[tool.ruff]
extension = {qmd="markdown"}
```

Issue astral-sh#23204
amyreese added a commit that referenced this pull request Feb 25, 2026
Users can now map their preferred markdown extensions in configuration
via #23218 and #23384.

Issue #3792, #23204
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configuration Related to settings and configuration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants