Skip to content

Commit

Permalink
Fix Vale by passing files to process instead of a glob to ignore (#3871)
Browse files Browse the repository at this point in the history
* Fix Vale by passing files to process instead of a glob to ignore

* Update .vale/justfile

* ignore node_modules

* Fix term casing context; update justfile recipe; fix Dockerfile order
  • Loading branch information
zackkrida authored Mar 8, 2024
1 parent bbea9e6 commit b09b865
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .vale/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ FROM jdkato/vale:v2.30.0

WORKDIR /vale
COPY .vale.ini .
COPY styles styles

RUN vale sync

COPY styles styles

ENTRYPOINT ["vale", "--config=/vale/.vale.ini"]
63 changes: 20 additions & 43 deletions .vale/justfile
Original file line number Diff line number Diff line change
@@ -1,64 +1,41 @@
COLOR := "\\033[0;34m"
NO_COLOR := "\\033[0m"


# Show all available recipes
@_default:
printf "\n{{ COLOR }}# Vale (path: \`.vale/\`)\n"
printf "===================={{ NO_COLOR }}\n"
just --list --unsorted


# Build a local version of `openverse-vale:local` for testing
build:
docker build . -t openverse-vale:local


# The --glob setting excludes things that should not be linted, including
# build artefacts, dependencies, and automatically generated files like
# the changelogs (without excluding `changelogs/index.md`). Project proposals
# are also excluded for want of a good way to ignore existing proposals and only
# lint _new_ proposals. Project proposals aren't "living documents" in the way
# the rest of our documentation is, so it doesn't seem right to retroactively
# edit them for mere editorial purposes (rather than, for example, to correct
# some grave inacurracy).
# Leading `,` compensates for lack of trailing comma support
# Note the lack of space before the trailing \ on each line, this is to prevent
# the addition of a space between each pattern, which isn't supported by Vale's glob
# If you change this and Vale takes a very long time to run (more than 30 seconds)
# then chances are the change is breaking the glob pattern. Unfortunately the only
# feedback you get when the glob pattern is not working as intended is a very long
# run time for Vale as it checks everything that should have otherwise been ignored,
# but wasn't due to some minor issue in the pattern syntax.
# This is fiddly, but I can't find a good way around it.
_IGNORE_PATTERNS := """
_build\
,_static\
,venv\
,.venv\
,.nuxt\
,.pnpm-store\
,node_modules\
,test-results\
,storebook-static\
,.ruff-cache\
,projects/proposals\
,changelogs/api\
,changelogs/frontend\
,changelogs/catalog\
,changelogs/ingestion_server\
"""

VALE_GLOB := "--glob='!*{" + _IGNORE_PATTERNS + "}*'"

IGNORE_FILES_PATTERN := ".pnpm|changelogs|projects/proposals|node_modules|.?venv"

# This recipe generates a list of Markdown and MDX files to be processed, excluding those
# matched by the IGNORE_FILES_PATTERN. Files are listed relative to the parent directory
# of the current working directory. If a custom separator is specified, newlines are
# replaced with this separator before outputting the file list.
@files separator="\n":
#! /usr/bin/env sh
files=$(
find "$PWD/.." -type f \( -name "*.md" -o -name "*.mdx" \) \
| grep -vE "{{ IGNORE_FILES_PATTERN }}" \
| sed "s|$PWD/../||"
)
if [ '{{ separator }}' != '\n' ]; then
echo "$files" | tr '\n' '{{ separator }}'
exit 0
fi
echo "$files"

# Run Vale configured for Openverse in Docker.
# Using Docker avoids the need for contributors to install the Vale binary.
#Configuration defaults to what is used for CI.
run +files=".": build
run: build
docker run --rm \
-v $PWD/..:/src:rw,Z \
--workdir=/src \
openverse-vale:local \
{{ files }} \
{{ VALE_GLOB }}
{{ "`just files`" }}
2 changes: 1 addition & 1 deletion .vale/styles/Openverse/TermCasing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ message: "Incorrect casing. Use '%s' instead of '%s'."
level: error
ignorecase: false
scope:
- paragraph
- text
swap:
# [^/\.] prevents matching things that look like URLs, file paths, or GitHub team mentions
# For example: @WordPress/openverse-maintainers
Expand Down

0 comments on commit b09b865

Please sign in to comment.