From 595cf6736464170e7146555b794200306225c748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 18 Dec 2023 13:44:32 -0800 Subject: [PATCH 1/3] auto update to onflow/cadence 0ff20e15e7e1 --- lint/go.mod | 13 +++++++------ lint/go.sum | 36 +++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/lint/go.mod b/lint/go.mod index 338ad87e..da4cee65 100644 --- a/lint/go.mod +++ b/lint/go.mod @@ -4,14 +4,15 @@ go 1.19 require ( github.com/logrusorgru/aurora v2.0.3+incompatible - github.com/onflow/cadence v0.42.5 - github.com/onflow/flow-go-sdk v0.41.16 + github.com/onflow/cadence v1.0.0-preview.1.0.20231213191345-0ff20e15e7e1 + github.com/onflow/flow-go-sdk v0.44.0-stable-cadence.2 github.com/stretchr/testify v1.8.4 - golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15 + golang.org/x/exp v0.0.0-20230321023759-10a507213a29 google.golang.org/grpc v1.53.0 ) require ( + github.com/SaveTheRbtz/mph v0.1.2 // indirect github.com/bits-and-blooms/bitset v1.5.0 // indirect github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -20,14 +21,14 @@ require ( github.com/fxamacker/cbor/v2 v2.4.1-0.20230228173756-c0c9f774e40c // indirect github.com/fxamacker/circlehash v0.3.0 // indirect github.com/golang/protobuf v1.5.2 // indirect - github.com/k0kubun/pp/v3 v3.2.0 // indirect + github.com/k0kubun/pp v3.0.1+incompatible // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/logrusorgru/aurora/v4 v4.0.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.18 // indirect - github.com/onflow/atree v0.6.0 // indirect + github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f // indirect github.com/onflow/flow-go/crypto v0.24.7 // indirect github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230602212908-08fc6536d391 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -39,6 +40,7 @@ require ( github.com/turbolent/prettier v0.0.0-20220320183459-661cc755135d // indirect github.com/x448/float16 v0.8.4 // indirect github.com/zeebo/blake3 v0.2.3 // indirect + github.com/zeebo/xxh3 v1.0.2 // indirect go.opentelemetry.io/otel v1.14.0 // indirect golang.org/x/crypto v0.7.0 // indirect golang.org/x/net v0.8.0 // indirect @@ -47,6 +49,5 @@ require ( golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect google.golang.org/protobuf v1.30.0 // indirect - gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/lint/go.sum b/lint/go.sum index 3185a272..9cce3e8b 100644 --- a/lint/go.sum +++ b/lint/go.sum @@ -1,3 +1,5 @@ +github.com/SaveTheRbtz/mph v0.1.2 h1:5l3W496Up+7BNOVJQnJhzcGBh+wWfxWdmPUAkx3WmaM= +github.com/SaveTheRbtz/mph v0.1.2/go.mod h1:V4+WtKQPe2+dEA5os1WnGsEB0NR9qgqqgIiSt73+sT4= github.com/bits-and-blooms/bitset v1.5.0 h1:NpE8frKRLGHIcEzkR+gZhiioW1+WbYV6fKwD6ZIpQT8= github.com/bits-and-blooms/bitset v1.5.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= github.com/btcsuite/btcd/btcec/v2 v2.2.1 h1:xP60mv8fvp+0khmrN0zTdPC3cNm24rfeE6lh2R/Yv3E= @@ -19,16 +21,14 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/k0kubun/pp/v3 v3.2.0 h1:h33hNTZ9nVFNP3u2Fsgz8JXiF5JINoZfFq4SvKJwNcs= -github.com/k0kubun/pp/v3 v3.2.0/go.mod h1:ODtJQbQcIRfAD3N+theGCV1m/CBxweERz2dapdz1EwA= +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM= +github.com/k0kubun/pp v3.0.1+incompatible h1:3tqvf7QgUnZ5tXO6pNAZlrvHgl6DvifjDrd9g2S9Z40= +github.com/k0kubun/pp v3.0.1+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg= github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c= @@ -41,12 +41,12 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/onflow/atree v0.6.0 h1:j7nQ2r8npznx4NX39zPpBYHmdy45f4xwoi+dm37Jk7c= -github.com/onflow/atree v0.6.0/go.mod h1:gBHU0M05qCbv9NN0kijLWMgC47gHVNBIp4KmsVFi0tc= -github.com/onflow/cadence v0.42.5 h1:QCilotmJzfRToLd+02o3N62JIioSr8FfN7cujmR/IXQ= -github.com/onflow/cadence v0.42.5/go.mod h1:raU8va8QRyTa/eUbhej4mbyW2ETePfSaywoo36MddgE= -github.com/onflow/flow-go-sdk v0.41.16 h1:HsmHwEVmj+iK+GszHbFseHh7Ii5W3PWOIRNAH/En08Q= -github.com/onflow/flow-go-sdk v0.41.16/go.mod h1:bVrVNoJKiwB6vW5Qbm5tFAfJBQ5we4uSQWnn9gNAFhQ= +github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f h1:Z8/PgTqOgOg02MTRpTBYO2k16FE6z4wEOtaC2WBR9Xo= +github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM= +github.com/onflow/cadence v1.0.0-preview.1.0.20231213191345-0ff20e15e7e1 h1:xIFPRIA/pmyplEu5JxuMCfC6zfdqRW7QDHYJ8ogCNuc= +github.com/onflow/cadence v1.0.0-preview.1.0.20231213191345-0ff20e15e7e1/go.mod h1:60RhxKY5V4DXFQfvXQa48eZZVN19O7Lu9cp53FM54vo= +github.com/onflow/flow-go-sdk v0.44.0-stable-cadence.2 h1:vUVO6m85BiT8c50Oc8YGc3CU+sGqiKW9FZbmiRph2dU= +github.com/onflow/flow-go-sdk v0.44.0-stable-cadence.2/go.mod h1:mbLrR3MkYbi9LH3yasDj1jrR4QTR8vjRLVFCm4jMHn0= github.com/onflow/flow-go/crypto v0.24.7 h1:RCLuB83At4z5wkAyUCF7MYEnPoIIOHghJaODuJyEoW0= github.com/onflow/flow-go/crypto v0.24.7/go.mod h1:fqCzkIBBMRRkciVrvW21rECKq1oD7Q6u+bCI78lfNX0= github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230602212908-08fc6536d391 h1:6uKg0gpLKpTZKMihrsFR0Gkq++1hykzfR1tQCKuOfw4= @@ -80,14 +80,17 @@ github.com/zeebo/blake3 v0.2.3 h1:TFoLXsjeXqRNFxSbk35Dk4YtszE/MQQGK10BH4ptoTg= github.com/zeebo/blake3 v0.2.3/go.mod h1:mjJjZpnsyIVtVgTOSpJ9vmRE4wgDeyt2HU3qXvvKCaQ= github.com/zeebo/pcg v1.0.1 h1:lyqfGeWiv4ahac6ttHs+I5hwtH/+1mrhlCtVNQM2kHo= github.com/zeebo/pcg v1.0.1/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4= +github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0= +github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA= go.opentelemetry.io/otel v1.14.0 h1:/79Huy8wbf5DnIPhemGB+zEPVwnN6fuQybr/SRXa6hM= go.opentelemetry.io/otel v1.14.0/go.mod h1:o4buv+dJzx8rohcUeRmWUZhqupFvzWis188WlggnNeU= -go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= +go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0= golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15 h1:5oN1Pz/eDhCpbMbLstvIPa0b/BEQo6g6nwV3pLjfM6w= -golang.org/x/exp v0.0.0-20221217163422-3c43f8badb15/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= -golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= +golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug= +golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -97,7 +100,7 @@ golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= @@ -111,7 +114,6 @@ google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cn google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 7d1c0540310d5ccaf64db5c2f227d59a6befe77c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 18 Dec 2023 13:54:51 -0800 Subject: [PATCH 2/3] remove outdated analyzers --- lint/auth_account_parameter_analyzer.go | 89 ---------- lint/auth_account_parameter_analyzer_test.go | 172 ------------------- lint/reference_operator_analyzer.go | 93 ---------- lint/reference_operator_analyzer_test.go | 63 ------- 4 files changed, 417 deletions(-) delete mode 100644 lint/auth_account_parameter_analyzer.go delete mode 100644 lint/auth_account_parameter_analyzer_test.go delete mode 100644 lint/reference_operator_analyzer.go delete mode 100644 lint/reference_operator_analyzer_test.go diff --git a/lint/auth_account_parameter_analyzer.go b/lint/auth_account_parameter_analyzer.go deleted file mode 100644 index 86844b38..00000000 --- a/lint/auth_account_parameter_analyzer.go +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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 lint - -import ( - "github.com/onflow/cadence/runtime/ast" - "github.com/onflow/cadence/runtime/common" - "github.com/onflow/cadence/tools/analysis" -) - -var AuthAccountParameterAnalyzer = (func() *analysis.Analyzer { - - elementFilter := []ast.Element{ - (*ast.FunctionDeclaration)(nil), - (*ast.SpecialFunctionDeclaration)(nil), - } - - return &analysis.Analyzer{ - Description: "Detects functions with AuthAccount type parameters", - Requires: []*analysis.Analyzer{ - analysis.InspectorAnalyzer, - }, - Run: func(pass *analysis.Pass) interface{} { - inspector := pass.ResultOf[analysis.InspectorAnalyzer].(*ast.Inspector) - - location := pass.Program.Location - report := pass.Report - - inspector.Preorder( - elementFilter, - func(element ast.Element) { - var parameterList *ast.ParameterList - switch declaration := element.(type) { - case *ast.FunctionDeclaration: - parameterList = declaration.ParameterList - case *ast.SpecialFunctionDeclaration: - if declaration.DeclarationKind() == common.DeclarationKindInitializer { - parameterList = declaration.FunctionDeclaration.ParameterList - } - } - - if parameterList == nil { - return - } - - for _, parameter := range parameterList.Parameters { - nominalType, ok := parameter.TypeAnnotation.Type.(*ast.NominalType) - if ok && nominalType.Identifier.Identifier == "AuthAccount" { - report( - analysis.Diagnostic{ - Location: location, - Range: ast.NewRangeFromPositioned(nil, element), - Category: UpdateCategory, - Message: "It is an anti-pattern to pass AuthAccount to functions.", - SecondaryMessage: "Consider using Capabilities instead.", - }, - ) - } - } - }, - ) - - return nil - }, - } -})() - -func init() { - RegisterAnalyzer( - "auth-account-parameter", - AuthAccountParameterAnalyzer, - ) -} diff --git a/lint/auth_account_parameter_analyzer_test.go b/lint/auth_account_parameter_analyzer_test.go deleted file mode 100644 index 82e04728..00000000 --- a/lint/auth_account_parameter_analyzer_test.go +++ /dev/null @@ -1,172 +0,0 @@ -/* - * 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 lint_test - -import ( - "testing" - - "github.com/onflow/cadence/runtime/ast" - "github.com/onflow/cadence/tools/analysis" - "github.com/stretchr/testify/require" - - "github.com/onflow/cadence-tools/lint" -) - -func TestAuthAccountParameterAnalyzerInContractFunction(t *testing.T) { - - t.Parallel() - - diagnostics := testAnalyzers(t, - ` - pub contract BalanceChecker { - pub fun getBalance(account: AuthAccount): UFix64 { - return account.balance - } - } - `, - lint.AuthAccountParameterAnalyzer, - ) - - require.Equal( - t, - []analysis.Diagnostic{ - { - Range: ast.Range{ - StartPos: ast.Position{Offset: 47, Line: 3, Column: 10}, - EndPos: ast.Position{Offset: 145, Line: 5, Column: 10}, - }, - Location: testLocation, - Category: lint.UpdateCategory, - Message: "It is an anti-pattern to pass AuthAccount to functions.", - SecondaryMessage: "Consider using Capabilities instead.", - }, - }, - diagnostics, - ) -} - -func TestAuthAccountParameterAnalyzerInContractInitFunction(t *testing.T) { - - t.Parallel() - - diagnostics := testAnalyzers(t, - ` - pub contract BalanceChecker { - pub let balance: UFix64 - init(account: AuthAccount) { - self.balance = account.balance - } - } - `, - lint.AuthAccountParameterAnalyzer, - ) - - require.Equal( - t, - []analysis.Diagnostic{ - { - Range: ast.Range{ - StartPos: ast.Position{Offset: 81, Line: 4, Column: 10}, - EndPos: ast.Position{Offset: 165, Line: 6, Column: 10}, - }, - Location: testLocation, - Category: lint.UpdateCategory, - Message: "It is an anti-pattern to pass AuthAccount to functions.", - SecondaryMessage: "Consider using Capabilities instead.", - }, - }, - diagnostics, - ) -} - -func TestAuthAccountParameterAnalyzerInStructInitFunction(t *testing.T) { - - t.Parallel() - - diagnostics := testAnalyzers(t, - ` - pub struct Balance { - pub let balance: UFix64 - init(account: AuthAccount) { - self.balance = account.balance - } - } - `, - lint.AuthAccountParameterAnalyzer, - ) - - require.Equal( - t, - []analysis.Diagnostic{ - { - Range: ast.Range{ - StartPos: ast.Position{Offset: 72, Line: 4, Column: 10}, - EndPos: ast.Position{Offset: 156, Line: 6, Column: 10}, - }, - Location: testLocation, - Category: lint.UpdateCategory, - Message: "It is an anti-pattern to pass AuthAccount to functions.", - SecondaryMessage: "Consider using Capabilities instead.", - }, - }, - diagnostics, - ) -} - -func TestAuthAccountParameterAnalyzerWithPublicAccount(t *testing.T) { - - t.Parallel() - - diagnostics := testAnalyzers(t, - ` - pub contract BalanceChecker { - pub fun getBalance(account: PublicAccount): UFix64 { - return account.balance - } - } - `, - lint.AuthAccountParameterAnalyzer, - ) - - require.Equal( - t, - []analysis.Diagnostic(nil), - diagnostics, - ) -} - -func TestAuthAccountParameterAnalyzerWithTransaction(t *testing.T) { - - t.Parallel() - - diagnostics := testAnalyzers(t, - ` - transaction { - prepare(account: AuthAccount) {} - } - `, - lint.AuthAccountParameterAnalyzer, - ) - - require.Equal( - t, - []analysis.Diagnostic(nil), - diagnostics, - ) -} diff --git a/lint/reference_operator_analyzer.go b/lint/reference_operator_analyzer.go deleted file mode 100644 index 8668b1a7..00000000 --- a/lint/reference_operator_analyzer.go +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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 lint - -import ( - "fmt" - "regexp" - - "github.com/onflow/cadence/runtime/ast" - "github.com/onflow/cadence/tools/analysis" -) - -var ReferenceOperatorAnalyzer = (func() *analysis.Analyzer { - - elementFilter := []ast.Element{ - (*ast.ReferenceExpression)(nil), - } - - invalidOperatorRegexp := regexp.MustCompile(`.*\bas[?!].*`) - - return &analysis.Analyzer{ - Description: "Detects invalid operators in reference expressions. These will get rejected in a future release.", - Requires: []*analysis.Analyzer{ - analysis.InspectorAnalyzer, - }, - Run: func(pass *analysis.Pass) interface{} { - inspector := pass.ResultOf[analysis.InspectorAnalyzer].(*ast.Inspector) - - location := pass.Program.Location - code := pass.Program.Code - report := pass.Report - - inspector.Preorder( - elementFilter, - func(element ast.Element) { - - referenceExpression, ok := element.(*ast.ReferenceExpression) - if !ok { - return - } - - // Operator is incorrectly parsed, but not stored in AST. - // Analyze code instead - - startOffset := referenceExpression.Expression.EndPosition(nil).Offset + 1 - endOffset := referenceExpression.Type.StartPosition().Offset - 1 - - if !invalidOperatorRegexp.Match(code[startOffset:endOffset]) { - return - } - - report( - analysis.Diagnostic{ - Location: location, - Range: ast.NewRangeFromPositioned(nil, element), - Category: UpdateCategory, - Message: "incorrect reference operator used", - SecondaryMessage: fmt.Sprintf( - "use the '%s' operator", - ast.OperationCast.Symbol(), - ), - }, - ) - }, - ) - - return nil - }, - } -})() - -func init() { - RegisterAnalyzer( - "reference-operator", - ReferenceOperatorAnalyzer, - ) -} diff --git a/lint/reference_operator_analyzer_test.go b/lint/reference_operator_analyzer_test.go deleted file mode 100644 index b229ba81..00000000 --- a/lint/reference_operator_analyzer_test.go +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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 lint_test - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/onflow/cadence/runtime/ast" - "github.com/onflow/cadence/tools/analysis" - - "github.com/onflow/cadence-tools/lint" -) - -func TestReferenceOperatorAnalyzer(t *testing.T) { - - t.Parallel() - - diagnostics := testAnalyzers(t, - ` - pub contract Test { - pub fun test() { - let ref = &1 as! &Int - } - } - `, - lint.ReferenceOperatorAnalyzer, - ) - - require.Equal( - t, - []analysis.Diagnostic{ - { - Range: ast.Range{ - StartPos: ast.Position{Offset: 90, Line: 4, Column: 28}, - EndPos: ast.Position{Offset: 100, Line: 4, Column: 38}, - }, - Location: testLocation, - Category: lint.UpdateCategory, - Message: "incorrect reference operator used", - SecondaryMessage: "use the 'as' operator", - }, - }, - diagnostics, - ) -} From b39d90caeb581d4bf2483cee7692932efbd901fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 18 Dec 2023 13:55:17 -0800 Subject: [PATCH 3/3] update analyzers to Cadence 1.0 --- lint/deprecated_member_analyzer.go | 48 +---------- lint/deprecated_member_analyzer_test.go | 11 ++- .../number_function_argument_analyzer_test.go | 80 +++++++++---------- lint/redundant_cast_analyzer_test.go | 24 +++--- lint/unnecessary_force_analyzer_test.go | 12 +-- 5 files changed, 66 insertions(+), 109 deletions(-) diff --git a/lint/deprecated_member_analyzer.go b/lint/deprecated_member_analyzer.go index e7e18397..9914da66 100644 --- a/lint/deprecated_member_analyzer.go +++ b/lint/deprecated_member_analyzer.go @@ -23,38 +23,9 @@ import ( "regexp" "github.com/onflow/cadence/runtime/ast" - "github.com/onflow/cadence/runtime/sema" "github.com/onflow/cadence/tools/analysis" ) -func memberReplacement(memberInfo sema.MemberInfo) string { - memberName := memberInfo.Member.Identifier.Identifier - switch memberInfo.AccessedType { - case sema.AuthAccountType: - switch memberName { - case sema.AuthAccountTypeAddPublicKeyFunctionName: - return "keys.add" - - case sema.AuthAccountTypeRemovePublicKeyFunctionName: - return "keys.revoke" - - case sema.AuthAccountTypeGetCapabilityFunctionName: - return "capabilities.get" - - case sema.AuthAccountTypeLinkFunctionName: - return "capabilities.storage.issue" - - case sema.AuthAccountTypeLinkAccountFunctionName: - return "capabilities.account.issue" - - case sema.AuthAccountTypeUnlinkFunctionName: - return "capabilities.unpublish" - } - } - - return "" -} - var docStringDeprecationWarningPattern = regexp.MustCompile(`(?i)[\t *_]*deprecated\b(?:[*_]*: (.*))?`) func MemberIsDeprecated(docString string) bool { @@ -87,7 +58,7 @@ var DeprecatedMemberAnalyzer = (func() *analysis.Analyzer { return } - memberInfo, _ := elaboration.MemberExpressionMemberInfo(memberExpression) + memberInfo, _ := elaboration.MemberExpressionMemberAccessInfo(memberExpression) member := memberInfo.Member if member == nil { return @@ -102,22 +73,6 @@ var DeprecatedMemberAnalyzer = (func() *analysis.Analyzer { identifierRange := ast.NewRangeFromPositioned(nil, memberExpression.Identifier) - var suggestedFixes []analysis.SuggestedFix - - replacement := memberReplacement(memberInfo) - if replacement != "" { - suggestedFix := analysis.SuggestedFix{ - Message: "replace", - TextEdits: []analysis.TextEdit{ - { - Replacement: replacement, - Range: identifierRange, - }, - }, - } - suggestedFixes = append(suggestedFixes, suggestedFix) - } - report( analysis.Diagnostic{ Location: location, @@ -129,7 +84,6 @@ var DeprecatedMemberAnalyzer = (func() *analysis.Analyzer { memberName, ), SecondaryMessage: docStringMatch[1], - SuggestedFixes: suggestedFixes, }, ) }, diff --git a/lint/deprecated_member_analyzer_test.go b/lint/deprecated_member_analyzer_test.go index 0c29f027..8b963430 100644 --- a/lint/deprecated_member_analyzer_test.go +++ b/lint/deprecated_member_analyzer_test.go @@ -30,18 +30,21 @@ import ( func TestDeprecatedMemberAnalyzer(t *testing.T) { + // TODO: no more deprecated members + t.SkipNow() + t.Parallel() diagnostics := testAnalyzers(t, ` - pub contract Test { + access(all) contract Test { /// **DEPRECATED** - pub fun foo() {} + access(all) fun foo() {} /// Deprecated: No good - pub fun bar() {} + access(all) fun bar() {} - pub fun test(account: AuthAccount) { + access(all) fun test(account: AuthAccount) { account.addPublicKey([]) account.removePublicKey(0) self.foo() diff --git a/lint/number_function_argument_analyzer_test.go b/lint/number_function_argument_analyzer_test.go index bd492f0d..f8640cf7 100644 --- a/lint/number_function_argument_analyzer_test.go +++ b/lint/number_function_argument_analyzer_test.go @@ -41,8 +41,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { t.Parallel() diagnostics := testAnalyzers(t, ` - pub contract Test { - pub fun test() { + access(all) contract Test { + access(all) fun test() { let x = Fix64(1) } }`, @@ -54,8 +54,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { []analysis.Diagnostic{ { Range: ast.Range{ - StartPos: ast.Position{Offset: 58, Line: 4, Column: 13}, - EndPos: ast.Position{Offset: 65, Line: 4, Column: 20}, + StartPos: ast.Position{Offset: 74, Line: 4, Column: 13}, + EndPos: ast.Position{Offset: 81, Line: 4, Column: 20}, }, Location: testLocation, Category: lint.ReplacementCategory, @@ -71,8 +71,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { t.Parallel() diagnostics := testAnalyzers(t, ` - pub contract Test { - pub fun test() { + access(all) contract Test { + access(all) fun test() { let x = UFix64(1) } }`, @@ -84,8 +84,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { []analysis.Diagnostic{ { Range: ast.Range{ - StartPos: ast.Position{Offset: 55, Line: 4, Column: 12}, - EndPos: ast.Position{Offset: 63, Line: 4, Column: 20}, + StartPos: ast.Position{Offset: 71, Line: 4, Column: 12}, + EndPos: ast.Position{Offset: 79, Line: 4, Column: 20}, }, Location: testLocation, Category: lint.ReplacementCategory, @@ -101,8 +101,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { t.Parallel() diagnostics := testAnalyzers(t, ` - pub contract Test { - pub fun test() { + access(all) contract Test { + access(all) fun test() { let x = Fix64(-1) } }`, @@ -114,8 +114,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { []analysis.Diagnostic{ { Range: ast.Range{ - StartPos: ast.Position{Offset: 55, Line: 4, Column: 12}, - EndPos: ast.Position{Offset: 63, Line: 4, Column: 20}, + StartPos: ast.Position{Offset: 71, Line: 4, Column: 12}, + EndPos: ast.Position{Offset: 79, Line: 4, Column: 20}, }, Location: testLocation, Category: lint.ReplacementCategory, @@ -133,8 +133,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { t.Parallel() diagnostics := testAnalyzers(t, ` - pub contract Test { - pub fun test() { + access(all) contract Test { + access(all) fun test() { let x = UFix64(1.2) } }`, @@ -146,8 +146,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { []analysis.Diagnostic{ { Range: ast.Range{ - StartPos: ast.Position{Offset: 55, Line: 4, Column: 12}, - EndPos: ast.Position{Offset: 65, Line: 4, Column: 22}, + StartPos: ast.Position{Offset: 71, Line: 4, Column: 12}, + EndPos: ast.Position{Offset: 81, Line: 4, Column: 22}, }, Location: testLocation, Category: lint.ReplacementCategory, @@ -163,8 +163,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { t.Parallel() diagnostics := testAnalyzers(t, ` - pub contract Test { - pub fun test() { + access(all) contract Test { + access(all) fun test() { let x = Fix64(-1.2) } }`, @@ -176,8 +176,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { []analysis.Diagnostic{ { Range: ast.Range{ - StartPos: ast.Position{Offset: 55, Line: 4, Column: 12}, - EndPos: ast.Position{Offset: 65, Line: 4, Column: 22}, + StartPos: ast.Position{Offset: 71, Line: 4, Column: 12}, + EndPos: ast.Position{Offset: 81, Line: 4, Column: 22}, }, Location: testLocation, Category: lint.ReplacementCategory, @@ -197,8 +197,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { t.Parallel() diagnostics := testAnalyzers(t, ` - pub contract Test { - pub fun test() { + access(all) contract Test { + access(all) fun test() { let x = UInt8(1) } }`, @@ -210,8 +210,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { []analysis.Diagnostic{ { Range: ast.Range{ - StartPos: ast.Position{Offset: 55, Line: 4, Column: 12}, - EndPos: ast.Position{Offset: 62, Line: 4, Column: 19}, + StartPos: ast.Position{Offset: 71, Line: 4, Column: 12}, + EndPos: ast.Position{Offset: 78, Line: 4, Column: 19}, }, Location: testLocation, Category: lint.ReplacementCategory, @@ -227,8 +227,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { t.Parallel() diagnostics := testAnalyzers(t, ` - pub contract Test { - pub fun test() { + access(all) contract Test { + access(all) fun test() { let x = Int8(1) } }`, @@ -240,8 +240,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { []analysis.Diagnostic{ { Range: ast.Range{ - StartPos: ast.Position{Offset: 55, Line: 4, Column: 12}, - EndPos: ast.Position{Offset: 61, Line: 4, Column: 18}, + StartPos: ast.Position{Offset: 71, Line: 4, Column: 12}, + EndPos: ast.Position{Offset: 77, Line: 4, Column: 18}, }, Location: testLocation, Category: lint.ReplacementCategory, @@ -258,8 +258,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { t.Parallel() diagnostics := testAnalyzers(t, ` - pub contract Test { - pub fun test() { + access(all) contract Test { + access(all) fun test() { let x = Int8(-1) } }`, @@ -271,8 +271,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { []analysis.Diagnostic{ { Range: ast.Range{ - StartPos: ast.Position{Offset: 55, Line: 4, Column: 12}, - EndPos: ast.Position{Offset: 62, Line: 4, Column: 19}, + StartPos: ast.Position{Offset: 71, Line: 4, Column: 12}, + EndPos: ast.Position{Offset: 78, Line: 4, Column: 19}, }, Location: testLocation, Category: lint.ReplacementCategory, @@ -288,8 +288,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { t.Parallel() diagnostics := testAnalyzers(t, ` - pub contract Test { - pub fun test() { + access(all) contract Test { + access(all) fun test() { let x = Int(1) } }`, @@ -301,8 +301,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { []analysis.Diagnostic{ { Range: ast.Range{ - StartPos: ast.Position{Offset: 55, Line: 4, Column: 12}, - EndPos: ast.Position{Offset: 60, Line: 4, Column: 17}, + StartPos: ast.Position{Offset: 71, Line: 4, Column: 12}, + EndPos: ast.Position{Offset: 76, Line: 4, Column: 17}, }, Location: testLocation, Category: lint.ReplacementCategory, @@ -318,8 +318,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { t.Parallel() diagnostics := testAnalyzers(t, ` - pub contract Test { - pub fun test() { + access(all) contract Test { + access(all) fun test() { let x = Int(-1) } }`, @@ -331,8 +331,8 @@ func TestCheckNumberConversionReplacementHint(t *testing.T) { []analysis.Diagnostic{ { Range: ast.Range{ - StartPos: ast.Position{Offset: 55, Line: 4, Column: 12}, - EndPos: ast.Position{Offset: 61, Line: 4, Column: 18}, + StartPos: ast.Position{Offset: 71, Line: 4, Column: 12}, + EndPos: ast.Position{Offset: 77, Line: 4, Column: 18}, }, Location: testLocation, Category: lint.ReplacementCategory, diff --git a/lint/redundant_cast_analyzer_test.go b/lint/redundant_cast_analyzer_test.go index 930cbee6..ae735729 100644 --- a/lint/redundant_cast_analyzer_test.go +++ b/lint/redundant_cast_analyzer_test.go @@ -38,8 +38,8 @@ func TestRedundantCastAnalyzer(t *testing.T) { diagnostics := testAnalyzers(t, ` - pub contract Test { - pub fun test() { + access(all) contract Test { + access(all) fun test() { let x = true as Bool } } @@ -52,8 +52,8 @@ func TestRedundantCastAnalyzer(t *testing.T) { []analysis.Diagnostic{ { Range: ast.Range{ - StartPos: ast.Position{Offset: 66, Line: 4, Column: 21}, - EndPos: ast.Position{Offset: 69, Line: 4, Column: 24}, + StartPos: ast.Position{Offset: 82, Line: 4, Column: 21}, + EndPos: ast.Position{Offset: 85, Line: 4, Column: 24}, }, Location: testLocation, Category: lint.UnnecessaryCastCategory, @@ -70,8 +70,8 @@ func TestRedundantCastAnalyzer(t *testing.T) { diagnostics := testAnalyzers(t, ` - pub contract Test { - pub fun test() { + access(all) contract Test { + access(all) fun test() { let x = true as! Bool } } @@ -84,8 +84,8 @@ func TestRedundantCastAnalyzer(t *testing.T) { []analysis.Diagnostic{ { Range: ast.Range{ - StartPos: ast.Position{Offset: 58, Line: 4, Column: 13}, - EndPos: ast.Position{Offset: 70, Line: 4, Column: 25}, + StartPos: ast.Position{Offset: 74, Line: 4, Column: 13}, + EndPos: ast.Position{Offset: 86, Line: 4, Column: 25}, }, Location: testLocation, Category: lint.UnnecessaryCastCategory, @@ -102,8 +102,8 @@ func TestRedundantCastAnalyzer(t *testing.T) { diagnostics := testAnalyzers(t, ` - pub contract Test { - pub fun test() { + access(all) contract Test { + access(all) fun test() { let x = true as? Bool } } @@ -116,8 +116,8 @@ func TestRedundantCastAnalyzer(t *testing.T) { []analysis.Diagnostic{ { Range: ast.Range{ - StartPos: ast.Position{Offset: 58, Line: 4, Column: 13}, - EndPos: ast.Position{Offset: 70, Line: 4, Column: 25}, + StartPos: ast.Position{Offset: 74, Line: 4, Column: 13}, + EndPos: ast.Position{Offset: 86, Line: 4, Column: 25}, }, Location: testLocation, Category: lint.UnnecessaryCastCategory, diff --git a/lint/unnecessary_force_analyzer_test.go b/lint/unnecessary_force_analyzer_test.go index 0c513605..68b4bf39 100644 --- a/lint/unnecessary_force_analyzer_test.go +++ b/lint/unnecessary_force_analyzer_test.go @@ -39,8 +39,8 @@ func TestForceOperatorAnalyzer(t *testing.T) { diagnostics := testAnalyzers(t, ` - pub contract Test { - pub fun test() { + access(all) contract Test { + access(all) fun test() { let x = 3 let y = x! } @@ -54,8 +54,8 @@ func TestForceOperatorAnalyzer(t *testing.T) { []analysis.Diagnostic{ { Range: ast.Range{ - StartPos: ast.Position{Offset: 73, Line: 5, Column: 13}, - EndPos: ast.Position{Offset: 74, Line: 5, Column: 14}, + StartPos: ast.Position{Offset: 89, Line: 5, Column: 13}, + EndPos: ast.Position{Offset: 90, Line: 5, Column: 14}, }, Location: testLocation, Category: lint.RemovalCategory, @@ -72,8 +72,8 @@ func TestForceOperatorAnalyzer(t *testing.T) { diagnostics := testAnalyzers(t, ` - pub contract Test { - pub fun test() { + access(all) contract Test { + access(all) fun test() { let x: Int? = 3 let y = x! }