github.com/apache/skywalking-eyes@v0.6.0/pkg/header/result.go (about)

     1  // Licensed to the Apache Software Foundation (ASF) under one
     2  // or more contributor license agreements.  See the NOTICE file
     3  // distributed with this work for additional information
     4  // regarding copyright ownership.  The ASF licenses this file
     5  // to you under the Apache License, Version 2.0 (the
     6  // "License"); you may not use this file except in compliance
     7  // with the License.  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,
    12  // software distributed under the License is distributed on an
    13  // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    14  // KIND, either express or implied.  See the License for the
    15  // specific language governing permissions and limitations
    16  // under the License.
    17  
    18  package header
    19  
    20  import (
    21  	"fmt"
    22  	"strings"
    23  )
    24  
    25  type Result struct {
    26  	Success []string
    27  	Failure []string
    28  	Ignored []string
    29  	Fixed   []string
    30  }
    31  
    32  func (result *Result) Fail(file string) {
    33  	result.Failure = append(result.Failure, file)
    34  }
    35  
    36  func (result *Result) Succeed(file string) {
    37  	result.Success = append(result.Success, file)
    38  }
    39  
    40  func (result *Result) Ignore(file string) {
    41  	result.Ignored = append(result.Ignored, file)
    42  }
    43  
    44  func (result *Result) Fix(file string) {
    45  	result.Fixed = append(result.Fixed, file)
    46  }
    47  
    48  func (result *Result) HasFailure() bool {
    49  	return len(result.Failure) > 0
    50  }
    51  
    52  func (result *Result) Error() error {
    53  	return fmt.Errorf(
    54  		"the following files don't have a valid license header: \n%v",
    55  		strings.Join(result.Failure, "\n"),
    56  	)
    57  }
    58  
    59  func (result *Result) String() string {
    60  	return fmt.Sprintf(
    61  		"Totally checked %d files, valid: %d, invalid: %d, ignored: %d, fixed: %d",
    62  		len(result.Success)+len(result.Failure)+len(result.Ignored),
    63  		len(result.Success),
    64  		len(result.Failure),
    65  		len(result.Ignored),
    66  		len(result.Fixed),
    67  	)
    68  }