mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-22 17:45:10 +00:00
Add Linters
Signed-off-by: Brett Logan <brett.t.logan@ibm.com>
This commit is contained in:
parent
e6184563ad
commit
59613c7e91
2 changed files with 96 additions and 0 deletions
|
|
@ -8,6 +8,8 @@ trigger:
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
FABRIC_VERSION: 2.2
|
FABRIC_VERSION: 2.2
|
||||||
|
GO_BIN: $(Build.Repository.LocalPath)/bin
|
||||||
|
GO_VER: 1.14.6
|
||||||
NODE_VER: 12.x
|
NODE_VER: 12.x
|
||||||
PATH: $(Build.Repository.LocalPath)/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
|
PATH: $(Build.Repository.LocalPath)/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
|
||||||
|
|
||||||
|
|
@ -68,6 +70,53 @@ jobs:
|
||||||
- template: templates/install-deps.yml
|
- template: templates/install-deps.yml
|
||||||
- template: templates/fabcar/azure-pipelines-typescript.yml
|
- template: templates/fabcar/azure-pipelines-typescript.yml
|
||||||
|
|
||||||
|
- job: Lint
|
||||||
|
displayName: Lint
|
||||||
|
pool:
|
||||||
|
vmImage: ubuntu-18.04
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
Basic-Application-Javascript:
|
||||||
|
DIRECTORY: asset-transfer-basic
|
||||||
|
LANGUAGE: javascript
|
||||||
|
TYPE: application
|
||||||
|
Basic-Chaincode-Go:
|
||||||
|
DIRECTORY: asset-transfer-basic
|
||||||
|
LANGUAGE: go
|
||||||
|
TYPE: chaincode
|
||||||
|
Basic-Chaincode-Javascript:
|
||||||
|
DIRECTORY: asset-transfer-basic
|
||||||
|
LANGUAGE: javascript
|
||||||
|
TYPE: chaincode
|
||||||
|
Basic-Chaincode-Typescript:
|
||||||
|
DIRECTORY: asset-transfer-basic
|
||||||
|
LANGUAGE: typescript
|
||||||
|
TYPE: chaincode
|
||||||
|
Ledger-Chaincode-Go:
|
||||||
|
DIRECTORY: asset-transfer-ledger-queries
|
||||||
|
LANGUAGE: go
|
||||||
|
TYPE: chaincode
|
||||||
|
Private-Chaincode-Go:
|
||||||
|
DIRECTORY: asset-transfer-private-data
|
||||||
|
LANGUAGE: go
|
||||||
|
TYPE: chaincode
|
||||||
|
Secured-Chaincode-Go:
|
||||||
|
DIRECTORY: asset-transfer-secured-agreement
|
||||||
|
LANGUAGE: go
|
||||||
|
TYPE: chaincode
|
||||||
|
steps:
|
||||||
|
- task: GoTool@0
|
||||||
|
inputs:
|
||||||
|
goBin: $(GO_BIN)
|
||||||
|
version: $(GO_VER)
|
||||||
|
displayName: Install GoLang
|
||||||
|
- task: NodeTool@0
|
||||||
|
inputs:
|
||||||
|
versionSpec: $(NODE_VER)
|
||||||
|
displayName: Install Node.js
|
||||||
|
- script: ./ci/scripts/lint.sh
|
||||||
|
displayName: Lint Code
|
||||||
|
|
||||||
- job: TestNetworkBasic
|
- job: TestNetworkBasic
|
||||||
displayName: Test Network
|
displayName: Test Network
|
||||||
pool:
|
pool:
|
||||||
|
|
|
||||||
47
ci/scripts/lint.sh
Executable file
47
ci/scripts/lint.sh
Executable file
|
|
@ -0,0 +1,47 @@
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
function print() {
|
||||||
|
GREEN='\033[0;32m'
|
||||||
|
NC='\033[0m'
|
||||||
|
echo
|
||||||
|
echo -e "${GREEN}${1}${NC}"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ "${LANGUAGE}" == "go" ]]; then
|
||||||
|
go get golang.org/x/tools/cmd/goimports
|
||||||
|
|
||||||
|
cd "${DIRECTORY}/${TYPE}-${LANGUAGE}"
|
||||||
|
print "Running go vet"
|
||||||
|
go vet ./...
|
||||||
|
|
||||||
|
print "Running gofmt"
|
||||||
|
output=$(gofmt -l -s $(go list -f '{{.Dir}}' ./...))
|
||||||
|
if [[ "${output}" != "" ]]; then
|
||||||
|
print "The following files contain formatting errors, please run 'gofmt -l -w <path>' to fix these issues:"
|
||||||
|
echo "${output}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
print "Running goimports"
|
||||||
|
output=$(goimports -l $(go list -f '{{.Dir}}' ./...))
|
||||||
|
if [[ "${output}" != "" ]]; then
|
||||||
|
print "The following files contain import errors, please run 'goimports -l -w <path>' to fix these issues:"
|
||||||
|
echo "${output}"
|
||||||
|
fi
|
||||||
|
elif [[ "${LANGUAGE}" == "javascript" ]]; then
|
||||||
|
npm install -g eslint
|
||||||
|
cd "${DIRECTORY}/${TYPE}-${LANGUAGE}"
|
||||||
|
print "Running ESLint"
|
||||||
|
if [[ "${TYPE}" == "chaincode" ]]; then
|
||||||
|
eslint *.js */**.js
|
||||||
|
else
|
||||||
|
eslint *.js
|
||||||
|
fi
|
||||||
|
elif [[ "${LANGUAGE}" == "typescript" ]]; then
|
||||||
|
npm install -g typescript tslint
|
||||||
|
cd "${DIRECTORY}/${TYPE}-${LANGUAGE}"
|
||||||
|
print "Running TSLint"
|
||||||
|
tslint --project .
|
||||||
|
else
|
||||||
|
echo "Language not supported"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Loading…
Reference in a new issue