ci(makefile): add format target (#468)

- 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
This commit is contained in:
Josh McKinney 2023-09-05 00:48:36 -07:00 committed by GitHub
parent 080a05bbd3
commit b996102837
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 52 deletions

View file

@ -43,9 +43,9 @@ jobs:
- name: Install cargo-make - name: Install cargo-make
uses: taiki-e/install-action@cargo-make uses: taiki-e/install-action@cargo-make
- name: Check formatting - name: Check formatting
run: cargo make fmt run: cargo make lint-format
- name: Check documentation - name: Check documentation
run: cargo make check-doc run: cargo make lint-docs
- name: Check conventional commits - name: Check conventional commits
uses: crate-ci/committed@master uses: crate-ci/committed@master
with: with:

View file

@ -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 reformatting changes into a separate PR from those that make a behavioral change, as the tests help
guarantee that the behavior is unchanged. 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 ### Search `tui-rs` for similar work
The original fork of Ratatui, [`tui-rs`](https://github.com/fdehau/tui-rs/), has a large amount of The original fork of Ratatui, [`tui-rs`](https://github.com/fdehau/tui-rs/), has a large amount of
@ -142,6 +147,7 @@ let style = Style::default().fg(Color::Red).add_modifier(Modifiers::BOLD);
#### Format #### Format
- First line is summary, second is blank, third onward is more detail - First line is summary, second is blank, third onward is more detail
```rust ```rust
/// Summary /// Summary
/// ///
@ -155,6 +161,7 @@ See [vscode rewrap extension](https://marketplace.visualstudio.com/items?itemNam
- Doc comments are above macros - Doc comments are above macros
i.e. i.e.
```rust ```rust
/// doc comment /// doc comment
#[derive(Debug)] #[derive(Debug)]

View file

@ -12,29 +12,30 @@ alias = "ci"
[tasks.ci] [tasks.ci]
description = "Run continuous integration tasks" description = "Run continuous integration tasks"
dependencies = [ dependencies = ["lint-style", "clippy", "check", "test"]
"style-check",
"clippy",
"check",
"test",
]
[tasks.style-check] [tasks.lint-style]
description = "Check code style" description = "Lint code style (formatting, typos, docs)"
dependencies = ["fmt", "typos", "check-doc"] dependencies = ["lint-format", "lint-typos", "lint-docs"]
[tasks.fmt] [tasks.lint-format]
description = "Format source code" description = "Lint code formatting"
toolchain = "nightly" toolchain = "nightly"
command = "cargo" command = "cargo"
args = ["fmt", "--all", "--check"] 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" description = "Run typo checks"
install_crate = { crate_name = "typos-cli", binary = "typos", test_arg = "--version" } install_crate = { crate_name = "typos-cli", binary = "typos", test_arg = "--version" }
command = "typos" command = "typos"
[tasks.check-doc] [tasks.lint-docs]
description = "Check documentation for errors and warnings" description = "Check documentation for errors and warnings"
toolchain = "nightly" toolchain = "nightly"
command = "cargo" command = "cargo"
@ -44,39 +45,35 @@ args = [
"--", "--",
"-Zunstable-options", "-Zunstable-options",
"--check", "--check",
"-Dwarnings" "-Dwarnings",
] ]
[tasks.check] [tasks.check]
description = "Check code for errors and warnings" description = "Check code for errors and warnings"
command = "cargo" command = "cargo"
args = [ args = ["check", "--all-targets", "--all-features"]
"check",
"--all-targets",
"--all-features"
]
[tasks.check.windows] [tasks.check.windows]
args = [ args = [
"check", "check",
"--all-targets", "--all-targets",
"--no-default-features", "--features", "${ALL_FEATURES},crossterm,termwiz" "--no-default-features",
"--features",
"${ALL_FEATURES},crossterm,termwiz",
] ]
[tasks.build] [tasks.build]
description = "Compile the project" description = "Compile the project"
command = "cargo" command = "cargo"
args = [ args = ["build", "--all-targets", "--all-features"]
"build",
"--all-targets",
"--all-features",
]
[tasks.build.windows] [tasks.build.windows]
args = [ args = [
"build", "build",
"--all-targets", "--all-targets",
"--no-default-features", "--features", "${ALL_FEATURES},crossterm,termwiz" "--no-default-features",
"--features",
"${ALL_FEATURES},crossterm,termwiz",
] ]
[tasks.clippy] [tasks.clippy]
@ -99,7 +96,9 @@ args = [
"--all-targets", "--all-targets",
"--tests", "--tests",
"--benches", "--benches",
"--no-default-features", "--features", "${ALL_FEATURES},crossterm,termwiz", "--no-default-features",
"--features",
"${ALL_FEATURES},crossterm,termwiz",
"--", "--",
"-D", "-D",
"warnings", "warnings",
@ -107,40 +106,34 @@ args = [
[tasks.test] [tasks.test]
description = "Run tests" description = "Run tests"
dependencies = [ dependencies = ["test-doc"]
"test-doc",
]
command = "cargo" command = "cargo"
args = [ args = ["test", "--all-targets", "--all-features"]
"test",
"--all-targets",
"--all-features",
]
[tasks.test-windows] [tasks.test-windows]
description = "Run tests on Windows" description = "Run tests on Windows"
dependencies = [ dependencies = ["test-doc"]
"test-doc",
]
args = [ args = [
"test", "test",
"--all-targets", "--all-targets",
"--no-default-features", "--features", "${ALL_FEATURES},crossterm,termwiz" "--no-default-features",
"--features",
"${ALL_FEATURES},crossterm,termwiz",
] ]
[tasks.test-doc] [tasks.test-doc]
description = "Run documentation tests" description = "Run documentation tests"
command = "cargo" command = "cargo"
args = [ args = ["test", "--doc", "--all-features"]
"test", "--doc",
"--all-features",
]
[tasks.test-doc.windows] [tasks.test-doc.windows]
args = [ args = [
"test", "--doc", "test",
"--no-default-features", "--features", "${ALL_FEATURES},crossterm,termwiz" "--doc",
"--no-default-features",
"--features",
"${ALL_FEATURES},crossterm,termwiz",
] ]
[tasks.test-backend] [tasks.test-backend]
@ -150,7 +143,9 @@ command = "cargo"
args = [ args = [
"test", "test",
"--all-targets", "--all-targets",
"--no-default-features", "--features", "${ALL_FEATURES},${@}" "--no-default-features",
"--features",
"${ALL_FEATURES},${@}",
] ]
@ -160,7 +155,8 @@ command = "cargo"
args = [ args = [
"llvm-cov", "llvm-cov",
"--lcov", "--lcov",
"--output-path", "target/lcov.info", "--output-path",
"target/lcov.info",
"--all-features", "--all-features",
] ]
@ -169,16 +165,25 @@ command = "cargo"
args = [ args = [
"llvm-cov", "llvm-cov",
"--lcov", "--lcov",
"--output-path", "target/lcov.info", "--output-path",
"target/lcov.info",
"--no-default-features", "--no-default-features",
"--features", "${ALL_FEATURES},crossterm,termwiz", "--features",
"${ALL_FEATURES},crossterm,termwiz",
] ]
[tasks.run-example] [tasks.run-example]
private = true private = true
condition = { env_set = ["TUI_EXAMPLE_NAME"] } condition = { env_set = ["TUI_EXAMPLE_NAME"] }
command = "cargo" 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] [tasks.build-examples]
description = "Compile project examples" description = "Compile project examples"