<commit_before>#!/usr/bin/env bash

# Copyright 2021 The Kubernetes Authors.
#
# 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.

# This script checks coding style for go language files in each
# Kubernetes package by golint.
# Usage: `tools/verify-golint.sh`.

set -o errexit
set -o nounset
set -o pipefail

KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${KUBE_ROOT}/tools/lib/util.sh"

#kube::golang::verify_go_version

# Ensure that we find the binaries we build before anything else.
KUBE_ROOT_ABSOLUTE="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"

export GOBIN="${KUBE_ROOT_ABSOLUTE}/tools"
PATH="${GOBIN}:${PATH}"

# Install golint
echo 'installing golint'
pushd "${KUBE_ROOT}/tools" >/dev/null
  GO111MODULE=on go get -u golang.org/x/lint/golint
popd >/dev/null

cd "${KUBE_ROOT}"

# Check that the file is in alphabetical order
failure_file="${KUBE_ROOT}/tools/.golint_failures"
kube::util::check-file-in-alphabetical-order "${failure_file}"

export IFS=$'\n'
# NOTE: when "go list -e ./..." is run within GOPATH, it turns the k8s.io/cloud-provider-gcp
# as the prefix, however if we run it outside it returns the full path of the file
# with a leading underscore. We'll need to support both scenarios for all_packages.
all_packages=()
while IFS='' read -r line; do all_packages+=("$line"); done < <(go list -e ./... | grep -vE "/(third_party|vendor|staging/src/k8s.io/client-go/pkg|generated|clientset_generated)" | sed -e 's|^k8s.io/cloud-provider-gcp/||' -e "s|^_\(${KUBE_ROOT}/\)\{0,1\}||")
# The regex below removes any "#" character and anything behind it and including any
# whitespace before it. Then it removes empty lines.
failing_packages=()
while IFS='' read -r line; do failing_packages+=("$line"); done < <(sed -e 's/[[:blank:]]*#.*//' -e '/^$/d' "$failure_file")
unset IFS
errors=()
not_failing=()
for p in "${all_packages[@]}"; do
  # Run golint on package/*.go file explicitly to validate all go files
  # and not just the ones for the current platform. This also will ensure that
  # _test.go files are linted.
  # Generated files are ignored, and each file is passed through golint
  # individually, as if one file in the package contains a fatal error (such as
  # a foo package with a corresponding foo_test package), golint seems to choke
  # completely.
  # Ref: https://github.com/kubernetes/kubernetes/pull/67675
  # Ref: https://github.com/golang/lint/issues/68
  failedLint=$(find "$p"/*.go | grep -vE "(zz_generated.*.go|generated.pb.go|generated.proto|types_swagger_doc_generated.go)" | xargs -L1 golint 2>/dev/null)
  kube::util::array_contains "$p" "${failing_packages[@]}" && in_failing=$? || in_failing=$?
  if [[ -n "${failedLint}" ]] && [[ "${in_failing}" -ne "0" ]]; then
    errors+=( "${failedLint}" )<commit_msg>Remove redundant dir<commit_after>#!/usr/bin/env bash

# Copyright 2021 The Kubernetes Authors.
#
# 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.

# This script checks coding style for go language files in each
# Kubernetes package by golint.
# Usage: `tools/verify-golint.sh`.

set -o errexit
set -o nounset
set -o pipefail

KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${KUBE_ROOT}/tools/lib/util.sh"

#kube::golang::verify_go_version

# Ensure that we find the binaries we build before anything else.
KUBE_ROOT_ABSOLUTE="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"

export GOBIN="${KUBE_ROOT_ABSOLUTE}/tools"
PATH="${GOBIN}:${PATH}"

# Install golint
echo 'installing golint'
pushd "${KUBE_ROOT}/tools" >/dev/null
  GO111MODULE=on go get -u golang.org/x/lint/golint
popd >/dev/null

cd "${KUBE_ROOT}"

# Check that the file is in alphabetical order
failure_file="${KUBE_ROOT}/tools/.golint_failures"
kube::util::check-file-in-alphabetical-order "${failure_file}"

export IFS=$'\n'
# NOTE: when "go list -e ./..." is run within GOPATH, it turns the k8s.io/cloud-provider-gcp
# as the prefix, however if we run it outside it returns the full path of the file
# with a leading underscore. We'll need to support both scenarios for all_packages.
all_packages=()
while IFS='' read -r line; do all_packages+=("$line"); done < <(go list -e ./... | grep -vE "/vendor" | sed -e 's|^k8s.io/cloud-provider-gcp/||' -e "s|^_\(${KUBE_ROOT}/\)\{0,1\}||")
# The regex below removes any "#" character and anything behind it and including any
# whitespace before it. Then it removes empty lines.
failing_packages=()
while IFS='' read -r line; do failing_packages+=("$line"); done < <(sed -e 's/[[:blank:]]*#.*//' -e '/^$/d' "$failure_file")
unset IFS
errors=()
not_failing=()
for p in "${all_packages[@]}"; do
  # Run golint on package/*.go file explicitly to validate all go files
  # and not just the ones for the current platform. This also will ensure that
  # _test.go files are linted.
  # Generated files are ignored, and each file is passed through golint
  # individually, as if one file in the package contains a fatal error (such as
  # a foo package with a corresponding foo_test package), golint seems to choke
  # completely.
  # Ref: https://github.com/kubernetes/kubernetes/pull/67675
  # Ref: https://github.com/golang/lint/issues/68
  failedLint=$(find "$p"/*.go | grep -vE "(zz_generated.*.go|generated.pb.go|generated.proto|types_swagger_doc_generated.go)" | xargs -L1 golint 2>/dev/null)
  kube::util::array_contains "$p" "${failing_packages[@]}" && in_failing=$? || in_failing=$?
  if [[ -n "${failedLint}" ]] && [[ "${in_failing}" -ne "0" ]]; then
    errors+=( "${failedLint}" )
{'fraction_non_alphanumeric': 0.14709517923362175, 'fraction_numerical': 0.008498145859085291, 'mean_word_length': 4.380714879467996, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3674212', 'n_tokens_mistral': 2178, 'n_tokens_neox': 2094, 'n_words': 734}