-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from onflow/bastian/refactor-linter
[lint] Refactor so it can be embedded
- Loading branch information
Showing
19 changed files
with
267 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
package analyzers | ||
package lint | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Cadence-lint - The Cadence linter | ||
* | ||
* Copyright 2019-2022 Dapper Labs, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
"sort" | ||
|
||
"github.com/onflow/cadence/tools/analysis" | ||
"github.com/onflow/flow-go-sdk" | ||
|
||
"github.com/onflow/cadence-tools/lint" | ||
) | ||
|
||
var csvPathFlag = flag.String("csv", "", "analyze all programs in the given CSV file") | ||
var directoryPathFlag = flag.String("directory", "", "analyze all programs in the given directory") | ||
var networkFlag = flag.String("network", "", "name of network") | ||
var addressFlag = flag.String("address", "", "analyze contracts in the given account") | ||
var transactionFlag = flag.String("transaction", "", "analyze transaction with given ID") | ||
var loadOnlyFlag = flag.Bool("load-only", false, "only load (parse and check) programs") | ||
var silentFlag = flag.Bool("silent", false, "only show parsing/checking success/failure") | ||
var colorFlag = flag.Bool("color", true, "format using colors") | ||
var analyzersFlag stringSliceFlag | ||
|
||
func init() { | ||
flag.Var(&analyzersFlag, "analyze", "enable analyzer") | ||
} | ||
|
||
func main() { | ||
defaultUsage := flag.Usage | ||
flag.Usage = func() { | ||
defaultUsage() | ||
_, _ = fmt.Fprintf(os.Stderr, "\nAvailable analyzers:\n") | ||
|
||
names := make([]string, 0, len(lint.Analyzers)) | ||
for name := range lint.Analyzers { | ||
names = append(names, name) | ||
} | ||
|
||
sort.Strings(names) | ||
|
||
for _, name := range names { | ||
analyzer := lint.Analyzers[name] | ||
_, _ = fmt.Fprintf( | ||
os.Stderr, | ||
" - %s:\n %s\n", | ||
name, | ||
analyzer.Description, | ||
) | ||
} | ||
} | ||
|
||
flag.Parse() | ||
|
||
var enabledAnalyzers []*analysis.Analyzer | ||
|
||
loadOnly := *loadOnlyFlag | ||
if !loadOnly { | ||
if len(analyzersFlag) > 0 { | ||
for _, analyzerName := range analyzersFlag { | ||
analyzer, ok := lint.Analyzers[analyzerName] | ||
if !ok { | ||
log.Panic(fmt.Errorf("unknown analyzer: %s", analyzerName)) | ||
} | ||
|
||
enabledAnalyzers = append(enabledAnalyzers, analyzer) | ||
} | ||
} else { | ||
// Use all analyzers | ||
for _, analyzer := range lint.Analyzers { | ||
enabledAnalyzers = append(enabledAnalyzers, analyzer) | ||
} | ||
} | ||
} | ||
|
||
linter := lint.NewLinter(lint.Config{ | ||
Analyzers: enabledAnalyzers, | ||
Silent: *silentFlag, | ||
UseColor: *colorFlag, | ||
}) | ||
|
||
cvsPath := *csvPathFlag | ||
directoryPath := *directoryPathFlag | ||
address := *addressFlag | ||
transaction := *transactionFlag | ||
|
||
switch { | ||
case cvsPath != "": | ||
linter.AnalyzeCSV(cvsPath) | ||
|
||
case directoryPath != "": | ||
linter.AnalyzeDirectory(directoryPath) | ||
|
||
case address != "": | ||
network := *networkFlag | ||
linter.AnalyzeAccount(address, network) | ||
|
||
case transaction != "": | ||
transactionID := flow.HexToID(transaction) | ||
network := *networkFlag | ||
linter.AnalyzeTransaction(transactionID, network) | ||
|
||
default: | ||
println("Nothing to do. Please provide -address, -transaction, -directory, or -csv. See -help") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
package analyzers | ||
package lint | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
package main | ||
package lint | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,3 +142,4 @@ require ( | |
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
lukechampine.com/blake3 v1.1.7 // indirect | ||
) | ||
|
Oops, something went wrong.