Skip to content

Commit

Permalink
Merge pull request #285 from onflow/jribbink/c1-warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Feb 16, 2024
2 parents ad5932e + abe9369 commit dff8cfa
Show file tree
Hide file tree
Showing 5 changed files with 1,151 additions and 0 deletions.
1 change: 1 addition & 0 deletions lint/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
UpdateCategory = "update recommended"
UnnecessaryCastCategory = "unnecessary-cast-hint"
DeprecatedCategory = "deprecated"
CadenceV1Category = "cadence-v1"
)

var Analyzers = map[string]*analysis.Analyzer{}
Expand Down
26 changes: 26 additions & 0 deletions lint/analyzers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/sema"
"github.com/onflow/cadence/tools/analysis"

"github.com/onflow/cadence-tools/lint"
Expand All @@ -32,6 +33,27 @@ import (
var testLocation = common.StringLocation("test")

func testAnalyzers(t *testing.T, code string, analyzers ...*analysis.Analyzer) []analysis.Diagnostic {
return testAnalyzersAdvanced(t, code, nil, analyzers...)
}

func testAnalyzersWithCheckerError(t *testing.T, code string, analyzers ...*analysis.Analyzer) ([]analysis.Diagnostic, *sema.CheckerError) {
var checkerErr *sema.CheckerError
diagnostics := testAnalyzersAdvanced(t, code, func(config *analysis.Config) {
config.HandleCheckerError = func(err analysis.ParsingCheckingError, checker *sema.Checker) error {
require.NotNil(t, checker)
require.Equal(t, err.ImportLocation(), testLocation)

require.ErrorAs(t, err, &checkerErr)
require.Len(t, checkerErr.Errors, 1)
return nil
}
}, analyzers...)

require.NotNil(t, checkerErr)
return diagnostics, checkerErr
}

func testAnalyzersAdvanced(t *testing.T, code string, setCustomConfigOptions func(config *analysis.Config), analyzers ...*analysis.Analyzer) []analysis.Diagnostic {

config := analysis.NewSimpleConfig(
lint.LoadMode,
Expand All @@ -42,6 +64,10 @@ func testAnalyzers(t *testing.T, code string, analyzers ...*analysis.Analyzer) [
nil,
)

if setCustomConfigOptions != nil {
setCustomConfigOptions(config)
}

programs, err := analysis.Load(config, testLocation)
require.NoError(t, err)

Expand Down
Loading

0 comments on commit dff8cfa

Please sign in to comment.