Skip to content

Commit

Permalink
ci: Use dprint to format documentation + TOML files (starship#3426)
Browse files Browse the repository at this point in the history
Adds Rust-based standardized markdown formatting and a CI step to catch unformatted files.
  • Loading branch information
chipbuster authored Jan 20, 2022
1 parent 9a4c1b5 commit 0965667
Show file tree
Hide file tree
Showing 16 changed files with 903 additions and 833 deletions.
24 changes: 12 additions & 12 deletions .cargo/audit.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[advisories]
ignore = [
# Out-of-bounds write in nix::unistd::getgrouplist
# Tracked in #3140
"RUSTSEC-2021-0119",
# Potential segfault in the time crate
# chrono dependency, but vulnerable function is never called
# Tacked in #3163
"RUSTSEC-2020-0071",
# chrono: Potential segfault in localtime_r invocations
# starship avoids setting any environment variables to avoid this issue
# Tracked in #3166
"RUSTSEC-2020-0159",
]
# Out-of-bounds write in nix::unistd::getgrouplist
# Tracked in #3140
"RUSTSEC-2021-0119",
# Potential segfault in the time crate
# chrono dependency, but vulnerable function is never called
# Tacked in #3163
"RUSTSEC-2020-0071",
# chrono: Potential segfault in localtime_r invocations
# starship avoids setting any environment variables to avoid this issue
# Tracked in #3166
"RUSTSEC-2020-0159",
]
43 changes: 43 additions & 0 deletions .dprint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"incremental": true,
"typescript": {},
"json": {},
"markdown": {
"lineWidth": 100
},
"toml": {},
"includes": [
"docs/**/*.{ts,js,cjs,mjs}",
"**/*.{md,toml,json}"
],
"excludes": [
"**/node_modules",
"**/*-lock.json",
".github/*",
"docs/ar-SA/**",
"docs/ckb-IR/**",
"docs/de-DE/**",
"docs/es-ES/**",
"docs/fr-FR/**",
"docs/id-ID/**",
"docs/it-IT/**",
"docs/ja-JP/**",
"docs/ko-KR/**",
"docs/nl-NL/**",
"docs/pl-PL/**",
"docs/pt-BR/**",
"docs/pt-PT/**",
"docs/ru-RU/**",
"docs/tr-TR/**",
"docs/vi-VN/**",
"docs/zh-CN/**",
"docs/zh-TW/**",
"target/"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.62.0.wasm",
"https://plugins.dprint.dev/json-0.14.0.wasm",
"https://plugins.dprint.dev/markdown-0.12.0.wasm",
"https://plugins.dprint.dev/toml-0.5.3.wasm"
]
}
17 changes: 17 additions & 0 deletions .github/workflows/format-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Format + Docs Workflow
on:
push:
paths: ["docs/**","**.md","**.toml","**.js","**.json","**.ts"]
pull_request:
paths: ["docs/**","**.md","**.toml","**.js","**.json","**.ts"]

jobs:
# Run the dprint code formatter for documentation
dprint:
name: Dprint [Docs Formatter]
runs-on: ubuntu-latest
steps:
- name: Setup | Checkout
uses: actions/[email protected]
- name: Docs | Format
uses: dprint/[email protected]
27 changes: 13 additions & 14 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Contributor Covenant Code of Conduct

## Our Pledge
Expand All @@ -18,23 +17,23 @@ diverse, inclusive, and healthy community.
Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
- Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
- The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities
Expand Down Expand Up @@ -107,7 +106,7 @@ Violating these terms may lead to a permanent ban.
### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
Expand All @@ -119,11 +118,11 @@ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].

Community Impact Guidelines were inspired by
Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].

For answers to common questions about this code of conduct, see the FAQ at
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
at [https://www.contributor-covenant.org/translations][translations].

[homepage]: https://www.contributor-covenant.org
Expand Down
19 changes: 15 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,24 @@ cargo clippy --all-targets --all-features

## Formatting

Starship source files are formatted with [rustfmt](https://crates.io/crates/rustfmt-nightly), using the default configuration. Rustfmt will be ran as part of CI. Unformatted code will fail a build, so it is suggested that you run rustfmt locally:
Starship source files are formatted with [rustfmt](https://crates.io/crates/rustfmt-nightly). Markdown and TOML files (among others) are formatted with [dprint](https://github.com/dprint/dprint). Unformatted code will fail the CI, so it is suggested that you run these tools locally.

For rustfmt:

```sh
rustup component add rustfmt
cargo fmt
```

For dprint:

```sh
cargo install dprint
dprint fmt
```

Editor plugins/functionality may help you run these automatically so that you don't accidentally create a PR that fails.

## Testing

Testing is critical to making sure starship works as intended on systems big and small. Starship interfaces with many applications and system APIs when generating the prompt, so there's a lot of room for bugs to slip in.
Expand Down Expand Up @@ -233,10 +244,10 @@ writing new modules low, starship provides a lot of functionality for a module,
which requires quite a few things be done. These are listed here to help
everyone remember what they are. Don't worry: most of them are quite simple!

- [ ] Add a section to `docs/config/README.md` describing the module, and
- [ ] Add a section to `docs/config/README.md` describing the module, and
its configuration options/variables (more documentation is often
appropriate--this is a bare minimum).
- [ ] Add the variable to the appropriate location in the "Default Prompt
- [ ] Add the variable to the appropriate location in the "Default Prompt
Format" section of the documentation
- [ ] Add an appropriate choice of options to each preset in `docs/presets/README.md`
- [ ] Create configs structs/traits in `src/configs/<module>.rs` and add the
Expand All @@ -250,4 +261,4 @@ everyone remember what they are. Don't worry: most of them are quite simple!

Finally, you should make sure to write your module's code in `src/modules`
and add any commands that need to be mocked when testing in `src/utils.rs`.
Command output can also be mocked in test by using `ModuleRenderer::cmd`.
Command output can also be mocked in test by using `ModuleRenderer::cmd`.
84 changes: 39 additions & 45 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[package]
name = "starship"
version = "1.2.1"
edition = "2021"
authors = ["Starship Contributors"]
homepage = "https://starship.rs"
build = "build.rs"
categories = ["command-line-utilities"]
documentation = "https://starship.rs/guide/"
repository = "https://github.com/starship/starship"
readme = "README.md"
license = "ISC"
edition = "2021"
homepage = "https://starship.rs"
# Keep `/` in front of `README.md` to exclude localized readmes
include = ["src/**/*", "build.rs", "Cross.toml", "LICENSE", "README.md"]
keywords = ["prompt", "shell", "bash", "fish", "zsh"]
categories = ["command-line-utilities"]
build = "build.rs"
license = "ISC"
readme = "README.md"
repository = "https://github.com/starship/starship"
description = """
The minimal, blazing-fast, and infinitely customizable prompt for any shell! ☄🌌️
"""
# Keep `/` in front of `README.md` to exclude localized readmes
include = ["src/**/*", "build.rs", "Cross.toml", "LICENSE", "README.md"]

[badges]
is-it-maintained-issue-resolution = { repository = "starship/starship" }
Expand All @@ -27,61 +27,55 @@ default = ["battery"]
battery = ["starship-battery"]

[dependencies]
ansi_term = "0.12.1"
byte-unit = "4.0.13"
chrono = "0.4.19"
clap = { version = "3.0.10", features = ["derive", "cargo", "unicode"] }
clap_complete = "3.0.4"
ansi_term = "0.12.1"
directories-next = "2.0.0"
gethostname = "0.2.2"
git2 = { version = "0.13.25", default-features = false }
toml = { version = "0.5.8", features = ["preserve_order"] }
rust-ini = "0.17.0"
serde_json = "1.0.75"
rayon = "1.5.1"
indexmap = { version = "1.8.0", features = ["serde"] }
log = { version = "0.4.14", features = ["std"] }
# battery is optional (on by default) because the crate doesn't currently build for Termux
# see: https://github.com/svartalf/rust-battery/issues/33
starship-battery = { version = "0.7.9", optional = true }
path-slash = "0.1.4"
unicode-segmentation = "1.8.0"
gethostname = "0.2.2"
notify-rust = { version = "4.5.5", optional = true }
once_cell = "1.9.0"
chrono = "0.4.19"
sys-info = "0.9.1"
byte-unit = "4.0.13"
starship_module_config_derive = { version = "0.2.1", path = "starship_module_config_derive" }
yaml-rust = "0.4.5"
open = "2.0.2"
os_info = "3.1.0"
path-slash = "0.1.4"
pest = "2.1.3"
pest_derive = "2.1.0"
regex = "1.5.4"
os_info = "3.1.0"
urlencoding = "2.1.0"
open = "2.0.2"
unicode-width = "0.1.9"
terminal_size = "0.1.17"
quick-xml = "0.22.0"
rand = "0.8.4"
serde = { version = "1.0.133", features = ["derive"] }
indexmap = { version ="1.8.0", features = ["serde"] }
notify-rust = { version = "4.5.5", optional = true }
rayon = "1.5.1"
regex = "1.5.4"
rust-ini = "0.17.0"
semver = "1.0.4"
which = "4.2.2"
serde = { version = "1.0.133", features = ["derive"] }
serde_json = "1.0.75"
sha-1 = "0.10.0"
shadow-rs = "0.8.1"
versions = "4.0.0"
# battery is optional (on by default) because the crate doesn't currently build for Termux
# see: https://github.com/svartalf/rust-battery/issues/33
starship-battery = { version = "0.7.9", optional = true }
starship_module_config_derive = { version = "0.2.1", path = "starship_module_config_derive" }
strsim = "0.10.0"
sha-1 = "0.10.0"
sys-info = "0.9.1"
terminal_size = "0.1.17"
toml = { version = "0.5.8", features = ["preserve_order"] }
toml_edit = "0.13.0"
unicode-segmentation = "1.8.0"
unicode-width = "0.1.9"
urlencoding = "2.1.0"
versions = "4.0.0"
which = "4.2.2"
yaml-rust = "0.4.5"

process_control = { version = "3.2.1", features = ["crossbeam-channel"] }

shell-words = "1.0.0"

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.9", features = [
"winuser",
"securitybaseapi",
"processthreadsapi",
"handleapi",
"impl-default",
] }
winapi = { version = "0.3.9", features = ["winuser", "securitybaseapi", "processthreadsapi", "handleapi", "impl-default"] }

[target.'cfg(not(windows))'.dependencies]
nix = "0.23.1"
Expand All @@ -90,8 +84,8 @@ nix = "0.23.1"
shadow-rs = "0.8.1"

[dev-dependencies]
tempfile = "3.2.0"
mockall = "0.11"
tempfile = "3.2.0"

[profile.release]
codegen-units = 1
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ Add the following to the end of your Nushell configuration (find it by running `

```toml
startup = [
"mkdir ~/.cache/starship",
"starship init nu | save ~/.cache/starship/init.nu",
"source ~/.cache/starship/init.nu"
"mkdir ~/.cache/starship",
"starship init nu | save ~/.cache/starship/init.nu",
"source ~/.cache/starship/init.nu",
]
prompt = "starship_prompt"
```
Expand Down
8 changes: 4 additions & 4 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
disallowed-methods = [
# std::process::Command::new may inadvertly run executables from the current working directory
"std::process::Command::new",
# Setting environment variables can cause issues with non-rust code
"std::env::set_var"
# std::process::Command::new may inadvertly run executables from the current working directory
"std::process::Command::new",
# Setting environment variables can cause issues with non-rust code
"std::env::set_var",
]
Loading

0 comments on commit 0965667

Please sign in to comment.