Repository: gohugoio/hugo (language: go)

Issue:
commands: Add --omitEmpty flag to gen chromastyles to omit empty rules
E.g.

```css
/* Name */ .chroma .n {  }
```

These are useless and take up bandwidth, so they're flagged by https://yellowlab.tools.

### What version of Hugo are you using (`hugo version`)?

<pre>
$ hugo version
hugo v0.145.0+extended+withdeploy darwin/arm64 BuildDate=2025-02-26T15:41:25Z VendorInfo=brew
</pre>

### Does this issue reproduce with the latest release?

Yes


Discussion / hints:
I randomly tested 10 of the available styles, and all had one or more empty rules. Some of the styles had one or more empty rules going back to v0.54.0... so this isn't anything new. If you're purging in production these are irrelevant.

It's a trivial, one word change to omit empty rules, but I'd probably put it behind a flag (`--omitEmpty`) to keep the existing behavior. I have no idea if anyone finds the empty rules useful... they could be if you wanted to populate them yourself.

Fix patch:
diff --git a/commands/gen.go b/commands/gen.go
index b77deeeb7c7..895340dbb97 100644
--- a/commands/gen.go
+++ b/commands/gen.go
@@ -50,6 +50,7 @@ func newGenCommand() *genCommand {
 		highlightStyle         string
 		lineNumbersInlineStyle string
 		lineNumbersTableStyle  string
+		omitEmpty              bool
 	)
 
 	newChromaStyles := func() simplecobra.Commander {
@@ -79,7 +80,14 @@ See https://xyproto.github.io/splash/docs/all.html for a preview of the availabl
 				if err != nil {
 					return err
 				}
-				formatter := html.New(html.WithAllClasses(true))
+
+				var formatter *html.Formatter
+				if omitEmpty {
+					formatter = html.New(html.WithClasses(true))
+				} else {
+					formatter = html.New(html.WithAllClasses(true))
+				}
+
 				w := os.Stdout
 				fmt.Fprintf(w, "/* Generated using: hugo %s */\n\n", strings.Join(os.Args[1:], " "))
 				formatter.WriteCSS(w, style)
@@ -95,6 +103,8 @@ See https://xyproto.github.io/splash/docs/all.html for a preview of the availabl
 				_ = cmd.RegisterFlagCompletionFunc("lineNumbersInlineStyle", cobra.NoFileCompletions)
 				cmd.PersistentFlags().StringVar(&lineNumbersTableStyle, "lineNumbersTableStyle", "", `foreground and background colors for table line numbers, e.g. --lineNumbersTableStyle "#fff000 bg:#000fff"`)
 				_ = cmd.RegisterFlagCompletionFunc("lineNumbersTableStyle", cobra.NoFileCompletions)
+				cmd.PersistentFlags().BoolVar(&omitEmpty, "omitEmpty", false, `omit empty CSS rules`)
+				_ = cmd.RegisterFlagCompletionFunc("omitEmpty", cobra.NoFileCompletions)
 			},
 		}
 	}


Test patch:
diff --git a/testscripts/commands/gen.txt b/testscripts/commands/gen.txt
index 2d57c8ec0ad..e83e9982f9f 100644
--- a/testscripts/commands/gen.txt
+++ b/testscripts/commands/gen.txt
@@ -14,3 +14,9 @@ hugo gen chromastyles --style monokai
 stdout 'Generated using: hugo gen chromastyles --style monokai'
 ! hugo gen chromastyles --style __invalid_style__
 stderr 'invalid style: __invalid_style__'
+
+# Issue 13475
+hugo gen chromastyles --style monokai
+stdout '{  }'
+hugo gen chromastyles --omitEmpty --style monokai
+! stdout '\{  \}'