Skip to content

Commit bc4df7e

Browse files
committed
docs: add CONTRIBUTING.md with contribution guidelines
1 parent 43417f9 commit bc4df7e

1 file changed

Lines changed: 254 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
# Contributing to filesize.js
2+
3+
Thank you for your interest in contributing to filesize.js! This document outlines the process for contributing to the project.
4+
5+
## Table of Contents
6+
7+
- [Getting Started](#getting-started)
8+
- [Reporting Issues](#reporting-issues)
9+
- [Development Workflow](#development-workflow)
10+
- [Testing](#testing)
11+
- [Code Style](#code-style)
12+
- [Commit Messages](#commit-messages)
13+
- [Pull Request Process](#pull-request-process)
14+
- [License](#license)
15+
16+
## Getting Started
17+
18+
1. Fork the repository
19+
2. Clone your fork:
20+
```bash
21+
git clone https://github.com/your-username/filesize.js.git
22+
cd filesize.js
23+
```
24+
3. Install dependencies:
25+
```bash
26+
npm install
27+
```
28+
4. Start development mode:
29+
```bash
30+
npm run dev
31+
```
32+
33+
## Reporting Issues
34+
35+
Before reporting an issue, please search existing issues to avoid duplicates.
36+
37+
When creating a new issue, include:
38+
- A clear, descriptive title
39+
- Steps to reproduce the problem
40+
- Expected vs. actual behavior
41+
- Environment details (Node.js version, OS, browser)
42+
- Code samples if applicable
43+
44+
## Development Workflow
45+
46+
### Project Structure
47+
48+
```
49+
filesize.js/
50+
├── src/
51+
│ ├── filesize.js # Main implementation
52+
│ ├── helpers.js # Helper functions
53+
│ └── constants.js # Constants and lookup tables
54+
├── tests/
55+
│ └── unit/ # Unit tests
56+
├── dist/ # Built distributions (generated)
57+
└── types/ # TypeScript definitions
58+
```
59+
60+
### Building
61+
62+
```bash
63+
npm run build # Build all distributions
64+
npm run build:watch # Watch mode for development
65+
npm run build:analyze # Analyze bundle sizes
66+
```
67+
68+
### Distribution Files
69+
70+
- `dist/filesize.cjs` - CommonJS
71+
- `dist/filesize.js` - ES Module
72+
- `dist/filesize.min.js` - Minified ES Module
73+
- `dist/filesize.umd.js` - UMD (browser)
74+
- `dist/filesize.umd.min.js` - Minified UMD
75+
76+
## Testing
77+
78+
### Running Tests
79+
80+
```bash
81+
npm test # Run all tests (lint + node:test)
82+
npm run test:watch # Live test watching
83+
```
84+
85+
### Coverage Requirements
86+
87+
- **100% test coverage** is required for all changes
88+
- Coverage includes: statements, branches, functions, and lines
89+
- Run with coverage: `npm test`
90+
91+
### Writing Tests
92+
93+
Tests use Node.js built-in test runner (`node:test`):
94+
95+
```javascript
96+
import assert from 'node:assert';
97+
import { describe, it } from 'node:test';
98+
import { filesize } from '../../src/filesize.js';
99+
100+
describe('Feature', () => {
101+
it('should do something', () => {
102+
const result = filesize(1024);
103+
assert.strictEqual(result, '1.02 kB');
104+
});
105+
});
106+
```
107+
108+
### Test Coverage
109+
110+
```
111+
------------|---------|----------|---------|---------|-------------------
112+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
113+
------------|---------|----------|---------|---------|-------------------
114+
All files | 100 | 100 | 100 | 100 |
115+
------------|---------|----------|---------|---------|-------------------
116+
```
117+
118+
## Code Style
119+
120+
### Linting
121+
122+
We use oxlint (Rust-based, fast):
123+
124+
```bash
125+
npm run lint # Check code style
126+
npm run lint:fix # Auto-fix issues
127+
```
128+
129+
### Formatting
130+
131+
We use oxfmt (Rust-based, fast):
132+
133+
```bash
134+
npm run format:fix # Format code
135+
```
136+
137+
### Conventions
138+
139+
- **JSDoc**: Use JSDoc standard for all functions and classes
140+
- **Naming**:
141+
- Functions: camelCase (`handleZeroValue`, `applyPrecisionHandling`)
142+
- Constants: UPPER_SNAKE_CASE (`IEC`, `JEDEC`, `BINARY_POWERS`)
143+
- **Imports**: Group by source, alphabetize
144+
- **Principles**: DRY, KISS, YAGNI, SOLID
145+
- **Security**: OWASP best practices
146+
147+
### Code Style Example
148+
149+
```javascript
150+
/**
151+
* Description
152+
* @param {type} param - Description
153+
* @returns {type} Description
154+
*/
155+
export function functionName(param) {
156+
// Implementation
157+
}
158+
159+
// Constants
160+
export const CONSTANT_NAME = 'value';
161+
162+
// Imports: group by source, alphabetize
163+
import {
164+
ARRAY,
165+
BIT,
166+
BYTE
167+
} from './constants.js';
168+
import {
169+
helperFunction
170+
} from './helpers.js';
171+
```
172+
173+
## Commit Messages
174+
175+
We follow [Conventional Commits](https://www.conventionalcommits.org/):
176+
177+
```
178+
<type>(<scope>): <description>
179+
180+
[optional body]
181+
182+
[optional footer]
183+
```
184+
185+
### Types
186+
187+
- `feat`: New feature
188+
- `fix`: Bug fix
189+
- `docs`: Documentation
190+
- `refactor`: Code restructuring
191+
- `build`: Build system changes
192+
- `test`: Test additions/fixes
193+
- `chore`: Maintenance tasks
194+
195+
### Examples
196+
197+
```
198+
feat: add precision option for significant digits
199+
fix: correct bits auto-increment with forced exponent
200+
docs: update README with TypeScript examples
201+
refactor: simplify exponent auto-detection logic
202+
build: update rollup configuration
203+
test: add coverage for NaN exponent edge case
204+
```
205+
206+
## Pull Request Process
207+
208+
1. **Create a branch**:
209+
```bash
210+
git checkout -b feature/your-feature-name
211+
```
212+
213+
2. **Make your changes** and ensure:
214+
- All tests pass (`npm test`)
215+
- 100% test coverage is maintained
216+
- Code is formatted (`npm run format:fix`)
217+
- No linting errors (`npm run lint`)
218+
219+
3. **Build the project**:
220+
```bash
221+
npm run build
222+
```
223+
224+
4. **Commit your changes**:
225+
```bash
226+
git commit -m "type: description"
227+
```
228+
229+
5. **Push to your fork**:
230+
```bash
231+
git push origin feature/your-feature-name
232+
```
233+
234+
6. **Open a Pull Request**:
235+
- Provide a clear title and description
236+
- Reference any related issues
237+
- Include test coverage for changes
238+
239+
### PR Checklist
240+
241+
- [ ] Tests pass (`npm test`)
242+
- [ ] 100% test coverage maintained
243+
- [ ] Code is formatted
244+
- [ ] No linting errors
245+
- [ ] Documentation updated (if applicable)
246+
- [ ] Build successful (`npm run build`)
247+
248+
## License
249+
250+
By contributing to filesize.js, you agree that your contributions will be licensed under the BSD-3 license.
251+
252+
---
253+
254+
Thank you for contributing to filesize.js!

0 commit comments

Comments
 (0)