reuse-tool icon indicating copy to clipboard operation
reuse-tool copied to clipboard

`--style` setting works incorrectly with `UncommentableCommentStyle`

Open pepijndevos opened this issue 2 years ago • 4 comments

I have some SVG files where I want to use HTML style comments rather than license files. Passing --style html just seems to put HTML-style comments in the license file.

This both doesn't make sense and doesn't allow any way to use a HTML-style header comment.

A simple solution would be to change SVG to HtmlCommentStyle but that's apparently undesirable for machine-generated SVG files, so a slightly more complex solution is needed.

You'd want to avoid accidentally adding a license header to a JPEG though, which could happen if the tool honored the --style parameter regardless if the file is an actual binary file, or just a file where a comment header is normally not desired. So the tool needs to be able to distinguish between these cases.

pepijndevos avatar Apr 28 '22 13:04 pepijndevos

Phew, in order to make that work we'd need

  1. A list of files/extensions that defines these optional syntaxes that can, but usually are not edited directly
  2. A flag like --force-header that applies this.

Are there other file types like SVG that would fall in this category?

mxmehl avatar Apr 29 '22 10:04 mxmehl

Typically "does it contain 0 bytes" is a fairly reasonable indicator if something is a binary file or not. I could imagine that if you apply an explicit --style argument, it would actually do that, unless the file is a binary file.

pepijndevos avatar Apr 29 '22 13:04 pepijndevos

Hm, but then it would also be possible to enforce comments e.g. in JSON files which would break their syntax. I am afraid that this could lead to unwanted results when running addheader in bulk operations.

mxmehl avatar Apr 29 '22 14:04 mxmehl

Some dialects of JSON do actually support JS-style comments, so it's not that weird in my mind. I'd argue that doing bulk operations with --style with files that are not compatible with that style is always going to produce wrong results. If someone wants JS-style comments in their JSON, they should be able to do that.

pepijndevos avatar Apr 29 '22 14:04 pepijndevos