Skip to content

Commit

Permalink
Makes custom rules show up in mllint list all and allows custom rul…
Browse files Browse the repository at this point in the history
…es to be disabled with through the config as though they are normal rules.
  • Loading branch information
bvobart committed Jul 16, 2021
1 parent 2648009 commit 100be2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
15 changes: 14 additions & 1 deletion commands/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/spf13/cobra"

"github.com/bvobart/mllint/api"
"github.com/bvobart/mllint/config"
"github.com/bvobart/mllint/linters"
"github.com/bvobart/mllint/utils/markdowngen"
)
Expand Down Expand Up @@ -60,6 +61,18 @@ func listAll(_ *cobra.Command, args []string) error {
if err := checkOutputFlag(); err != nil {
return err
}

conf, conftype, err := config.ParseFromDir(".")
if err == nil && len(conf.Rules.Custom) > 0 {
shush(func() {
color.Green("Including %d custom rules from the %s file in the current directory\n\n", len(conf.Rules.Custom), conftype.String())
})

if err := linters.ConfigureAll(conf); err != nil {
color.HiYellow("Warning! The mllint configuration file %s contains an error: %s\n\n", conftype.String(), err.Error())
}
}

return listLinters(linters.ByCategory)
}

Expand All @@ -80,10 +93,10 @@ func listEnabled(_ *cobra.Command, args []string) error {
}
shush(func() { fmt.Print("---\n\n") })

linters.DisableAll(conf.Rules.Disabled)
if err := linters.ConfigureAll(conf); err != nil {
return err
}
linters.DisableAll(conf.Rules.Disabled)

if err := listLinters(linters.ByCategory); err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@ func (rc *runCommand) RunLint(cmd *cobra.Command, args []string) error {
rc.ProjectR.Config = *rc.Config
shush(func() { fmt.Print("---\n\n") })

// disable any rules from config
rulesDisabled := linters.DisableAll(rc.Config.Rules.Disabled)

// configure all linters with config
if err = linters.ConfigureAll(rc.Config); err != nil {
return err
}

// disable any rules from config.
// This is done after configuring each linter, such that any rules arising from the configuration (e.g. custom rules) can also be disabled.
rulesDisabled := linters.DisableAll(rc.Config.Rules.Disabled)

// run pre-analysis checks
if err = rc.runPreAnalysisChecks(); err != nil {
return fmt.Errorf("failed to run pre-analysis checks: %w", err)
Expand Down

0 comments on commit 100be2f

Please sign in to comment.