]>
Commit | Line | Data |
---|---|---|
eb39fafa DC |
1 | # Pull Requests |
2 | ||
3 | If you want to contribute to an ESLint repo, please use a GitHub pull request. This is the fastest way for us to evaluate your code and to merge it into the code base. Please don't file an issue with snippets of code. Doing so means that we need to manually merge the changes in and update any appropriate tests. That decreases the likelihood that your code is going to get included in a timely manner. Please use pull requests. | |
4 | ||
5 | ## Getting Started | |
6 | ||
7 | If you'd like to work on a pull request and you've never submitted code before, follow these steps: | |
8 | ||
9 | 1. Sign our [Contributor License Agreement](https://cla.js.foundation/eslint/eslint). | |
10 | 1. Set up a [development environment](../development-environment.md). | |
11 | 1. If you want to implement a breaking change or a change to the core, ensure there's an issue that describes what you're doing and the issue has been accepted. You can create a new issue or just indicate you're [working on an existing issue](working-on-issues.md). Bug fixes, documentation changes, and other pull requests do not require an issue. | |
12 | ||
13 | After that, you're ready to start working on code. | |
14 | ||
15 | ## Working with Code | |
16 | ||
17 | The process of submitting a pull request is fairly straightforward and generally follows the same pattern each time: | |
18 | ||
19 | 1. [Create a new branch](#step1) | |
20 | 2. [Make your changes](#step2) | |
21 | 3. [Rebase onto upstream](#step3) | |
22 | 4. [Run the tests](#step4) | |
23 | 5. [Double check your submission](#step5) | |
24 | 6. [Push your changes](#step6) | |
25 | 7. [Submit the pull request](#step7) | |
26 | ||
27 | Details about each step are found below. | |
28 | ||
29 | ### Step 1: Create a new branch<a name="step1"></a> | |
30 | ||
31 | The first step to sending a pull request is to create a new branch in your ESLint fork. Give the branch a descriptive name that describes what it is you're fixing, such as: | |
32 | ||
34eeec05 | 33 | ```sh |
eb39fafa DC |
34 | $ git checkout -b issue1234 |
35 | ``` | |
36 | ||
37 | You should do all of your development for the issue in this branch. | |
38 | ||
39 | **Note:** Do not combine fixes for multiple issues into one branch. Use a separate branch for each issue you're working on. | |
40 | ||
41 | ### Step 2: Make your changes<a name="step2"></a> | |
42 | ||
43 | Make the changes to the code and tests, following the [code conventions](../code-conventions.md) as you go. Once you have finished, commit the changes to your branch: | |
44 | ||
34eeec05 | 45 | ```sh |
eb39fafa DC |
46 | $ git add -A |
47 | $ git commit | |
48 | ``` | |
49 | ||
609c276f | 50 | All ESLint projects follow [Conventional Commits](https://www.conventionalcommits.org/) for our commit messages. Here's an example commit message: |
eb39fafa | 51 | |
34eeec05 | 52 | ```pt |
609c276f | 53 | tag: Short description of what you did |
eb39fafa DC |
54 | |
55 | Longer description here if necessary | |
609c276f TL |
56 | |
57 | Fixes #1234 | |
eb39fafa DC |
58 | ``` |
59 | ||
60 | The first line of the commit message (the summary) must have a specific format. This format is checked by our build tools. | |
61 | ||
609c276f | 62 | The `tag` is one of the following: |
eb39fafa | 63 | |
609c276f TL |
64 | * `fix` - for a bug fix. |
65 | * `feat` - either for a backwards-compatible enhancement or for a rule change that adds reported problems. | |
66 | * `fix!` - for a backwards-incompatible bug fix. | |
67 | * `feat!` - for a backwards-incompatible enhancement or feature. | |
68 | * `docs` - changes to documentation only. | |
69 | * `chore` - for changes that aren't user-facing. | |
70 | * `build` - changes to build process only. | |
71 | * `refactor` - a change that doesn't affect APIs or user experience. | |
72 | * `test` - just changes to test files. | |
73 | * `ci` - changes to our CI configuration files and scripts. | |
74 | * `perf` - a code change that improves performance. | |
eb39fafa DC |
75 | |
76 | Use the [labels of the issue you are working on](working-on-issues.md#issue-labels) to determine the best tag. | |
77 | ||
609c276f | 78 | The message summary should be a one-sentence description of the change, and it must be 72 characters in length or shorter. If the pull request addresses an issue, then the issue number should be mentioned in the body of the commit message in the format `Fixes #1234`. If the commit doesn't completely fix the issue, then use `Refs #1234` instead of `Fixes #1234`. |
eb39fafa DC |
79 | |
80 | Here are some good commit message summary examples: | |
81 | ||
34eeec05 | 82 | ```pt |
609c276f TL |
83 | build: Update Travis to only test Node 0.10 |
84 | fix: Semi rule incorrectly flagging extra semicolon | |
85 | chore: Upgrade Esprima to 1.2, switch to using comment attachment | |
eb39fafa DC |
86 | ``` |
87 | ||
88 | The commit message format is important because these messages are used to create a changelog for each release. The tag and issue number help to create more consistent and useful changelogs. | |
89 | ||
90 | ### Step 3: Rebase onto upstream<a name="step3"></a> | |
91 | ||
92 | Before you send the pull request, be sure to rebase onto the upstream source. This ensures your code is running on the latest available code. | |
93 | ||
34eeec05 | 94 | ```sh |
eb39fafa | 95 | git fetch upstream |
609c276f | 96 | git rebase upstream/main |
eb39fafa DC |
97 | ``` |
98 | ||
99 | ### Step 4: Run the tests<a name="step4"></a> | |
100 | ||
101 | After rebasing, be sure to run all of the tests once again to make sure nothing broke: | |
102 | ||
34eeec05 | 103 | ```sh |
eb39fafa DC |
104 | npm test |
105 | ``` | |
106 | ||
107 | If there are any failing tests, update your code until all tests pass. | |
108 | ||
109 | ### Step 5: Double check your submission<a name="step5"></a> | |
110 | ||
111 | With your code ready to go, this is a good time to double-check your submission to make sure it follows our conventions. Here are the things to check: | |
112 | ||
113 | * Make sure your commit is formatted correctly. | |
114 | * The pull request must have a description. The description should explain what you did and how its effects can be seen. | |
115 | * The commit message is properly formatted. | |
116 | * The change introduces no functional regression. Be sure to run `npm test` to verify your changes before submitting a pull request. | |
117 | * Make separate pull requests for unrelated changes. Large pull requests with multiple unrelated changes may be closed without merging. | |
118 | * All changes must be accompanied by tests, even if the feature you're working on previously had no tests. | |
119 | * All user-facing changes must be accompanied by appropriate documentation. | |
120 | * Follow the [Code Conventions](../code-conventions.md). | |
121 | ||
122 | ### Step 6: Push your changes<a name="step6"></a> | |
123 | ||
124 | Next, push your changes to your clone: | |
125 | ||
34eeec05 | 126 | ```sh |
eb39fafa DC |
127 | git push origin issue1234 |
128 | ``` | |
129 | ||
130 | If you are unable to push because some references are old, do a forced push instead: | |
131 | ||
34eeec05 | 132 | ```sh |
eb39fafa DC |
133 | git push -f origin issue1234 |
134 | ``` | |
135 | ||
136 | ### Step 7: Send the pull request<a name="step7"></a> | |
137 | ||
138 | Now you're ready to send the pull request. Go to your ESLint fork and then follow the [GitHub documentation](https://help.github.com/articles/creating-a-pull-request) on how to send a pull request. | |
139 | ||
140 | ## Following Up | |
141 | ||
142 | Once your pull request is sent, it's time for the team to review it. As such, please make sure to: | |
143 | ||
144 | 1. Monitor the status of the Travis CI build for your pull request. If it fails, please investigate why. We cannot merge pull requests that fail Travis for any reason. | |
145 | 1. Respond to comments left on the pull request from team members. Remember, we want to help you land your code, so please be receptive to our feedback. | |
146 | 1. We may ask you to make changes, rebase, or squash your commits. | |
147 | ||
148 | ### Updating the Commit Message | |
149 | ||
150 | If your commit message is in the incorrect format, you'll be asked to update it. You can do so via: | |
151 | ||
34eeec05 | 152 | ```sh |
eb39fafa DC |
153 | $ git commit --amend |
154 | ``` | |
155 | ||
156 | This will open up your editor so you can make changes. After that, you'll need to do a forced push to your branch: | |
157 | ||
34eeec05 | 158 | ```sh |
eb39fafa DC |
159 | $ git push origin issue1234 -f |
160 | ``` | |
161 | ||
162 | ### Updating the Code | |
163 | ||
164 | If we ask you to make code changes, there's no need to close the pull request and create a new one. Just go back to the branch on your fork and make your changes. Then, when you're ready, you can add your changes into the branch: | |
165 | ||
34eeec05 | 166 | ```sh |
eb39fafa DC |
167 | $ git add -A |
168 | $ git commit | |
169 | $ git push origin issue1234 | |
170 | ``` | |
171 | ||
609c276f TL |
172 | When updating the code, it's usually better to add additional commits to your branch rather than amending the original commit, because reviewers can easily tell which changes were made in response to a particular review. When we merge pull requests, we will squash all the commits from your branch into a single commit on the `main` branch. |
173 | ||
174 | The commit messages in subsequent commits do not need to be in any specific format because these commits do not show up in the changelog. | |
eb39fafa DC |
175 | |
176 | ### Rebasing | |
177 | ||
178 | If your code is out-of-date, we might ask you to rebase. That means we want you to apply your changes on top of the latest upstream code. Make sure you have set up a [development environment](../development-environment.md) and then you can rebase using these commands: | |
179 | ||
34eeec05 | 180 | ```sh |
eb39fafa | 181 | $ git fetch upstream |
609c276f | 182 | $ git rebase upstream/main |
eb39fafa DC |
183 | ``` |
184 | ||
185 | You might find that there are merge conflicts when you attempt to rebase. Please [resolve the conflicts](https://help.github.com/articles/resolving-merge-conflicts-after-a-git-rebase/) and then do a forced push to your branch: | |
186 | ||
34eeec05 | 187 | ```sh |
eb39fafa DC |
188 | $ git push origin issue1234 -f |
189 | ``` |