Skip to content

Commit 1869573

Browse files
authored
Add spell check script (#26228)
* Add spell check script Signed-off-by: Ricardo Pchevuzinske Katz <[email protected]> * Add instructions on how to run the spelling verification script Signed-off-by: Ricardo Pchevuzinske Katz <[email protected]>
1 parent cbbd860 commit 1869573

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

scripts/verify-spelling.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2019 The Kubernetes Authors.
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+
# This script verifies mispellings in location. Today it only supports
18+
# verifying English locale but can be modified in a future to support
19+
# also other locales.
20+
# You need to run this script inside the root directory of "website" git repo.
21+
#
22+
# Syntax: verify-spelling.sh LOCALE
23+
# Example: verify-spelling.sh en
24+
# If no locale is passed, it will assume "en"
25+
#
26+
# Requirements:
27+
# - go v1.14 or superior version
28+
29+
30+
31+
set -o errexit
32+
set -o nounset
33+
set -o pipefail
34+
35+
TOOL_VERSION="v0.3.4"
36+
37+
LANGUAGE="${1:-en}"
38+
# cd to the root path
39+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
40+
cd "${ROOT}"
41+
42+
# create a temporary directory
43+
TMP_DIR=$(mktemp -d)
44+
45+
# cleanup
46+
exitHandler() (
47+
echo "Cleaning up..."
48+
rm -rf "${TMP_DIR}"
49+
)
50+
trap exitHandler EXIT
51+
52+
# perform go get in a temp dir as we are not tracking this version in a go module
53+
# if we do the go get in the repo, it will create / update a go.mod and go.sum
54+
cd "${TMP_DIR}"
55+
GO111MODULE=on GOBIN="${TMP_DIR}" go get "github.com/client9/misspell/cmd/misspell@${TOOL_VERSION}"
56+
export PATH="${TMP_DIR}:${PATH}"
57+
cd "${ROOT}"
58+
59+
# check spelling
60+
RES=0
61+
echo "Checking spelling..."
62+
ERROR_LOG="${TMP_DIR}/errors.log"
63+
git ls-files | grep content/${LANGUAGE} | xargs misspell > "${ERROR_LOG}"
64+
if [[ -s "${ERROR_LOG}" ]]; then
65+
sed 's/^/error: /' "${ERROR_LOG}" # add 'error' to each line to highlight in e2e status
66+
echo "Found spelling errors!"
67+
RES=1
68+
fi
69+
exit "${RES}"

0 commit comments

Comments
 (0)