Skip to content

Commit 612dfc0

Browse files
committed
Restructure contribution documentation and add formatter templates
Break down the monolithic CONTRIBUTING.md into focused files in docs/contributing/, eliminate duplicated information, and add templates for new formatter development. The new structure provides clearer separation of concerns and removes redundancy while adding practical templates and examples for contributors. Assisted-by: Opencode (GLM-4.6)
1 parent 1aadefa commit 612dfc0

14 files changed

+394
-194
lines changed

AGENTS.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Agent Instructions
2+
3+
This file contains instructions for AI agents working on this repository.
4+
5+
## Development Commands
6+
7+
| Command | Description |
8+
| ------------------ | -------------------------------- |
9+
| `composer install` | Install dependencies |
10+
| `composer test` | Run all tests |
11+
| `composer lint` | Check PSR-12 compliance |
12+
| `composer format` | Fix coding style automatically |
13+
| `composer analyze` | Run static analysis with PHPStan |
14+
15+
## Testing & Quality Standards
16+
17+
- **Unit tests**: Located in `tests/Unit/`
18+
- **All contributions must include tests that pass**
19+
- **Code style**: Follow PSR-12 coding standard
20+
- **Static analysis**: Use PHPStan, fix any issues before submitting
21+
22+
## Formatter Development
23+
24+
When creating new formatters:
25+
26+
1. **Class template**: `docs/contributing/templates/php/src/TemplateFormatter.php`
27+
2. **Test template**: `docs/contributing/templates/php/tests/TemplateFormatterTest.php`
28+
3. **Documentation template**: `docs/contributing/templates/formatter-documentation-template.md`
29+
30+
All formatters must implement the `Respect\StringFormatter\Formatter` interface.
31+
32+
## Commit Guidelines
33+
34+
Follow the detailed rules in `docs/contributing/commit-guidelines.md`:
35+
- Title: 5-116 characters, imperative mood, starts with capital
36+
- Body: Explain WHY, max 116 characters per line
37+
- Footer: Use trailers for references and AI attribution
38+
39+
## Repository Structure
40+
41+
- `/src/` - Formatter implementations
42+
- `/tests/Unit/` - Unit tests
43+
- `/docs/` - Documentation including formatter docs
44+
- `/docs/contributing/` - Contribution guidelines and templates
45+
46+
## Before Submitting Changes
47+
48+
1. Run composer commands: `test`, `lint`, `analyze`
49+
2. Ensure documentation follows templates
50+
3. Check commit message follows guidelines
51+
4. Verify all tests pass
52+
53+
Remember: Reference external docs rather than duplicating information in this file.

CONTRIBUTING.md

Lines changed: 8 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -1,199 +1,14 @@
11
# Contributing to StringFormatter
22

3-
Thank you for considering contributing to StringFormatter! This document provides guidelines and information for contributors.
3+
Thank you for considering contributing to StringFormatter! This document provides an overview of the contribution process.
44

5-
## Getting Started
5+
For detailed guidelines, see the [contributing documentation](docs/contributing/):
66

7-
### Prerequisites
8-
9-
- PHP 8.5 or higher
10-
- Composer
11-
- Git
12-
13-
### Setting Up the Development Environment
14-
15-
1. **Fork the repository**
16-
17-
```bash
18-
# Fork the repository on GitHub, then clone your fork
19-
git clone https://github.com/yourusername/StringFormatter.git
20-
cd StringFormatter
21-
```
22-
23-
2. **Install dependencies**
24-
25-
```bash
26-
composer install
27-
```
28-
29-
3. **Run tests**
30-
31-
```bash
32-
composer test
33-
```
34-
35-
## How to Contribute
36-
37-
### Adding New Formatters
38-
39-
StringFormatter is designed to be extensible. All formatters must implement the `Respect\StringFormatter\Formatter` interface.
40-
41-
**Steps to add a new formatter:**
42-
43-
1. **Create the formatter class**
44-
45-
```php
46-
<?php
47-
48-
declare(strict_types=1);
49-
50-
namespace Respect\StringFormatter;
51-
52-
final readonly class YourFormatter implements Formatter
53-
{
54-
public function format(string $input): string
55-
{
56-
// Your formatting implementation
57-
return $formattedInput;
58-
}
59-
}
60-
```
61-
62-
2. **Create tests**
63-
64-
```php
65-
<?php
66-
// tests/Unit/YourFormatterTest.php
67-
68-
declare(strict_types=1);
69-
70-
namespace Respect\StringFormatter\Test\Unit;
71-
72-
use PHPUnit\Framework\TestCase;
73-
use Respect\StringFormatter\YourFormatter;
74-
75-
final class YourFormatterTest extends TestCase
76-
{
77-
// Test your formatter implementation
78-
}
79-
```
80-
81-
3. **Add documentation**
82-
- Create `docs/YourFormatter.md` following the template used by MaskFormatter
83-
- Include usage examples, API reference, and any special considerations
84-
85-
4. **Update README.md**
86-
- Add your formatter to the "Formatters" table
87-
88-
### Testing
89-
90-
- **Unit tests**: Located in `tests/Unit/`
91-
- **Run all tests**: `composer test`
92-
93-
All contributions must include tests that pass.
94-
95-
### Code Style
96-
97-
This project follows the PSR-12 coding standard via the Respect Coding Standard. Run the following command before submitting:
98-
99-
```bash
100-
composer lint # Check coding style
101-
composer format # Fix coding style automatically
102-
```
103-
104-
### Static Analysis
105-
106-
This project uses PHPStan for static analysis. Run:
107-
108-
```bash
109-
composer analyze # Run static analysis
110-
```
111-
112-
### Submitting Changes
113-
114-
1. **Create a feature branch**
115-
116-
```bash
117-
git checkout -b feature/your-feature-name
118-
```
119-
120-
2. **Make your changes**
121-
- Add your formatter implementation
122-
- Include comprehensive tests
123-
- Update documentation
124-
- Follow PSR-12 coding standards
125-
126-
3. **Test your changes**
127-
128-
```bash
129-
composer test # Run tests
130-
composer lint # Check code style
131-
composer format # Fix coding style automatically
132-
composer analyze # Run static analysis
133-
```
134-
135-
4. **Commit your changes**
136-
137-
```bash
138-
git add .
139-
git commit -m "Add YourFormatter for [purpose]"
140-
```
141-
142-
5. **Push and create a pull request**
143-
144-
```bash
145-
git push origin feature/your-feature-name
146-
```
147-
148-
Then create a pull request on GitHub with:
149-
150-
- Clear description of the changes
151-
- Link to any relevant issues
152-
- Explain the use case and benefits
153-
154-
## Development Commands
155-
156-
| Command | Description |
157-
| ------------------ | -------------------------------- |
158-
| `composer install` | Install dependencies |
159-
| `composer test` | Run all tests |
160-
| `composer lint` | Check PSR-12 compliance |
161-
| `composer format` | Fix coding style automatically |
162-
| `composer analyze` | Run static analysis with PHPStan |
163-
164-
## Guidelines
165-
166-
### Do
167-
168-
- Write clear, well-documented code
169-
- Include comprehensive tests
170-
- Follow PSR-12 coding standards
171-
- Use type declarations everywhere
172-
- Write commit messages that explain the "why" not just the "what"
173-
174-
### Don't
175-
176-
- Submit changes without tests
177-
- Break backward compatibility unless necessary
178-
- Use PHP without strict typing
179-
- Commit sensitive information
180-
- Mix multiple concerns in a single PR
181-
182-
## Reporting Issues
183-
184-
When reporting issues, please include:
185-
186-
- PHP version
187-
- Library version
188-
- Complete error messages
189-
- Minimal reproducible example
190-
- Expected vs actual behavior
191-
192-
## Questions
193-
194-
If you have questions about contributing, feel free to:
195-
196-
- Open an issue with the "question" label
197-
- Start a discussion in the repository discussions
7+
- [Getting Started](docs/contributing/getting-started.md) - Set up your development environment
8+
- [Guidelines](docs/contributing/guidelines.md) - Best practices
9+
- [Adding Formatters](docs/contributing/adding-formatters.md) - How to create new formatters
10+
- [Development](docs/contributing/development.md) - Testing, linting, and static analysis
11+
- [Submitting Changes](docs/contributing/submitting-changes.md) - Pull request process
12+
- [Commit Guidelines](docs/contributing/commit-guidelines.md) - How to write good commit messages
19813

19914
Thank you for contributing to StringFormatter! 🎉

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
},
2323
"autoload-dev": {
2424
"psr-4": {
25-
"Respect\\StringFormatter\\Test\\": "tests/"
25+
"Respect\\StringFormatter\\": ["docs/contributing/templates/php/src"],
26+
"Respect\\StringFormatter\\Test\\": ["tests/", "docs/contributing/templates/php/tests"]
2627
}
2728
},
2829
"authors": [
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Adding New Formatters
2+
3+
StringFormatter is designed to be extensible. All formatters must implement the `Respect\StringFormatter\Formatter` interface.
4+
5+
**Steps to add a new formatter:**
6+
7+
1. **Create the formatter class**
8+
9+
Copy and rename the [TemplateFormatter.php](templates/php/src/TemplateFormatter.php) as a starting point.
10+
11+
2. **Create tests**
12+
13+
Copy and rename the [TemplateFormatterTest.php](templates/php/tests/TemplateFormatterTest.php) as a starting point.
14+
15+
3. **Add documentation**
16+
- Create `docs/YourFormatter.md` following the [formatter documentation template](templates/formatter-documentation-template.md)
17+
18+
4. **Update README.md**
19+
- Add your formatter to the "Formatters" table
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Commit Message Guidelines
2+
3+
Follow these guidelines for writing clear, consistent commit messages.
4+
5+
## Title
6+
7+
- Contains 5-116 characters
8+
- Start with capital letter (A-Z)
9+
- Use imperative mood ("Add feature" not "Added feature")
10+
- No ticket numbers in title (use footer instead)
11+
- No trailing whitespace
12+
13+
## Body
14+
15+
- Explain WHY and maybe a bit of HOW
16+
- Empty line required between title and body
17+
- Max 116 characters per line (except URLs, code blocks, footer annotations)
18+
- 5 characters
19+
20+
## Footer
21+
22+
Use trailers to provide additional context when there's value to it:
23+
24+
- `Reference: https://github.com/example/project/issues/123` - Only when linking to a specific, relevant issue or PR
25+
- `Assisted-by: Tool/Agent (<Model/Version>)` - When AI assistance was provided
26+
27+
## Examples
28+
29+
### Good commit message
30+
31+
```
32+
Add uppercase formatter with UTF-8 support
33+
34+
The new UpperCaseFormatter provides proper UTF-8 handling for
35+
international characters, converting strings to uppercase while
36+
maintaining accent marks and special characters.
37+
38+
This addresses the need for proper internationalization support
39+
when manipulating text in various languages.
40+
41+
Reference: https://github.com/example/project/issues/123
42+
```
43+
44+
### Bad commit message
45+
46+
```
47+
added upper case stuff
48+
49+
fixes #123
50+
```
51+
52+
The bad example uses lowercase, doesn't explain the reasoning, and
53+
includes the issue number in the title instead of the footer.

docs/contributing/development.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Development Commands
2+
3+
| Command | Description |
4+
| ------------------ | -------------------------------- |
5+
| `composer install` | Install dependencies |
6+
| `composer test` | Run all tests |
7+
| `composer lint` | Check PSR-12 compliance |
8+
| `composer format` | Fix coding style automatically |
9+
| `composer analyze` | Run static analysis with PHPStan |
10+
11+
## Testing
12+
13+
- **Unit tests**: Located in `tests/Unit/`
14+
- **Run all tests**: `composer test`
15+
16+
All contributions must include tests that pass.
17+
18+
## Code Style
19+
20+
This project follows the PSR-12 coding standard via the Respect Coding Standard. Run the following command before submitting:
21+
22+
```bash
23+
composer lint # Check coding style
24+
composer format # Fix coding style automatically
25+
```
26+
27+
## Static Analysis
28+
29+
This project uses PHPStan for static analysis. Run:
30+
31+
```bash
32+
composer analyze # Run static analysis
33+
```

0 commit comments

Comments
 (0)