A cross-platform Rust library for resolving XDG and platform-specific directories with proper fallbacks.
1# Contributing to dir_spec
2
3Thank you for your interest in contributing to dir_spec! This guide will help you get set up and understand our
4development workflow.
5
6## Quick Start
7
8### Prerequisites
9
10- **Rust**: Install via [rustup](https://rustup.rs/)
11- **Git**: For version control
12
13### Development Setup (Recommended: mise)
14
15We **strongly recommend** using [mise](https://mise.jdx.dev/) for tool management as it automatically handles all
16dependencies and toolchain setup:
17
181. **Clone the repository**
19
20 ```bash
21 git clone https://github.com/aaronmallen/dir_spec.git
22 cd dir_spec
23 ```
24
252. **Install mise**
26
27 ```bash
28 curl https://mise.jdx.dev/install.sh | sh
29 ```
30
313. **Install tools and dependencies**
32
33 ```bash
34 mise install
35 mise run setup
36 ```
37
384. **Verify setup**
39
40 ```bash
41 mise run test
42 mise run lint:check:rust
43 ```
44
45### Alternative: Manual Setup
46
47If you prefer not to use mise, you can use our setup script:
48
491. **Install Rust toolchain**
50
51 ```bash
52 # The project will automatically use the toolchain specified in rust-toolchain.toml
53 rustup component add clippy rustfmt
54 ```
55
562. **Install development tools**
57
58 ```bash
59 ./bin/setup
60 ```
61
623. **Verify setup**
63
64 ```bash
65 ./bin/test/_default
66 ./bin/lint/check/rust
67 ```
68
69## Development Workflow
70
71### Running Tests
72
73```bash
74# Recommended: Use mise
75mise run test
76
77# Without mise: Use bin scripts
78./bin/test
79```
80
81### Code Formatting and Linting
82
83We use several tools to maintain code quality:
84
85```bash
86# Recommended: Use mise
87mise run lint:check:rust # Check formatting, imports, and clippy
88mise run lint:fix:rust # Auto-fix formatting and imports
89mise run lint:check:md # Check markdown formatting
90mise run lint:fix:md # Auto-fix markdown formatting
91
92# Without mise: Use bin scripts
93./bin/lint/check/rust # Check formatting, imports, and clippy
94./bin/lint/fix/rust # Auto-fix formatting and imports
95./bin/lint/check/markdown # Check markdown formatting
96./bin/lint/fix/markdown # Auto-fix markdown formatting
97
98# Run all checks at once
99./bin/lint/_default # Check everything
100./bin/lint/fix/_default # Fix everything
101```
102
103### Running All CI Checks
104
105To run the same checks that CI runs:
106
107```bash
108# Recommended: Use mise
109mise run ci
110
111# Without mise: Use bin scripts
112./bin/ci
113```
114
115### Other Useful Commands
116
117```bash
118# Build the project
119./bin/build
120
121# Check for dependency updates and security issues
122./bin/audit
123
124# Clean build artifacts
125./bin/clean
126```
127
128**Our linting includes:**
129
130- **cargo-sort**: Ensures `Cargo.toml` dependencies are sorted
131- **rustfmt**: Code formatting (configured in `rustfmt.toml`)
132- **clippy**: Lint checks for common mistakes and improvements
133- **markdownlint**: Markdown file linting
134
135### Code Style
136
137- **Formatting**: We use `rustfmt` with custom settings (see `rustfmt.toml`)
138- **Imports**: Sorted and grouped by `StdExternalCrate`
139- **Line length**: 120 characters max
140- **Indentation**: 2 spaces (no tabs)
141
142### Making Changes
143
144#### Create a feature branch
145
146```bash
147git checkout -b feature/your-feature-name
148```
149
150#### *Make your changes
151
152- Add tests for new functionality
153- Update documentation as needed
154- Follow existing code patterns
155
156#### Test your changes
157
158```bash
159# Recommended: Use mise
160mise run test
161mise run lint:check:rust
162
163# Without mise: Use bin scripts
164./bin/test
165./bin/lint/check/rust
166```
167
168#### Commit your changes
169
170```bash
171git add .
172git commit -m "feat: add support for XYZ"
173```
174
175#### Push and create a PR
176
177```bash
178git push origin feature/your-feature-name
179```
180
181## Testing Guidelines
182
183### Platform Coverage
184
185This crate supports Linux, macOS, and Windows. When adding new features:
186
187- **Test on your platform** during development
188- **Consider all platforms** in your implementation
189- **Use `#[cfg(target_os = "...")]`** for platform-specific code
190- **CI will test** on all platforms automatically
191
192### Test Categories
193
194- **Unit tests**: Test individual functions and edge cases
195- **Integration tests**: Test the full API surface
196- **Platform-specific tests**: Verify platform conventions are followed
197
198### Writing Tests
199
200```rust
201#[cfg(test)]
202mod tests {
203 use super::*;
204
205 #[test]
206 fn test_config_home_xdg_override() {
207 // Test XDG environment variable override
208 }
209
210 #[test]
211 #[cfg(target_os = "linux")]
212 fn test_config_home_linux_default() {
213 // Test Linux-specific defaults
214 }
215}
216```
217
218## XDG Compliance
219
220This crate prioritizes XDG compliance across all platforms:
221
222### Key Principles
223
2241. **XDG variables take precedence** on all platforms
2252. **Platform conventions** are used as fallbacks
2263. **Consistent behavior** across operating systems
2274. **Proper error handling** for missing directories
228
229### Adding New Directories
230
231When adding support for new directories:
232
2331. **Research platform conventions**
234
235 - Linux: Follow XDG Base Directory Specification
236 - macOS: Use native `~/Library/*` locations
237 - Windows: Use appropriate `%APPDATA%` or `%LOCALAPPDATA%` paths
238
2392. **Implement XDG-first logic**
240
241 ```rust
242 pub fn new_directory() -> Result<PathBuf> {
243 if let Ok(xdg_var) = env::var("XDG_NEW_HOME") {
244 return Ok(PathBuf::from(xdg_var));
245 }
246
247 // Platform-specific fallbacks
248 #[cfg(target_os = "linux")]
249 { /* Linux default */ }
250
251 #[cfg(target_os = "macos")]
252 { /* macOS default */ }
253
254 #[cfg(target_os = "windows")]
255 { /* Windows default */ }
256 }
257 ```
258
2593. **Update documentation**
260
261- Add to the table in README.md
262- Include examples in doc comments
263
264## Pull Request Guidelines
265
266### Before Submitting
267
268- [ ] Code passes all tests (`mise run test` or `./bin/test`)
269- [ ] Code passes all lints (`mise run lint:check:rust` or `./bin/lint/check/rust`)
270- [ ] Documentation is updated if needed
271- [ ] Platform-specific behavior is documented
272- [ ] XDG compliance is maintained
273
274### PR Description
275
276Please include:
277
278- **What**: Brief description of changes
279- **Why**: Motivation for the change
280- **Platform impact**: Any platform-specific considerations
281- **Testing**: How you tested the changes
282
283### Review Process
284
2851. **Automated checks** must pass (CI)
2862. **Code review** by maintainers
2873. **Testing** on multiple platforms (via CI)
2884. **Merge** once approved
289
290## Getting Help
291
292- **Issues**: Open an issue for bugs or feature requests
293- **Discussions**: Use GitHub Discussions for questions
294- **Documentation**: Check the README.md and code comments
295
296## References
297
298Understanding these specifications will help with contributions:
299
300- [XDG Base Directory Specification][xdg-spec]
301- [Apple File System Programming Guide][apple-guide]
302- [Windows Known Folder IDs][windows-folders]
303
304[xdg-spec]: https://specifications.freedesktop.org/basedir-spec/latest/
305[apple-guide]:
306 https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/
307[windows-folders]: https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid
308
309## License
310
311By contributing to dir_spec, you agree that your contributions will be licensed under the MIT License.