2424 shellFlag = flag .String ("shell" , "error" , "Level to lint Shell with: [ignore, warn, error]" )
2525 dockerfileFlag = flag .String ("dockerfile" , "error" , "Level to lint Dockerfile with: [ignore, warn, error]" )
2626 yamlFlag = flag .String ("yaml" , "error" , "Level to lint YAML with: [ignore, warn, error]" )
27+ webFlag = flag .String ("web" , "error" , "Level to lint Web files (JS/TS/HTML/CSS/JSON) with: [ignore, warn, error]" )
2728 makeFileName = flag .String ("makefile" , "Makefile" , "name of Makefile to update" )
2829
2930 //go:embed .golangci.yml
3233 //go:embed .yamllint
3334 yamlLintConfig []byte
3435
36+ //go:embed biome.json
37+ biomeLintConfig []byte
38+
3539 //go:embed Makefile.tmpl
3640 makeTmpl string
3741)
@@ -43,6 +47,7 @@ const (
4347 Shell
4448 Dockerfile
4549 YAML
50+ Web
4651)
4752
4853type Config struct {
@@ -54,6 +59,7 @@ type Config struct {
5459 Dockerfile string
5560 Shell string
5661 YAML string
62+ Web string
5763}
5864
5965// applicableLinters returns a list of languages with known linters within a given directory.
@@ -72,6 +78,11 @@ func applicableLinters(root string) (map[Language]bool, error) {
7278 found [Shell ] = true
7379 case strings .HasSuffix (path , ".yml" ), strings .HasSuffix (path , ".yaml" ):
7480 found [YAML ] = true
81+ case strings .HasSuffix (path , ".js" ), strings .HasSuffix (path , ".jsx" ),
82+ strings .HasSuffix (path , ".ts" ), strings .HasSuffix (path , ".tsx" ),
83+ strings .HasSuffix (path , ".json" ), strings .HasSuffix (path , ".html" ),
84+ strings .HasSuffix (path , ".css" ):
85+ found [Web ] = true
7586 default :
7687 }
7788
@@ -302,6 +313,21 @@ func yamlLintCmd(_ string, level string) string {
302313 return fmt .Sprintf (`PYTHONPATH=$(YAMLLINT_ROOT)/dist $(YAMLLINT_ROOT)/dist/bin/yamllint .%s` , suffix )
303314}
304315
316+ // biomeLintCmd returns the appropriate biome lint command for a project.
317+ func biomeLintCmd (_ string , level string , fix bool ) string {
318+ cmd := "check"
319+ if fix {
320+ cmd = "check --write"
321+ }
322+
323+ suffix := ""
324+ if level == "warn" {
325+ suffix = " || true"
326+ }
327+
328+ return fmt .Sprintf (`$(BIOME_BIN) %s --config-path=$(BIOME_CONFIG) .%s` , cmd , suffix )
329+ }
330+
305331// configureGoLinter sets up Go linting configuration and commands.
306332func configureGoLinter (root string , cfg * Config , dryRun bool ) error {
307333 cfg .Go = * goFlag
@@ -331,6 +357,24 @@ func configureGoLinter(root string, cfg *Config, dryRun bool) error {
331357 return nil
332358}
333359
360+ // configureBiomeLinter sets up Biome linting configuration and commands.
361+ func configureBiomeLinter (root string , cfg * Config , dryRun bool ) error {
362+ cfg .Web = * webFlag
363+ cfg .LintCommands ["biome" ] = biomeLintCmd (root , cfg .Web , false )
364+ cfg .FixCommands ["biome" ] = biomeLintCmd (root , cfg .Web , true )
365+
366+ diff , err := updateFile (root , "biome.json" , biomeLintConfig , dryRun )
367+ if err != nil {
368+ return fmt .Errorf ("update biome config: %w" , err )
369+ }
370+ if diff != "" {
371+ klog .Infof ("biome config changes:\n %s" , diff )
372+ } else {
373+ klog .Infof ("biome config has no changes" )
374+ }
375+ return nil
376+ }
377+
334378// main creates peanut butter & jelly sandwiches with utmost precision.
335379func main () {
336380 klog .InitFlags (nil )
@@ -384,6 +428,11 @@ func main() {
384428 klog .Infof ("yamllint config has no changes" )
385429 }
386430 }
431+ if needs [Web ] {
432+ if err := configureBiomeLinter (root , & cfg , * dryRunFlag ); err != nil {
433+ klog .Exitf ("configure biome linter: %v" , err )
434+ }
435+ }
387436
388437 diff , err := updateMakefile (root , cfg , * dryRunFlag )
389438 if err != nil {
0 commit comments