Skip to content

air format <file>.R and air format --stdin-file-path <file>.R should respect exclude and default-exclude #472

@DavisVaughan

Description

@DavisVaughan

Extracted from #471

Currently if a user does

air format <file>.R

then <file>.R is unconditionally formatted, full stop, regardless of exclude and default-exclude.

This means that air format renv/activate.R would try to format renv/activate.R, even though it is part of default-exclude and should never be formatted. Similar results with any user provided excludes.

I think this is wrong!

In particular, it makes it more difficult for tools such as pre-commit and RStudio to invoke air. Those tools have no way of knowing what excludes or default-excludes are, so when a user edits or saves renv/activate.R, both of them are very likely to just call:

air format renv/activate.R

This was a problem for ruff as well, so much so that they added a special --force-exclude option that they use in their default pre-commit hook:
https://github.com/astral-sh/ruff-pre-commit/blob/1629a02ed57c23345951c75547bfe5fb73970fd3/.pre-commit-hooks.yaml#L15

For them, --force-exclude means "Respect excludes even for files provided directly on the command line".

I'd like to make the argument that we should just always respect exclude and default-exclude for files provided directly on the command line.

It seems very unlikely that a user would really want to ever run air format renv/activate.R, but there is a real problem with the fact that pre-commit (and eventually RStudio when it uses stdin) do this right now and will change these files. So I'd advocate for the safer default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions