func Lint(srcRoot string) (err error) { target := config.Targets[0] allmap := make(map[string]map[int][]common.Violation) var allv []common.Violation var fmap map[string]map[int][]common.Violation for i := range target.RuleSets { // Lint with each modules rs := target.RuleSets[i] for j := range rs.Modules { switch rs.Modules[j].Id { case "pattern_match": fmap, err = modules.LintWalk(srcRoot, rs.Modules[j], opt.Locale, opt.Fix, modules.LintPatternMatchFunc) case "indent": fmap, err = modules.LintWalk(srcRoot, rs.Modules[j], opt.Locale, opt.Fix, modules.LintIndentFunc) case "max_length": fmap, err = modules.LintWalk(srcRoot, rs.Modules[j], opt.Locale, opt.Fix, modules.LintMaxLengthFunc) } if err != nil { return } // Merge into one map if fmap != nil { for f, vmap := range fmap { if allmap[f] == nil { allmap[f] = make(map[int][]common.Violation) } for n, vs := range vmap { allmap[f][n] = append(allmap[f][n], vs...) allv = append(allv, vs...) } } } } } violations = allv for f, vmap := range allmap { vcnt := 0 for _, vs := range vmap { vvcnt := 0 for i := range vs { if !vs[i].Fixed { vvcnt++ } } vcnt = vcnt + vvcnt } printReportBody(f, vcnt, vmap) } return }
func TestSetbufsizeAndLint(t *testing.T) { // normal var m common.Module m.Pattern = ".*\\.(m|mm|h)$" m.Rules = []common.Rule{ common.Rule{Id: "ExceedMaxLength", Args: []interface{}{".*", 80.0}, Message: map[string]string{"en": "Line length exceeds %d characters"}}} // When the bufSize is set to 0, default size will be set. fint.Setbufsize(0) _, err := modules.LintWalk(SrcRootObjcNormal, m, LocaleDefault, false, modules.LintMaxLengthFunc) if err != nil { t.Errorf("Unexpected error occurred: %v", err) } fint.Setbufsize(1) _, err = modules.LintWalk(SrcRootObjcNormal, m, LocaleDefault, false, modules.LintMaxLengthFunc) // Do normal test to initialize opt testExecuteNormal(t, &common.Opt{SrcRoot: SrcRootObjcNormal, ConfigPath: ConfigDefault, Locale: LocaleJa, Id: LintIdObjc}, ErrorsObjcNormal) }