Skip to content

Add a write_changes flag - #112

Open
TheGiraffe3 wants to merge 8 commits into
codespell-project:masterfrom
TheGiraffe3:allow-writes
Open

TheGiraffe3 wants to merge 8 commits into
codespell-project:masterfrom
TheGiraffe3:allow-writes

Conversation

@TheGiraffe3

@TheGiraffe3 TheGiraffe3 commented Oct 13, 2026 •

Copy link
Copy Markdown

This is the equivalent of specifying -w with the original codespell.
Feedback welcome.

related: #68

@larsoner

Copy link
Copy Markdown
Member

Seems reasonable to me, but a test and README update would be good

@TheGiraffe3

Copy link
Copy Markdown
Author

Added a test. README update was already done

@larsoner

Copy link
Copy Markdown
Member

Okay, thinking more about this and how actions like this (pre-commit, prek, etc.) normally operate, the action typically fails if it makes changes. I think we should probably do the same. So maybe in write mode we should do:

  1. A normal dry run, unchanged. Fixed typos then show up as annotations, which is useful because they show what was changed.
  2. A second run with --write-changes to apply the fixes, with its stdout sent to /dev/null. Otherwise every misspelling is reported twice and gets duplicate annotations. As a bonus, -w prints the fixed lines indented ( path:1: x ==> y), and the default matcher regex ^(.+):(\d+): would capture those leading spaces as part of the file path.

And longer-term, we update codespell to optionally allow returning non-zero exit code in -w mode, then things can be simplified here if desired.

@TheGiraffe3

Copy link
Copy Markdown
Author

If we're deleting output of the second run, it doesn't print the fixed lines. Should we be sending that to stdout too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants