electron/docs/styleguide.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

260 lines
6.7 KiB
Markdown
Raw Normal View History

# Electron Documentation Style Guide
2015-08-22 12:07:45 +00:00
2016-06-24 19:28:41 +00:00
These are the guidelines for writing Electron documentation.
2015-08-22 12:07:45 +00:00
## Headings
2015-08-22 12:07:45 +00:00
2016-06-24 19:40:55 +00:00
* Each page must have a single `#`-level title at the top.
* Chapters in the same page must have `##`-level headings.
* Sub-chapters need to increase the number of `#` in the heading according to
their nesting depth.
* The page's title must follow [APA title case][title-case].
* All chapters must follow [APA sentence case][sentence-case].
2016-06-24 01:45:37 +00:00
Using `Quick Start` as example:
```markdown
# Quick Start
...
## Main process
...
## Renderer process
...
## Run your app
2015-08-22 12:07:45 +00:00
2016-06-24 01:45:37 +00:00
...
### Run as a distribution
...
### Manually downloaded Electron binary
...
```
For API references, there are exceptions to this rule.
## Markdown rules
This repository uses the [`markdownlint`][markdownlint] package to enforce consistent
Markdown styling. For the exact rules, see the `.markdownlint.json` file in the root
folder.
There are a few style guidelines that aren't covered by the linter rules:
<!--TODO(erickzhao): make sure this matches with the lint:markdownlint task-->
2017-11-24 10:13:57 +00:00
* Use `sh` instead of `cmd` in code blocks (due to the syntax highlighter).
* Keep line lengths between 80 and 100 characters if possible for readability
purposes.
2016-06-24 19:28:41 +00:00
* No nesting lists more than 2 levels (due to the markdown renderer).
2016-08-16 21:07:50 +00:00
* All `js` and `javascript` code blocks are linted with
2020-11-02 09:58:14 +00:00
[standard-markdown](https://www.npmjs.com/package/standard-markdown).
* For unordered lists, use asterisks instead of dashes.
2016-06-24 01:45:37 +00:00
## Picking words
2016-06-24 01:45:37 +00:00
* Use "will" over "would" when describing outcomes.
* Prefer "in the ___ process" over "on".
2016-06-24 01:45:37 +00:00
## API references
2016-06-24 19:28:41 +00:00
The following rules only apply to the documentation of APIs.
2015-08-22 12:07:45 +00:00
### Title and description
2015-08-22 12:07:45 +00:00
Each module's API doc must use the actual object name returned by `require('electron')`
as its title (such as `BrowserWindow`, `autoUpdater`, and `session`).
2016-06-24 01:45:37 +00:00
Directly under the page title, add a one-line description of the module
as a markdown quote (beginning with `>`).
2015-08-22 12:07:45 +00:00
Using the `session` module as an example:
2016-06-24 01:45:37 +00:00
```markdown
# session
> Manage browser sessions, cookies, cache, proxy settings, etc.
```
2015-08-22 12:07:45 +00:00
2016-06-24 01:45:37 +00:00
### Module methods and events
For modules that are not classes, their methods and events must be listed under
2016-06-24 19:40:55 +00:00
the `## Methods` and `## Events` chapters.
2016-06-24 01:45:37 +00:00
2016-06-24 19:28:41 +00:00
Using `autoUpdater` as an example:
2016-06-24 01:45:37 +00:00
```markdown
# autoUpdater
## Events
### Event: 'error'
## Methods
### `autoUpdater.setFeedURL(url[, requestHeaders])`
```
2015-08-22 12:07:45 +00:00
2016-06-24 01:45:37 +00:00
### Classes
* API classes or classes that are part of modules must be listed under a
2016-06-24 19:40:55 +00:00
`## Class: TheClassName` chapter.
* One page can have multiple classes.
* Constructors must be listed with `###`-level headings.
* [Static Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static)
must be listed under a `### Static Methods` chapter.
* [Instance Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Prototype_methods)
must be listed under an `### Instance Methods` chapter.
* All methods that have a return value must start their description with
"Returns `[TYPE]` - \[Return description]"
* If the method returns an `Object`, its structure can be specified using a colon
followed by a newline then an unordered list of properties in the same style as
function parameters.
2016-07-13 05:00:28 +00:00
* Instance Events must be listed under an `### Instance Events` chapter.
* Instance Properties must be listed under an `### Instance Properties` chapter.
* Instance Properties must start with "A \[Property Type] ..."
2016-06-24 01:45:37 +00:00
2016-06-24 19:40:55 +00:00
Using the `Session` and `Cookies` classes as an example:
2016-06-24 01:45:37 +00:00
```markdown
# session
## Methods
### session.fromPartition(partition)
## Static Properties
2016-06-24 01:45:37 +00:00
### session.defaultSession
## Class: Session
### Instance Events
#### Event: 'will-download'
### Instance Methods
#### `ses.getCacheSize()`
2016-06-24 01:45:37 +00:00
### Instance Properties
#### `ses.cookies`
## Class: Cookies
### Instance Methods
#### `cookies.get(filter, callback)`
```
### Methods and their arguments
2016-06-24 01:45:37 +00:00
2016-06-24 19:28:41 +00:00
The methods chapter must be in the following form:
2016-06-24 01:45:37 +00:00
```markdown
### `objectName.methodName(required[, optional]))`
* `required` string - A parameter description.
2016-12-29 22:11:26 +00:00
* `optional` Integer (optional) - Another parameter description.
2016-06-24 01:45:37 +00:00
...
```
#### Heading level
The heading can be `###` or `####`-levels depending on whether the method
belongs to a module or a class.
#### Function signature
2016-06-24 01:45:37 +00:00
2016-06-24 22:59:30 +00:00
For modules, the `objectName` is the module's name. For classes, it must be the
2016-06-24 19:28:41 +00:00
name of the instance of the class, and must not be the same as the module's
name.
2016-06-24 01:45:37 +00:00
2016-06-24 19:28:41 +00:00
For example, the methods of the `Session` class under the `session` module must
use `ses` as the `objectName`.
2016-06-24 01:45:37 +00:00
Optional arguments are notated by square brackets `[]` surrounding the optional
argument as well as the comma required if this optional argument follows another
2016-06-24 22:59:30 +00:00
argument:
```markdown
2016-06-24 22:59:30 +00:00
required[, optional]
```
2015-08-22 12:07:45 +00:00
#### Argument descriptions
2016-06-24 19:28:41 +00:00
More detailed information on each of the arguments is noted in an unordered list
below the method. The type of argument is notated by either JavaScript primitives
(e.g. `string`, `Promise`, or `Object`), a custom API structure like Electron's
[`Cookie`](api/structures/cookie.md), or the wildcard `any`.
If the argument is of type `Array`, use `[]` shorthand with the type of value
inside the array (for example,`any[]` or `string[]`).
If the argument is of type `Promise`, parametrize the type with what the promise
resolves to (for example, `Promise<void>` or `Promise<string>`).
If an argument can be of multiple types, separate the types with `|`.
The description for `Function` type arguments should make it clear how it may be
called and list the types of the parameters that will be passed to it.
#### Platform-specific functionality
2015-08-22 12:07:45 +00:00
2016-06-24 01:45:37 +00:00
If an argument or a method is unique to certain platforms, those platforms are
denoted using a space-delimited italicized list following the datatype. Values
can be `macOS`, `Windows` or `Linux`.
2016-06-17 19:33:50 +00:00
2016-06-24 19:28:41 +00:00
```markdown
* `animate` boolean (optional) _macOS_ _Windows_ - Animate the thing.
2016-06-17 19:33:50 +00:00
```
2015-08-22 12:07:45 +00:00
### Events
2016-06-24 19:28:41 +00:00
The events chapter must be in following form:
2015-08-22 12:07:45 +00:00
2016-06-24 01:45:37 +00:00
```markdown
### Event: 'wake-up'
2015-08-22 12:07:45 +00:00
Returns:
* `time` string
2016-06-24 01:45:37 +00:00
...
```
2015-08-22 12:07:45 +00:00
The heading can be `###` or `####`-levels depending on whether the event
belongs to a module or a class.
2016-06-24 01:45:37 +00:00
2016-06-24 19:40:55 +00:00
The arguments of an event follow the same rules as methods.
2016-06-24 01:45:37 +00:00
### Properties
2016-06-24 19:28:41 +00:00
The properties chapter must be in following form:
2016-06-24 01:45:37 +00:00
```markdown
### session.defaultSession
...
2015-08-22 12:07:45 +00:00
```
2016-06-24 01:45:37 +00:00
The heading can be `###` or `####`-levels depending on whether the property
belongs to a module or a class.
2016-06-24 01:45:37 +00:00
## Documentation translations
2016-06-24 01:45:37 +00:00
2018-03-02 20:05:49 +00:00
See [electron/i18n](https://github.com/electron/i18n#readme)
[title-case]: https://apastyle.apa.org/style-grammar-guidelines/capitalization/title-case
[sentence-case]: https://apastyle.apa.org/style-grammar-guidelines/capitalization/sentence-case
[markdownlint]: https://github.com/DavidAnson/markdownlint