CPY001: Make diagnostic fixable (flake8_copyright)
I would like to propose making CPY001 (flake8_copyright) fixable. This would be a new feature, as the functionality is not available in the original. The main motivating factors are that as far as I can see, fixing the diagnostic is relatively straightforward, and it would increase the utility of the rule. For example, in the company I am working for, we have our own pre-commit hook that automatically adds the copyright notice if necessary.
In my proposal, a new setting would be added alongside author, notice_rgx and min_file_size: notice_tpl (notice template). It would default to Copyright (C) {year}, where {year} is a special placeholder that will be replaced by the current year.
There are two relevant cases for fixing the diagnostic:
- The notice is missing altogether. In this case, it would simply be generated and inserted based on
notice_tpl. If the generated notice does not matchnotice_rgx, an error would be logged viaerror!and the fix would be skipped. - There is a notice, but
authorwas specified and is missing at the end of the notice. In this case, the author would be inserted in the appropriate position.
Is there interest in fixing CPY001? If so, does this proposal make sense?
I have a working proof of concept. If there is interest, I could work on a pull request.
Related issue https://github.com/astral-sh/ruff/issues/5306
Is there anything I can do to help with the decision?
I'd love to see an auto-fix in place for this, as it would save us tons of time in making sure we are compliant with CPY1 - especially for codebases we are migrating, and for accepting contributions from community members who aren't going to know our spec for license requirements and what text to input.
X-posted from #5306:
+1 to this request. And to raise an alternative more generic implementation - which would be "file_starts_with" customization.
This variant would allow auto-fixing of CPY1 indirectly, but with an approach more generic. The generic implementation would allow Ruff to check for (and auto-fix) a mandatory pre-amble for each python file.