Skip to content

Commit 2aed506

Browse files
azure-sdkfanyang-monobenbpCopilot
authored
Sync eng/common directory with azure-sdk-tools for PR 11330 (#42340)
* Add shell script for spell check * Add shebang and make cspell script executable for bash invocation * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> * Apply suggestion from @benbp --------- Co-authored-by: Fan Yang <[email protected]> Co-authored-by: Ben Broderick Phillips <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 09da8e4 commit 2aed506

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

eng/common/spelling/Invoke-Cspell.ps1

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env pwsh
2+
13
<#
24
.SYNOPSIS
35
Invokes cspell using dependencies defined in adjacent ./package*.json

eng/common/spelling/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Spelling Check Scripts
2+
3+
This directory contains a script to run cspell (Code Spell Checker) on the repository using the dependencies defined in the adjacent `package*.json` files.
4+
5+
## Adding Legitimate Words
6+
7+
If the spell checker flags legitimate words as misspelled, you can add them to the dictionary configuration file located at `.vscode/cspell.json`.
8+
9+
### Where to Add Words
10+
11+
There are two main places to add legitimate words. Maintain alphabetical order when adding words to keep the dictionary organized:
12+
13+
1. **Root-level words array**: Add words to the `"words"` array at the root level of the configuration file. This is the preferred location for project-specific terms, technical vocabulary, and commonly used words.
14+
15+
2. **Baseline dictionary**: Add words to the `"baseline"` dictionary under `"dictionaryDefinitions"`. This is typically used for words that were already present in the codebase when the spell checker was first introduced.
16+
17+
18+
### Example
19+
20+
To add new words, edit `.vscode/cspell.json` and add them to the `"words"` array:
21+
22+
```json
23+
{
24+
"words": [
25+
"myprojectname",
26+
"customterm",
27+
"technicalword"
28+
]
29+
}
30+
```
31+
32+
### Guidelines
33+
34+
- Use lowercase for words
35+
- Consider whether the word is truly legitimate or if it might be a typo
36+
37+
## Available Scripts
38+
39+
### PowerShell Version (Windows)
40+
- **File**: `Invoke-Cspell.ps1`
41+
- **Usage**: For Windows PowerShell environments
42+
43+
## Usage Examples
44+
45+
```powershell
46+
# Check all files (default)
47+
./eng/common/spelling/Invoke-Cspell.ps1
48+
49+
# Check specific files
50+
./eng/common/spelling/Invoke-Cspell.ps1 -ScanGlobs 'sdk/*/*/PublicAPI/**/*.md'
51+
52+
# Check multiple globs (powershell invocation only)
53+
./eng/common/spelling/Invoke-Cspell.ps1 -ScanGlobs @('sdk/storage/**', 'sdk/keyvault/**')
54+
55+
# Check single file
56+
./eng/common/spelling/Invoke-Cspell.ps1 -ScanGlobs './README.md'
57+
```
58+
59+
## Parameters
60+
61+
- **Job Type**: The cspell command to run (default: `lint`)
62+
- **Scan Globs**: File patterns to check for spelling
63+
- **Config Path**: Location of the cspell.json configuration file
64+
- **Spell Check Root**: Root directory for relative paths
65+
- **Package Cache**: Working directory for npm dependencies
66+
- **Leave Cache**: Option to preserve the npm package cache
67+
68+
## Requirements
69+
70+
- Node.js and npm must be installed
71+
- The `.vscode/cspell.json` configuration file must exist
72+
- `jq` command-line JSON processor (for bash version)
73+
74+
## How It Works
75+
76+
1. Creates a temporary working directory for npm packages
77+
2. Copies `package.json` and `package-lock.json` to the working directory
78+
3. Installs npm dependencies using `npm ci`
79+
4. Modifies the cspell configuration to include specified file globs
80+
5. Runs cspell with the modified configuration
81+
6. Restores the original configuration
82+
7. Cleans up temporary files
83+
84+
The scripts ensure that a LICENSE file (or temporary file) is always included in the scan to meet cspell's requirements for the "files" array.

0 commit comments

Comments
 (0)