github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/bin/run_lint_validator (about) 1 #!/bin/bash 2 # 3 # Copyright 2018 Intel Corporation 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # ------------------------------------------------------------------------------ 17 18 top_dir=$(cd $(dirname $(dirname $0)) && pwd) 19 20 dirs=" 21 $top_dir/validator 22 " 23 24 exitcode=0 25 26 rustfmt --version 27 28 for dir in $dirs; do 29 cd $dir 30 echo "$dir" 31 32 echo "-- rustfmt" 33 34 diff=$(cargo fmt -- --write-mode=diff) 35 rustfmt_exit=$? 36 37 # rustfmt returns the following exit codes: 38 # 39 # 0 = No errors 40 # 1 = Encountered operational errors e.g. an IO error 41 # 2 = Failed to reformat code because of parsing errors 42 # 3 = Code is valid, but it is impossible to format it properly 43 # 4 = Formatted code differs from existing code (write-mode diff only) 44 # 45 # Codes 3 and 4 both indicate formatting errors in the code, so 46 # they will be treated the same. 47 # 48 # This may change in the future. 49 # See https://github.com/rust-lang-nursery/rustfmt/issues/1977. 50 51 if [[ $rustfmt_exit != 0 ]]; then 52 exitcode=1 53 54 if [[ $rustfmt_exit == 1 ]]; then 55 echo "rustfmt encountered an operational error" 56 elif [[ $rustfmt_exit == 2 ]]; then 57 echo "Parsing error in $dir" 58 else 59 echo "Incorrect formatting: $dir" 60 echo -e $diff 61 fi 62 fi 63 64 done 65 66 exit $exitcode