Debian Codegraph @

CONTRIBUTING.md

raw
1 # Contributing
2
3 Welcome stranger!
4
5 If you have come here to learn how to contribute to mdBook, we have some tips for you!
6
7 First of all, don't hesitate to ask questions!
8 Use the [issue tracker](https://github.com/rust-lang/mdBook/issues), no question is too simple.
9
10 ## Issue assignment
11
12 **:warning: Important :warning:**
13
14 Before working on pull request, please ping us on the corresponding issue.
15 The current PR backlog is beyond what we can process at this time.
16 Only issues that have an [`E-Help-wanted`](https://github.com/rust-lang/mdBook/labels/E-Help-wanted) or [`Feature accepted`](https://github.com/rust-lang/mdBook/labels/Feature%20accepted) label will likely receive reviews.
17 If there isn't already an open issue for what you want to work on, please open one first to see if it is something we would be available to review.
18
19 ## Issues to work on
20
21 If you are starting out, you might be interested in the
22 [E-Easy issues](https://github.com/rust-lang/mdBook/issues?q=is%3Aopen+is%3Aissue+label%3AE-Easy).
23 Those are issues that are considered more straightforward for beginners to Rust or the codebase itself.
24 These issues can be a good launching pad for more involved issues.
25 Easy tasks for a first time contribution include documentation improvements, new tests, examples, updating dependencies, etc.
26
27 If you come from a web development background, you might be interested in issues related to web technologies tagged
28 [A-JavaScript](https://github.com/rust-lang/mdBook/issues?q=is%3Aopen+is%3Aissue+label%3AA-JavaScript),
29 [A-Style](https://github.com/rust-lang/mdBook/issues?q=is%3Aopen+is%3Aissue+label%3AA-Style),
30 [A-HTML](https://github.com/rust-lang/mdBook/issues?q=is%3Aopen+is%3Aissue+label%3AA-HTML) or
31 [A-Mobile](https://github.com/rust-lang/mdBook/issues?q=is%3Aopen+is%3Aissue+label%3AA-Mobile).
32
33 When you decide you want to work on a specific issue, and it isn't already assigned to someone else, assign the issue to yourself by leaving a comment with the text `@rustbot claim`.
34 Again, do not hesitate to ask questions. We will gladly mentor anyone that want to tackle an issue.
35
36 Issues on the issue tracker are categorized with the following labels:
37
38 - **A**-prefixed labels state which area of the project an issue relates to.
39 - **E**-prefixed labels show an estimate of the experience necessary to fix the issue.
40 - **M**-prefixed labels are meta-issues regarding the management of the mdBook project itself
41 - **S**-prefixed labels show the status of the issue
42 - **C**-prefixed labels show the category of issue
43
44 ## Building mdBook
45
46 mdBook builds on stable Rust, if you want to build mdBook from source, here are the steps to follow:
47
48 1. Navigate to the directory of your choice
49 0. Clone this repository with git.
50
51 ```
52 git clone https://github.com/rust-lang/mdBook.git
53 ```
54 0. Navigate into the newly created `mdBook` directory
55 0. Run `cargo build`
56
57 The resulting binary can be found in `mdBook/target/debug/` under the name `mdbook` or `mdbook.exe`.
58
59 ## Code quality
60
61 We love code quality and Rust has some excellent tools to assist you with contributions.
62
63 ### Formatting code with rustfmt
64
65 Before you make your Pull Request to the project, please run it through the `rustfmt` utility.
66 This will ensure we have good quality source code that is better for us all to maintain.
67
68 [rustfmt](https://github.com/rust-lang/rustfmt) has a lot more information on the project.
69 The quick guide is
70
71 1. Install it (`rustfmt` is usually installed by default via [rustup](https://rustup.rs/)):
72 ```
73 rustup component add rustfmt
74 ```
75 1. You can now run `rustfmt` on a single file simply by...
76 ```
77 rustfmt src/path/to/your/file.rs
78 ```
79 ... or you can format the entire project with
80 ```
81 cargo fmt
82 ```
83 When run through `cargo` it will format all bin and lib files in the current package.
84
85 For more information, such as running it from your favourite editor, please see the `rustfmt` project. [rustfmt](https://github.com/rust-lang/rustfmt)
86
87 ### Finding issues with clippy
88
89 [Clippy](https://doc.rust-lang.org/clippy/) is a code analyser/linter detecting mistakes, and therefore helps to improve your code.
90 Like formatting your code with `rustfmt`, running clippy regularly and before your Pull Request will help us maintain awesome code.
91
92 1. To install
93 ```
94 rustup component add clippy
95 ```
96 2. Running clippy
97 ```
98 cargo clippy
99 ```
100
101 ## Change requirements
102
103 Please consider the following when making a change:
104
105 * Almost all changes that modify the Rust code must be accompanied with a test.
106
107 * Almost all features and changes must update the documentation.
108 mdBook has the [mdBook Guide](https://rust-lang.github.io/mdBook/) whose source is at <https://github.com/rust-lang/mdBook/tree/master/guide>.
109
110 * Almost all Rust items should be documented with doc comments.
111 See the [Rustdoc Book](https://doc.rust-lang.org/rustdoc/) for more information on writing doc comments.
112
113 * Breaking the API can only be done in major SemVer releases.
114 These are done very infrequently, so it is preferred to avoid these when possible.
115 See [SemVer Compatibility](https://doc.rust-lang.org/cargo/reference/semver.html) for more information on what a SemVer breaking change is.
116
117 (Note: At this time, some SemVer breaking changes are inevitable due to the current code structure.
118 An example is adding new fields to the config structures.
119 These are intended to be fixed in the next major release.)
120
121 * Similarly, the CLI interface is considered to be stable.
122 Care should be taken to avoid breaking existing workflows.
123
124 * Check out the [Rust API Guidelines](https://rust-lang.github.io/api-guidelines/) for guidelines on designing the API.
125
126 ## Tests
127
128 The main test harness is described in the [testsuite documentation](tests/testsuite/README.md). There are several different commands to run different kinds of tests:
129
130 - `cargo test --workspace` — This runs all of the unit and integration tests, except for the GUI tests.
131 - `cargo test --test gui` — This runs the [GUI test harness](#browser-compatibility-and-testing). This does not get run automatically due to its extra requirements.
132 - `npm run lint` — [Checks the `.js` files](#checking-changes-in-js-files)
133 - `cargo test --workspace --no-default-features` — Testing without default features helps check that all feature checks are implemented correctly.
134 - `cargo clippy --workspace --all-targets --no-deps -- -D warnings` — This makes sure that there are no clippy warnings.
135 - `RUSTDOCFLAGS="-D warnings" cargo doc --workspace --document-private-items --no-deps` — This verifies that there aren't any rustdoc warnings.
136 - `cargo fmt --check` — Verifies that everything is formatted correctly.
137 - `cargo +stable semver-checks` — Verifies that no SemVer breaking changes have been made. You must install [`cargo-semver-checks`](https://crates.io/crates/cargo-semver-checks) first.
138
139 To help simplify running all these commands, you can run the following cargo command:
140
141 ```sh
142 cargo xtask test-all
143 ```
144
145 It is useful to run all tests before submitting a PR. While developing I recommend to run some subset of that command based on what you are working on. There are individual arguments for each one. For example:
146
147 ```sh
148 cargo xtask test-workspace clippy doc eslint fmt gui semver-checks
149 ```
150
151 While developing, remove any of those arguments that are not relevant to what you are changing, or are really slow.
152
153 ## Making a pull-request
154
155 When you feel comfortable that your changes could be integrated into mdBook, you can create a pull-request on GitHub.
156 One of the core maintainers will then approve the changes or request some changes before it gets merged.
157
158 That's it, happy contributions! :tada: :tada: :tada:
159
160 ## Browser compatibility and testing
161
162 Currently we don't have a strict browser compatibility matrix due to our limited resources.
163 We generally strive to keep mdBook compatible with a relatively recent browser on all of the most major platforms.
164 That is, supporting Chrome, Safari, Firefox, Edge on Windows, macOS, Linux, iOS, and Android.
165 If possible, do your best to avoid breaking older browser releases.
166
167 GUI tests are checked with the GUI testsuite. To run it, you need to install `npm` first. Then run:
168
169 ```
170 cargo test --test gui
171 ```
172
173 If you want to only run some tests, you can filter them by passing (part of) their name:
174
175 ```
176 cargo test --test gui -- search
177 ```
178
179 The first time, it'll fail and ask you to install the `browser-ui-test` package. Install it with the provided
180 command then re-run the tests.
181
182 If you want to disable the headless mode, use the `--disable-headless-test` option:
183
184 ```
185 cargo test --test gui -- --disable-headless-test
186 ```
187
188 The GUI tests are in the directory `tests/gui` in text files with the `.goml` extension. The books that the tests use are located in the `tests/gui/books` directory. These tests are run using a `node.js` framework called `browser-ui-test`. You can find documentation for this language on its [repository](https://github.com/GuillaumeGomez/browser-UI-test/blob/master/goml-script.md).
189
190 ### Checking changes in `.js` files
191
192 The `.js` files source code is checked using [`eslint`](https://eslint.org/). This is a linter (just like `clippy` in Rust)
193 for the Javascript language. You can install it with `npm` by running the following command:
194
195 ```
196 npm install
197 ```
198
199 Then you can run it using:
200
201 ```
202 npm run lint
203 ```
204
205 ## Updating highlight.js
206
207 The following are instructions for updating [highlight.js](https://highlightjs.org/).
208
209 1. Clone the repository at <https://github.com/highlightjs/highlight.js>
210 1. Check out a tagged release (like `10.1.1`).
211 1. Run `npm install`
212 1. Run `node tools/build.js :common apache armasm coffeescript d handlebars haskell http julia nginx nim nix properties r scala x86asm yaml`
213 1. Compare the language list that it spits out to the one in [`syntax-highlighting.md`](https://github.com/camelid/mdBook/blob/master/guide/src/format/theme/syntax-highlighting.md). If any are missing, add them to the list and rebuild (and update these docs). If any are added to the common set, add them to `syntax-highlighting.md`.
214 1. Copy `build/highlight.min.js` to mdbook's directory [`highlight.js`](https://github.com/rust-lang/mdBook/blob/master/src/theme/highlight.js).
215 1. Be sure to check the highlight.js [CHANGES](https://github.com/highlightjs/highlight.js/blob/main/CHANGES.md) for any breaking changes. Breaking changes that would affect users will need to wait until the next major release.
216 1. Build mdbook with the new file and build some books with the new version and compare the output with a variety of languages to see if anything changes. The [syntax GUI test](https://github.com/rust-lang/mdBook/tree/master/tests/gui/books/highlighting) contains a chapter with many languages to examine. Update the test (`highlighting.goml`) to add any new languages.
217
218 ## Publishing new releases
219
220 Instructions for mdBook maintainers to publish a new release:
221
222 1. Create a PR that bumps the version and updates the changelog:
223 1. `git fetch upstream`
224 2. `git checkout -B bump-version upstream/master && git branch --set-upstream-to=origin/bump-version`
225 3. `cargo xtask bump <BUMP>`
226 - This will update the version of all the crates.
227 - `cargo set-version` must first be installed with `cargo install cargo-edit`.
228 - Replace `<BUMP>` with the kind of bump (patch, alpha, etc.)
229 4. `cargo xtask changelog`
230 - This will update `CHANGELOG.md` to add a list of all changes at the top. You will need to move those into the appropriate categories. Most changes that are generally not relevant to a user should be removed. Rewrite the descriptions so that a user can reasonably figure out what it means.
231 5. `git add --update .`
232 6. `git commit`
233 7. `git push`
234 2. After the PR has been merged, create a release in GitHub. This can either be done in the GitHub web UI, or on the command-line:
235 ```bash
236 MDBOOK_VERS="`cargo read-manifest | jq -r .version`" ; \
237 gh release create -R rust-lang/mdbook v$MDBOOK_VERS \
238 --title v$MDBOOK_VERS \
239 --notes "See https://github.com/rust-lang/mdBook/blob/master/CHANGELOG.md#mdbook-${MDBOOK_VERS//.} for a complete list of changes."
240 ```