Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: 🤖 spell checker file normalisation #17

Merged
merged 10 commits into from
Jun 10, 2024
24 changes: 6 additions & 18 deletions .github/actions/spell-checker/ignore_words.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
2fa
8Fdevelop
8f
8fdevelop
astro
Expand All @@ -26,25 +25,21 @@ customtitlesbydirectoryname
customTitlesByDirectoryName
ddos
dev
Develop
develop
Development
development
devs
dns
dnslink
ef
env
EnvVars
envvars
ethereum
eu
️Fleek
fleek
fleek's
fleekchangelog01mar11
fleekreleasenotes06
fleekxyz
fleek’s
flkservices
fmt
gatsby
Expand All @@ -69,13 +64,10 @@ lon
md
mdx
meilisearch
Meilisearch's
metamask
mp4
NavBar
navbar
nodejs
NodeJS
npm
openinnewtab
openInNewTab
Expand All @@ -96,7 +88,6 @@ sdk
signups
src
srcset
SrcSet
stylesheets
submenu
submenus
Expand All @@ -106,7 +97,6 @@ tld
todo
totp
txt
TypeScript
typescript
ui
url
Expand All @@ -117,22 +107,20 @@ walkthrough
webp
xyz
onchain
onchain
serverless
testnet
latencygraphic
onchain
geo
serverless
Vercel
vercel
permissionless
onchain
deplatform
APIs
serverless
apis
serverless
users
Functions’
users'
functions'
lodash
repos
users
users'
12 changes: 11 additions & 1 deletion .github/workflows/grammar-spell-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ jobs:
with:
fetch-depth: 0

- uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install Hunspell
run: |
sudo apt-get update
Expand All @@ -31,9 +35,15 @@ jobs:
echo

for file in $diff; do
output=$(hunspell -l -d en_US -p .github/actions/spell-checker/ignore_words.txt "$file")
normalizedFile=$(mktemp)

./scripts/markdown-normalizer.ts "$file" > "$normalizedFile"

output=$(hunspell -l -d en_US -p .github/actions/spell-checker/ignore_words.txt "$normalizedFile")
typos_count=$(echo "$output" | wc -l)

rm "$normalizedFile"

if [[ -n "$output" ]]; then
echo "🤓 Found the following typos in $file"
echo
Expand Down
32 changes: 32 additions & 0 deletions scripts/markdown-normalizer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bun

import fs from 'fs';

if (!process.argv.slice(1).length) {
console.error("👹 Oops! Missing the filename argument.");
process.exit(1);
}

const args = process.argv.slice(1);
const filePath = args[1];
const fileContent = fs.readFileSync(filePath, 'utf-8');

// Markdown headings
const re1 = /---[\s\S]*?---/g;
// Code blocks
const re2 = /```[\s\S]*?```/g;
// Named URL
const re3 = /\[.*?\]\(.*?\)/g;

try {
const content = fileContent
.replace(re1, '')
.replace(re2, '')
.replace(re3, '')
.toLowerCase();

process.stdout.write(content);
} catch (err) {
console.error("👹 Oops! Failed to normalize the file for some reason...");
process.exit(1);
}