Skip to content

Commit f3ae29d

Browse files
committed
docs: add contributing guidelines for collaborators
1 parent 60f69d6 commit f3ae29d

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

CONTRIBUTING.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Express Collaborator Guide
2+
3+
This document contains information for Collaborators of the express codemod regarding maintaining the code, documentation.
4+
5+
## Getting Started
6+
7+
1. [Create an issue](https://github.com/expressjs/codemod/issues/new) for the
8+
bug you want to fix or the feature that you want to add.
9+
2. Create your own [fork](https://github.com/expressjs/codemod) on GitHub, then
10+
checkout your fork.
11+
3. Write your code in your local copy. It's good practice to create a branch for
12+
each new issue you work on, although not compulsory.
13+
4. To run the test suite, first install the dependencies by running `npm install`,
14+
then run `npm test`.
15+
5. Ensure your code is linted by running `npm run lint` -- fix any issue you
16+
see listed.
17+
6. If the tests pass, you can commit your changes to your fork and then create
18+
a pull request from there. Make sure to reference your issue from the pull
19+
request comments by including the issue number e.g. `#123`.
20+
21+
## How to add codemods
22+
23+
We use `jscodeshift` to create and run the codemods. To add a new codemod for Express, we follow the following process.
24+
25+
1. Create a new file in the `transforms` directory. For example, `transforms/pluralized-methods.ts`.
26+
27+
2. Write your codemod. Here's an example that pluralizes Express methods:
28+
29+
```typescript
30+
// filepath: codemod/transforms/pluralized-methods.ts
31+
import type { API, FileInfo } from 'jscodeshift'
32+
import { Identifier, identifier } from 'jscodeshift'
33+
import { getParsedFile } from '../utils/parse'
34+
35+
export default function transformer(file: FileInfo, _api: API): string {
36+
const parsedFile = getParsedFile(file)
37+
38+
const identifierNamesToReplace = ['acceptsLanguage', 'acceptsCharset', 'acceptsEncoding']
39+
40+
for (const singular of identifierNamesToReplace) {
41+
const plural = `${singular}s`
42+
43+
parsedFile
44+
.find(Identifier, {
45+
name: singular,
46+
})
47+
.replaceWith(() => identifier(plural))
48+
}
49+
50+
return parsedFile.toSource()
51+
}
52+
```
53+
54+
3. Add tests to verify the functionality of the codemod
55+
- A new file is created in the `/transforms/__test__` directory with the same name as the codemod with the following content
56+
```ts
57+
// filepath: codemod/transforms/__test__/pluralized-methods.ts
58+
59+
import { testSpecBuilder } from './util'
60+
61+
testSpecBuilder('magic-redirect')
62+
```
63+
- Two new files are created, `name-codemod.input.ts` and `name_codemod.output.ts`, inside the `/transforms/__testfixtures__` directory
64+
- The files ending in `.input.ts ` contain the content that should be changed by the codemod
65+
- The `.output.ts` files contain the content that should be present after the codemod has been correctly applied.
66+
67+
4. To make the codemod visible within the CLI, the `config.ts` file is modified, where a brief description of the codemod, its name, and the version of Express to which the migration should be applied are added.
68+
69+
## Developer's Certificate of Origin 1.1
70+
71+
```text
72+
By making a contribution to this project, I certify that:
73+
74+
(a) The contribution was created in whole or in part by me and I
75+
have the right to submit it under the open source license
76+
indicated in the file; or
77+
78+
(b) The contribution is based upon previous work that, to the best
79+
of my knowledge, is covered under an appropriate open source
80+
license and I have the right under that license to submit that
81+
work with modifications, whether created in whole or in part
82+
by me, under the same open source license (unless I am
83+
permitted to submit under a different license), as indicated
84+
in the file; or
85+
86+
(c) The contribution was provided directly to me by some other
87+
person who certified (a), (b) or (c) and I have not modified
88+
it.
89+
90+
(d) I understand and agree that this project and the contribution
91+
are public and that a record of the contribution (including all
92+
personal information I submit with it, including my sign-off) is
93+
maintained indefinitely and may be redistributed consistent with
94+
this project or the open source license(s) involved.
95+
```

0 commit comments

Comments
 (0)