2020-03-19 07:15:20 +08:00
|
|
|
# Contributor's Manual
|
2016-02-19 07:13:35 +08:00
|
|
|
|
2020-03-19 05:56:12 +08:00
|
|
|
## Human communication
|
2016-02-19 07:13:35 +08:00
|
|
|
|
2020-03-19 07:57:46 +08:00
|
|
|
The project lead is @xiaq, who is reachable in the user group most of the time.
|
2016-02-19 07:13:35 +08:00
|
|
|
|
2020-05-31 08:42:26 +08:00
|
|
|
If you intend to make user-visible changes to Elvish's behavior, it is good idea
|
|
|
|
to talk to him first; this will make it easier to review your changes.
|
2016-02-19 07:13:35 +08:00
|
|
|
|
2020-05-31 08:42:26 +08:00
|
|
|
On the other hand, if you find it easier to express your thoughts directly in
|
|
|
|
code, it is also completely fine to directly send a pull request, as long as you
|
|
|
|
don't mind the risk of the PR being rejected due to lack of prior discussion.
|
|
|
|
|
|
|
|
## Testing changes
|
2018-01-01 23:06:07 +08:00
|
|
|
|
2020-05-31 08:42:26 +08:00
|
|
|
Write comprehensive unit tests for your code, and make sure that existing tests
|
2020-06-25 06:00:59 +08:00
|
|
|
are passing. Tests are run on CI automatically for PRs; you can also run
|
|
|
|
`make test` in the repo root yourself.
|
2018-01-01 23:06:07 +08:00
|
|
|
|
2020-05-31 08:42:26 +08:00
|
|
|
Respect established patterns of how unit tests are written. Some packages
|
|
|
|
unfortunately have competing patterns, which usually reflects a still-evolving
|
|
|
|
idea of how to best test the code. Worse, parts of the codebase are poorly
|
|
|
|
tested, or even untestable. In either case, discuss with the project lead on the
|
|
|
|
best way forward.
|
2018-01-01 23:06:07 +08:00
|
|
|
|
2020-05-04 04:35:51 +08:00
|
|
|
### ELVISH_TEST_TIME_SCALE
|
|
|
|
|
|
|
|
Some unit tests depend on time thresholds. The default values of these time
|
|
|
|
thresholds are suitable for a reasonably powerful laptop, but on
|
|
|
|
resource-constraint environments (virtual machines, embedded systems) they might
|
|
|
|
not be enough.
|
|
|
|
|
|
|
|
Set the `ELVISH_TEST_TIME_SCALE` environment variable to a number greater than 1
|
|
|
|
to scale up the time thresholds used in tests. The CI environments use
|
|
|
|
`ELVISH_TEST_TIME_SCALE = 10`.
|
|
|
|
|
2020-05-31 08:42:26 +08:00
|
|
|
## Documenting changes
|
|
|
|
|
|
|
|
Always document user-visible changes.
|
|
|
|
|
|
|
|
### Release notes
|
2020-03-19 07:15:20 +08:00
|
|
|
|
2020-05-31 08:42:26 +08:00
|
|
|
Add a brief list item to the release note of the next release, in the
|
|
|
|
appropriate section.
|
2020-03-19 07:15:20 +08:00
|
|
|
|
2020-06-25 06:00:59 +08:00
|
|
|
The release notes live in `website/blog`; the symlink `NEXT-RELEASE.md` at the
|
|
|
|
repo root always points to those of the next release.
|
2020-05-31 08:42:26 +08:00
|
|
|
|
|
|
|
### Reference docs
|
|
|
|
|
|
|
|
Reference docs are interspersed in Go sources as comments blocks whose first
|
|
|
|
line starts with `//elvdoc` (and are hence called _elvdocs_). They can use
|
|
|
|
[Github Flavored Markdown](https://github.github.com/gfm/).
|
|
|
|
|
|
|
|
Elvdocs for functions look like the following:
|
2020-03-19 07:15:20 +08:00
|
|
|
|
|
|
|
````go
|
|
|
|
//elvdoc:fn name-of-fn
|
|
|
|
//
|
|
|
|
// ```elvish
|
|
|
|
// name-of-fn $arg &opt=default
|
|
|
|
// ```
|
|
|
|
//
|
|
|
|
// Does something.
|
|
|
|
//
|
|
|
|
// Example:
|
|
|
|
//
|
|
|
|
// ```elvish-transcript
|
|
|
|
// ~> name-of-fn something
|
|
|
|
// ▶ some-value-output
|
|
|
|
// ```
|
2020-05-31 08:42:26 +08:00
|
|
|
|
|
|
|
func nameOfFn() { ... }
|
2020-03-19 07:15:20 +08:00
|
|
|
````
|
|
|
|
|
2020-05-31 08:42:26 +08:00
|
|
|
Generally, elvdocs for functions have the following structure:
|
2020-03-19 07:15:20 +08:00
|
|
|
|
2020-05-31 08:42:26 +08:00
|
|
|
- A line starting with `//elvdoc:fn`, followed by the name of the function.
|
|
|
|
Note that there should be no space after `//`, unlike all the other lines.
|
2020-03-19 07:15:20 +08:00
|
|
|
|
2020-05-31 08:42:26 +08:00
|
|
|
- An `elvish` code block describing the signature of the function, following
|
|
|
|
the convention [here](website/ref/builtin.md#usage-notation).
|
2020-03-19 07:15:20 +08:00
|
|
|
|
2020-05-31 08:42:26 +08:00
|
|
|
- Description of the function, which can be one or more paragraphs. The first
|
|
|
|
sentence of the description should start with a verb in 3rd person singular
|
|
|
|
(i.e. ending with a "s"), as if there is an implicit subject "this
|
2020-03-19 07:15:20 +08:00
|
|
|
function".
|
|
|
|
|
2020-05-31 08:42:26 +08:00
|
|
|
- One or more `elvish-transcript` code blocks showing example usages, which
|
|
|
|
are transcripts of actual REPL input and output. Transcripts must use the
|
|
|
|
default prompt `~>` and default value output indicator `▶`. You can use
|
|
|
|
`elvish -norc` if you have customized either in your `rc.elv`.
|
|
|
|
|
|
|
|
Place the comment block before the implementation of the function. If the
|
|
|
|
function has no implementation (e.g. it is a simple wrapper of a function from
|
|
|
|
the Go standard library), place it before the top-level declaration of the
|
|
|
|
namespace.
|
2020-03-19 07:15:20 +08:00
|
|
|
|
2020-05-31 08:42:26 +08:00
|
|
|
Similarly, reference docs for variables start with `//elvdoc:var`:
|
2020-03-19 07:15:20 +08:00
|
|
|
|
|
|
|
```go
|
|
|
|
//elvdoc:var name-of-var
|
|
|
|
//
|
|
|
|
// Something.
|
|
|
|
```
|
|
|
|
|
2020-05-31 08:42:26 +08:00
|
|
|
Variables do not have signatures, and are described using a noun phrase.
|
2020-03-19 07:15:20 +08:00
|
|
|
Examples are not always needed; if they are, they can be given in the same
|
2020-05-31 08:42:26 +08:00
|
|
|
format as examples for functions.
|
2020-03-19 07:15:20 +08:00
|
|
|
|
2020-03-19 05:56:12 +08:00
|
|
|
## Generating code
|
2016-02-19 07:13:35 +08:00
|
|
|
|
2020-03-19 05:56:12 +08:00
|
|
|
Elvish uses generated code in a few places. As is the usual case with Go
|
|
|
|
projects, they are committed into the repo, and if you change the input of a
|
|
|
|
generated file you should re-generate it.
|
2016-02-19 07:13:35 +08:00
|
|
|
|
2020-03-19 05:56:12 +08:00
|
|
|
Use the standard command, `go generate ./...` to regenerate all files.
|
2016-02-19 07:13:35 +08:00
|
|
|
|
2020-03-19 05:56:12 +08:00
|
|
|
Dependencies of the generation rules:
|
2016-02-19 07:13:35 +08:00
|
|
|
|
2020-03-19 05:56:12 +08:00
|
|
|
- The `stringer` tool: Install with
|
|
|
|
`go get -u golang.org/x/tools/cmd/stringer`;
|
2016-02-19 07:13:35 +08:00
|
|
|
|
2020-03-19 05:56:12 +08:00
|
|
|
- An installed `elvish` in your PATH;
|
|
|
|
|
|
|
|
## Formatting source files
|
|
|
|
|
2020-06-25 06:00:59 +08:00
|
|
|
Install [goimports](https://pkg.go.dev/golang.org/x/tools/cmd/goimports) to
|
|
|
|
format Go files, and [prettier](https://prettier.io/) to format Markdown files.
|
2020-03-19 05:56:12 +08:00
|
|
|
|
|
|
|
```sh
|
2020-06-25 06:00:59 +08:00
|
|
|
go get golang.org/x/tools/cmd/goimports
|
|
|
|
npm install --global prettier
|
2020-03-19 05:56:12 +08:00
|
|
|
```
|
|
|
|
|
2020-06-25 06:00:59 +08:00
|
|
|
Once you have installed the tools, use `make style` to format Go and Markdown
|
|
|
|
files. If you prefer, you can also configure your editor to run these commands
|
|
|
|
automatically when saving Go or Markdown sources.
|
2020-03-19 05:56:12 +08:00
|
|
|
|
2020-06-25 06:00:59 +08:00
|
|
|
Use `make checkstyle` to check if all Go and Markdown files are properly
|
|
|
|
formatted.
|
2016-02-19 07:13:35 +08:00
|
|
|
|
|
|
|
## Licensing
|
|
|
|
|
2020-03-19 05:56:12 +08:00
|
|
|
By contributing, you agree to license your code under the same license as
|
|
|
|
existing source code of elvish. See the LICENSE file.
|