mirror of
https://github.com/mgechev/revive.git
synced 2025-11-23 22:04:49 +02:00
Separating lib from cli (#655)
* Separating lib from cli * Renamed NewRevive to New * Added GetLintFailures helper function * Moved formatter to call to format since that's when it's needed * makes fields of Revive struct non-public * minor modifs in tests: remove unnamed constats * Added lint package management to lint command * README message for using revive as a library * README formatting * Removed unused method * Slightly improved wording in README * Handling format errors * Renaming file to better reflect intent * Refactoring pattern usage * README heads * renames excludePaths into excludePatterns Co-authored-by: Bernardo Heynemann <bernardo.heynemann@coinbase.com> Co-authored-by: chavacava <salvadorcavadini+github@gmail.com>
This commit is contained in:
committed by
GitHub
parent
fa939adbf0
commit
318db94210
69
revivelib/core_internal_test.go
Normal file
69
revivelib/core_internal_test.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package revivelib
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mgechev/revive/config"
|
||||
"github.com/mgechev/revive/lint"
|
||||
)
|
||||
|
||||
func TestReviveCreateInstance(t *testing.T) {
|
||||
revive := getMockRevive(t)
|
||||
|
||||
if revive.config == nil {
|
||||
t.Fatal("Could not load config.")
|
||||
}
|
||||
|
||||
if revive.maxOpenFiles != 2048 {
|
||||
t.Fatal("Expected MaxOpenFiles to be 2048")
|
||||
}
|
||||
|
||||
if revive.lintingRules == nil || len(revive.lintingRules) == 0 {
|
||||
t.Fatal("Linting rules not loaded.")
|
||||
}
|
||||
|
||||
rules := map[string]lint.Rule{}
|
||||
for _, rule := range revive.lintingRules {
|
||||
rules[rule.Name()] = rule
|
||||
}
|
||||
|
||||
if _, ok := rules["mock-rule"]; !ok {
|
||||
t.Fatal("Didn't load mock rule.")
|
||||
}
|
||||
|
||||
if revive.config.ErrorCode != 1 && revive.config.WarningCode != 1 {
|
||||
t.Fatal("Didn't set the codes in the config instance.")
|
||||
}
|
||||
}
|
||||
|
||||
type mockRule struct {
|
||||
}
|
||||
|
||||
func (r *mockRule) Name() string {
|
||||
return "mock-rule"
|
||||
}
|
||||
|
||||
func (r *mockRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
|
||||
return nil
|
||||
}
|
||||
|
||||
func getMockRevive(t *testing.T) *Revive {
|
||||
t.Helper()
|
||||
|
||||
conf, err := config.GetConfig("../defaults.toml")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
revive, err := New(
|
||||
conf,
|
||||
true,
|
||||
2048,
|
||||
NewExtraRule(&mockRule{}, lint.RuleConfig{}),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
return revive
|
||||
}
|
||||
Reference in New Issue
Block a user