Skip to content

Commit 1319c03

Browse files
committed
Add CONFIG.md - Configuration reference
Progressive disclosure file for shell-script-quality skill - ShellCheck configuration - Editor integration - Environment setup - Project configuration - Tools installation
1 parent 49c71a8 commit 1319c03

1 file changed

Lines changed: 345 additions & 0 deletions

File tree

Lines changed: 345 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,345 @@
1+
# Configuration Reference
2+
3+
Complete configuration guide for shell script quality tools.
4+
5+
## ShellCheck Configuration
6+
7+
### .shellcheckrc
8+
9+
Create `.shellcheckrc` in project root:
10+
11+
```bash
12+
# Shell dialect
13+
shell=bash
14+
15+
# Enable all optional checks
16+
enable=all
17+
18+
# Disable specific warnings
19+
# SC1090: Can't follow non-constant source
20+
# SC2034: Variable appears unused (for exports)
21+
disable=SC1090,SC2034
22+
23+
# Additional source paths
24+
source-path=SCRIPTDIR:./lib:./scripts
25+
26+
# External sources (for libraries)
27+
external-sources=true
28+
```
29+
30+
### Severity Levels
31+
32+
```bash
33+
# Only show errors
34+
shellcheck --severity=error script.sh
35+
36+
# Show warnings and errors
37+
shellcheck --severity=warning script.sh
38+
39+
# Show everything (default)
40+
shellcheck --severity=style script.sh
41+
```
42+
43+
### Per-Project Configs
44+
45+
**Strict Mode**:
46+
```bash
47+
cat > .shellcheckrc <<'EOF'
48+
shell=bash
49+
enable=all
50+
severity=error
51+
EOF
52+
```
53+
54+
**Relaxed Mode**:
55+
```bash
56+
cat > .shellcheckrc <<'EOF'
57+
shell=bash
58+
disable=SC1090,SC2034,SC2086,SC2155
59+
EOF
60+
```
61+
62+
## Editor Integration
63+
64+
### VS Code
65+
66+
**.vscode/settings.json**:
67+
```json
68+
{
69+
"shellcheck.enable": true,
70+
"shellcheck.executablePath": "shellcheck",
71+
"shellcheck.run": "onType",
72+
"shellcheck.exclude": ["SC1090"],
73+
"files.associations": {
74+
"*.sh": "shellscript",
75+
".shellcheckrc": "properties"
76+
}
77+
}
78+
```
79+
80+
Install extension:
81+
```bash
82+
code --install-extension timonwong.shellcheck
83+
```
84+
85+
### Vim/Neovim
86+
87+
**Using ALE**:
88+
```vim
89+
let g:ale_linters = {'sh': ['shellcheck']}
90+
let g:ale_sh_shellcheck_options = '-x'
91+
```
92+
93+
**Using Syntastic**:
94+
```vim
95+
let g:syntastic_sh_shellcheck_args = '-x'
96+
```
97+
98+
### Emacs
99+
100+
**Flycheck**:
101+
```elisp
102+
(require 'flycheck)
103+
(add-hook 'sh-mode-hook 'flycheck-mode)
104+
```
105+
106+
### JetBrains IDEs
107+
108+
Install ShellCheck plugin from marketplace:
109+
- Settings → Plugins → Search "ShellCheck"
110+
- Configure: Settings → Tools → ShellCheck
111+
112+
## BATS Configuration
113+
114+
### Installation Methods
115+
116+
**macOS (Homebrew)**:
117+
```bash
118+
brew install bats-core
119+
brew install bats-support bats-assert bats-file
120+
```
121+
122+
**Ubuntu/Debian**:
123+
```bash
124+
sudo apt-get install bats
125+
126+
# Or latest version
127+
git clone https://github.com/bats-core/bats-core.git
128+
cd bats-core
129+
sudo ./install.sh /usr/local
130+
```
131+
132+
**From npm**:
133+
```bash
134+
npm install -g bats
135+
```
136+
137+
### Helper Libraries
138+
139+
```bash
140+
# Install helper libraries
141+
git clone https://github.com/bats-core/bats-support test/test_helper/bats-support
142+
git clone https://github.com/bats-core/bats-assert test/test_helper/bats-assert
143+
git clone https://github.com/bats-core/bats-file test/test_helper/bats-file
144+
```
145+
146+
**Load in tests**:
147+
```bash
148+
load 'test_helper/bats-support/load'
149+
load 'test_helper/bats-assert/load'
150+
load 'test_helper/bats-file/load'
151+
```
152+
153+
## Environment Setup
154+
155+
### Development Environment
156+
157+
**direnv (.envrc)**:
158+
```bash
159+
export CLAUDE_PLUGIN_ROOT="$(pwd)"
160+
export LOG_LEVEL="DEBUG"
161+
export PATH="$PWD/scripts:$PATH"
162+
```
163+
164+
**bashrc/zshrc**:
165+
```bash
166+
# ShellCheck alias
167+
alias sc='shellcheck'
168+
alias sca='find . -name "*.sh" -exec shellcheck {} +'
169+
170+
# BATS alias
171+
alias bt='bats tests/'
172+
alias btv='bats -t tests/'
173+
```
174+
175+
### Docker Environment
176+
177+
**Dockerfile**:
178+
```dockerfile
179+
FROM ubuntu:22.04
180+
181+
RUN apt-get update && apt-get install -y \
182+
shellcheck \
183+
bats \
184+
curl \
185+
jq \
186+
&& rm -rf /var/lib/apt/lists/*
187+
188+
WORKDIR /workspace
189+
COPY . .
190+
191+
CMD ["bash", "scripts/check-quality.sh"]
192+
```
193+
194+
**docker-compose.yml**:
195+
```yaml
196+
version: '3.8'
197+
services:
198+
quality-check:
199+
build: .
200+
volumes:
201+
- .:/workspace
202+
command: bash scripts/check-quality.sh
203+
```
204+
205+
## Project Structure
206+
207+
### Recommended Layout
208+
209+
```
210+
project/
211+
├── .shellcheckrc # ShellCheck config
212+
├── .editorconfig # Editor config
213+
├── scripts/
214+
│ ├── main.sh
215+
│ ├── utils.sh
216+
│ └── check-quality.sh
217+
├── tests/
218+
│ ├── test_helper/
219+
│ │ ├── common.bash
220+
│ │ ├── bats-support/
221+
│ │ └── bats-assert/
222+
│ ├── main.bats
223+
│ └── utils.bats
224+
├── .github/
225+
│ └── workflows/
226+
│ └── quality.yml
227+
└── .gitignore
228+
```
229+
230+
### .editorconfig
231+
232+
```ini
233+
root = true
234+
235+
[*.sh]
236+
indent_style = space
237+
indent_size = 4
238+
end_of_line = lf
239+
charset = utf-8
240+
trim_trailing_whitespace = true
241+
insert_final_newline = true
242+
243+
[*.bats]
244+
indent_style = space
245+
indent_size = 4
246+
```
247+
248+
### .gitignore
249+
250+
```
251+
# Logs
252+
*.log
253+
254+
# Test artifacts
255+
*.tmp
256+
*.temp
257+
test-results/
258+
coverage/
259+
260+
# OS files
261+
.DS_Store
262+
Thumbs.db
263+
```
264+
265+
## CI/CD Tool Versions
266+
267+
### GitHub Actions
268+
269+
```yaml
270+
- name: Install specific versions
271+
run: |
272+
# ShellCheck latest
273+
wget -qO- "https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz" | tar -xJv
274+
sudo cp "shellcheck-stable/shellcheck" /usr/bin/
275+
276+
# BATS latest
277+
git clone --depth 1 https://github.com/bats-core/bats-core.git
278+
sudo bats-core/install.sh /usr/local
279+
```
280+
281+
### Version Pinning
282+
283+
```yaml
284+
- uses: ludeeus/action-shellcheck@2.0.0
285+
with:
286+
version: v0.9.0
287+
```
288+
289+
## Environment Variables
290+
291+
### ShellCheck
292+
293+
```bash
294+
# Custom config location
295+
export SHELLCHECK_OPTS="-x -a"
296+
297+
# Ignore specific codes
298+
export SHELLCHECK_OPTS="-e SC2086,SC2181"
299+
```
300+
301+
### BATS
302+
303+
```bash
304+
# Test timeout
305+
export BATS_TEST_TIMEOUT=30
306+
307+
# Formatter
308+
export BATS_FORMATTER="tap"
309+
```
310+
311+
## Quick Setup Script
312+
313+
**setup-quality-tools.sh**:
314+
```bash
315+
#!/bin/bash
316+
set -euo pipefail
317+
318+
echo "Setting up shell script quality tools..."
319+
320+
# Create directories
321+
mkdir -p tests/test_helper scripts
322+
323+
# Create .shellcheckrc
324+
cat > .shellcheckrc <<'EOF'
325+
shell=bash
326+
enable=all
327+
disable=SC1090
328+
source-path=SCRIPTDIR
329+
EOF
330+
331+
# Create basic test helper
332+
cat > tests/test_helper/common.bash <<'EOF'
333+
setup_test_env() {
334+
export TEST_ROOT="$(cd "$BATS_TEST_DIRNAME/.." && pwd)"
335+
export TEST_TEMP_DIR="$(mktemp -d)"
336+
}
337+
EOF
338+
339+
# Install tools (macOS)
340+
if command -v brew >/dev/null; then
341+
brew install shellcheck bats-core
342+
fi
343+
344+
echo "✅ Setup complete!"
345+
```

0 commit comments

Comments
 (0)