Skip to content

Commit

Permalink
ci(makefile): add format target (#468)
Browse files Browse the repository at this point in the history
- add format target to Makefile.toml that actually fixes the formatting
- rename fmt target to lint-format
- rename style-check target to lint-style
- rename typos target to lint-typos
- rename check-docs target to lint-docs
- add section to CONTRIBUTING.md about formatting
  • Loading branch information
joshka authored Sep 5, 2023
1 parent 080a05b commit b996102
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ jobs:
- name: Install cargo-make
uses: taiki-e/install-action@cargo-make
- name: Check formatting
run: cargo make fmt
run: cargo make lint-format
- name: Check documentation
run: cargo make check-doc
run: cargo make lint-docs
- name: Check conventional commits
uses: crate-ci/committed@master
with:
Expand Down
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ change becomes a place where a bug may have been introduced. Consider splitting
reformatting changes into a separate PR from those that make a behavioral change, as the tests help
guarantee that the behavior is unchanged.

### Code formatting

Run `cargo make format` before committing to ensure that code is consistently formatted with
rustfmt. Configuration is in [rustfmt.toml](./rustfmt.toml).

### Search `tui-rs` for similar work

The original fork of Ratatui, [`tui-rs`](https://github.com/fdehau/tui-rs/), has a large amount of
Expand Down Expand Up @@ -142,6 +147,7 @@ let style = Style::default().fg(Color::Red).add_modifier(Modifiers::BOLD);
#### Format

- First line is summary, second is blank, third onward is more detail

```rust
/// Summary
///
Expand All @@ -155,6 +161,7 @@ See [vscode rewrap extension](https://marketplace.visualstudio.com/items?itemNam

- Doc comments are above macros
i.e.

```rust
/// doc comment
#[derive(Debug)]
Expand Down
105 changes: 55 additions & 50 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,30 @@ alias = "ci"

[tasks.ci]
description = "Run continuous integration tasks"
dependencies = [
"style-check",
"clippy",
"check",
"test",
]
dependencies = ["lint-style", "clippy", "check", "test"]

[tasks.style-check]
description = "Check code style"
dependencies = ["fmt", "typos", "check-doc"]
[tasks.lint-style]
description = "Lint code style (formatting, typos, docs)"
dependencies = ["lint-format", "lint-typos", "lint-docs"]

[tasks.fmt]
description = "Format source code"
[tasks.lint-format]
description = "Lint code formatting"
toolchain = "nightly"
command = "cargo"
args = ["fmt", "--all", "--check"]

[tasks.typos]
[tasks.format]
description = "Fix code formatting"
toolchain = "nightly"
command = "cargo"
args = ["fmt", "--all"]

[tasks.lint-typos]
description = "Run typo checks"
install_crate = { crate_name = "typos-cli", binary = "typos", test_arg = "--version" }
command = "typos"

[tasks.check-doc]
[tasks.lint-docs]
description = "Check documentation for errors and warnings"
toolchain = "nightly"
command = "cargo"
Expand All @@ -44,39 +45,35 @@ args = [
"--",
"-Zunstable-options",
"--check",
"-Dwarnings"
"-Dwarnings",
]

[tasks.check]
description = "Check code for errors and warnings"
command = "cargo"
args = [
"check",
"--all-targets",
"--all-features"
]
args = ["check", "--all-targets", "--all-features"]

[tasks.check.windows]
args = [
"check",
"--all-targets",
"--no-default-features", "--features", "${ALL_FEATURES},crossterm,termwiz"
"--no-default-features",
"--features",
"${ALL_FEATURES},crossterm,termwiz",
]

[tasks.build]
description = "Compile the project"
command = "cargo"
args = [
"build",
"--all-targets",
"--all-features",
]
args = ["build", "--all-targets", "--all-features"]

[tasks.build.windows]
args = [
"build",
"--all-targets",
"--no-default-features", "--features", "${ALL_FEATURES},crossterm,termwiz"
"--no-default-features",
"--features",
"${ALL_FEATURES},crossterm,termwiz",
]

[tasks.clippy]
Expand All @@ -99,48 +96,44 @@ args = [
"--all-targets",
"--tests",
"--benches",
"--no-default-features", "--features", "${ALL_FEATURES},crossterm,termwiz",
"--no-default-features",
"--features",
"${ALL_FEATURES},crossterm,termwiz",
"--",
"-D",
"warnings",
]

[tasks.test]
description = "Run tests"
dependencies = [
"test-doc",
]
dependencies = ["test-doc"]
command = "cargo"
args = [
"test",
"--all-targets",
"--all-features",
]
args = ["test", "--all-targets", "--all-features"]


[tasks.test-windows]
description = "Run tests on Windows"
dependencies = [
"test-doc",
]
dependencies = ["test-doc"]
args = [
"test",
"--all-targets",
"--no-default-features", "--features", "${ALL_FEATURES},crossterm,termwiz"
"--no-default-features",
"--features",
"${ALL_FEATURES},crossterm,termwiz",
]

[tasks.test-doc]
description = "Run documentation tests"
command = "cargo"
args = [
"test", "--doc",
"--all-features",
]
args = ["test", "--doc", "--all-features"]

[tasks.test-doc.windows]
args = [
"test", "--doc",
"--no-default-features", "--features", "${ALL_FEATURES},crossterm,termwiz"
"test",
"--doc",
"--no-default-features",
"--features",
"${ALL_FEATURES},crossterm,termwiz",
]

[tasks.test-backend]
Expand All @@ -150,7 +143,9 @@ command = "cargo"
args = [
"test",
"--all-targets",
"--no-default-features", "--features", "${ALL_FEATURES},${@}"
"--no-default-features",
"--features",
"${ALL_FEATURES},${@}",
]


Expand All @@ -160,7 +155,8 @@ command = "cargo"
args = [
"llvm-cov",
"--lcov",
"--output-path", "target/lcov.info",
"--output-path",
"target/lcov.info",
"--all-features",
]

Expand All @@ -169,16 +165,25 @@ command = "cargo"
args = [
"llvm-cov",
"--lcov",
"--output-path", "target/lcov.info",
"--output-path",
"target/lcov.info",
"--no-default-features",
"--features", "${ALL_FEATURES},crossterm,termwiz",
"--features",
"${ALL_FEATURES},crossterm,termwiz",
]

[tasks.run-example]
private = true
condition = { env_set = ["TUI_EXAMPLE_NAME"] }
command = "cargo"
args = ["run", "--release", "--example", "${TUI_EXAMPLE_NAME}", "--features", "all-widgets"]
args = [
"run",
"--release",
"--example",
"${TUI_EXAMPLE_NAME}",
"--features",
"all-widgets",
]

[tasks.build-examples]
description = "Compile project examples"
Expand Down

0 comments on commit b996102

Please sign in to comment.