This is an excerpt from an article about Vale I wrote for the Stream Blog.
To integrate Vale with Xcode we need to do some more work. There is not an Xcode plugin available at the moment allowing easy integration with Vale.But fortunately, the Vale tool itself is very flexible. Here’s how to integrate:
.styles
folder of your repository containing your Xcode project..styles
, create a file names: xcode-line.tmpl
. The contents of this file should be:
{{range .Files}}
{{- $path := .Path -}}
{{- range .Alerts -}}
{{$path}}:{{.Line}}:{{index .Span 0}}: {{.Severity}}: {{.Check}}:{{.Message}}
{{end -}}
{{end -}}
vale-linting.sh
in the directory bin
at the root of your project.
a. Change the directory in your terminal at the root of your project.
b. Run mkdir bin
if the bin
directory does not exist yet.
c. Next, run touch bin/vale-linting.sh
.
d. Make sure your new script is executable by running: chmod +xu bin/vale-linting.sh
.
e. Edit the vale-linting.sh file with your text editor of choice and make sure the contents of the file are:
if ! which vale >/dev/null; then
if ! which brew >/dev/null; then # If it's not found, check the Homebrew location and update PATH when needed
if test -e "/usr/local/bin/brew"; then # Default Homebrew location (pre M1 era)
PATH="${PATH}:/usr/local/bin"
elif test -e "/opt/homebrew/bin/brew"; then # Default Homebrew location (M1 era)
PATH="${PATH}:/opt/homebrew/bin"
else
echo "warning: Homebrew not found at default location"
fi
fi
fi
if which vale >/dev/null; then
vale --output=./.styles/xcode-line.tmpl docusaurus
else
echo "warning: Vale not installed, download from https://vale.sh"
fi
f. Finally, add a custom build script step to your build target.
./bin/vale-lint.sh
.Stream’s Swift Chat SDK has a working setup based on the above.