Skip to content

Commit

Permalink
✏️ resolved changes asked in the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
AucaCoyan committed Jun 13, 2023
1 parent 13ae3b0 commit c1f18dd
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 30 deletions.
6 changes: 3 additions & 3 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Salutations! Thanks for coming by and the interest into this project!
We would like to order the contributions like this:

- Before you start hacking, it is important to **ask first** if your idea or bugfix is in order.
Create an issue or come and say hi in the [`#nufmt` channel][nufmt discord channel] by joining [the discord][Nushell discord].
We don't bite!.
Create an issue or come and say hi in the [`#nufmt` channel](https://discord.com/channels/601130461678272522/1087437882396004442) by joining [the discord](https://discord.gg/NtAbbGn).
We don't bite!.

It would be sad that you do the effort to clone the project, successfully make the PR, but it wasn't in our plans or there is another PR that is currently adressing that issue.

Expand All @@ -16,7 +16,7 @@ We don't bite!.

This is a list of things we would like to have and mantain across time. Please do your best to abide by.

- Everything should be explained: rust docs, comments, drawings, pick what makes you comfortable, but it is important to make it clear. There will always be some new guy or gal into the project we want to welcome 😄.
- Everything should be explained: rust docs, drawings, markdown files, pick what makes you comfortable, but it is important to make it clear. There will always be some new guy or gal into the project we want to welcome 😄.
- Use clear variable names and try to avoid confusing abbreviations. Think that your peers may not be fully fluent in english 💬.

[Nushell discord]: https://discord.gg/NtAbbGn
Expand Down
6 changes: 2 additions & 4 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn format_inner(contents: &[u8], _config: &Config) -> Vec<u8> {
trace!("parsed block:\n{:?}", &parsed_block);

// check if the block has at least 1 pipeline
if !block_has_pipilnes(&parsed_block) {
if !block_has_pipelines(&parsed_block) {
trace!("block has no pipelines!");
println!("File has no code to format.");
return contents.to_vec();
Expand Down Expand Up @@ -177,13 +177,11 @@ pub fn trim_ascii_whitespace(x: &[u8]) -> &[u8] {
/// We don't want to return a blank file if that is the case,
/// so this check gives the opportunity to `nufmt`
/// to know when not to touch the file at all in the implementation.
fn block_has_pipilnes(block: &Block) -> bool {
fn block_has_pipelines(block: &Block) -> bool {
!block.pipelines.is_empty()
}

/// Returns true if the `Span` is the last Span in the slice of `flat`
///
/// Takes a Span and a slice of tuples `(Span, FlatShape)`.
fn is_last_span(span: Span, flat: &[(Span, FlatShape)]) -> bool {
span == flat.last().unwrap().0
}
14 changes: 1 addition & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
//!
//! It does not do anything more than that, which makes it so fast.

#![deny(rustdoc::broken_intra_doc_links)] // throw error if finds a broken link in doc
#![warn(missing_docs // or docs are missing for public members
,clippy::missing_docs_in_private_items // warn if docs are missing in private items
,clippy::explicit_iter_loop // warn if you find array.iter(), &array will do the same
,clippy::explicit_into_iter_loop // same with into_iter()
,clippy::semicolon_if_nothing_returned // consistent semicolon endings
,clippy::doc_markdown // warn if _ :: or ` are missing in .md
,clippy::manual_let_else // warn if a match has only 1 arm => do if let
)]

use config::Config;
use formatting::format_inner;
use log::{debug, trace};
Expand All @@ -23,7 +13,7 @@ use std::path::PathBuf;
pub mod config;
pub mod formatting;

/// Reads a `&PathBuf` pointing to a file and format it. Then writes the file inplace.
/// Reads a file and format it. Then writes the file inplace.
pub fn format_single_file(file: &PathBuf, config: &Config) {
// read the contents of the file
let contents = std::fs::read(file)
Expand All @@ -47,8 +37,6 @@ pub fn format_single_file(file: &PathBuf, config: &Config) {
}

/// Take a `String` and format it. Then returns a new `String`
///
/// Takes a pointer to a String `&String` and a config `&Config`.
pub fn format_string(input_string: &String, config: &Config) -> String {
let contents = input_string.as_bytes();
let formatted_bytes = format_inner(contents, config);
Expand Down
10 changes: 0 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@
//!
//! - `-v` or `--version` prints the version and exit

#![deny(rustdoc::broken_intra_doc_links)] // throw error if finds a broken link in doc
#![warn(missing_docs // or docs are missing for public members
,clippy::missing_docs_in_private_items // warn if docs are missing in private items
,clippy::explicit_iter_loop // warn if you find array.iter(), &array will do the same
,clippy::explicit_into_iter_loop // same with into_iter()
,clippy::semicolon_if_nothing_returned // consistent semicolon endings
,clippy::doc_markdown // warn if _ :: or ` are missing in .md
,clippy::manual_let_else // warn if a match has only 1 arm => do if let
)]

use anyhow::{Ok, Result};
use clap::Parser;
use log::trace;
Expand Down
119 changes: 119 additions & 0 deletions toolkit.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# this module regroups a bunch of development tools to make the development
# process easier for anyone.
#
# the main purpose of `toolkit` is to offer an easy to use interface for the
# developer during a PR cycle, namely to (**1**) format the source base,
# (**2**) catch classical flaws in the new changes with *clippy* and (**3**)
# make sure all the tests pass.

# check standard code formatting and apply the changes
export def fmt [
--check: bool # do not apply the format changes, only check the syntax
--verbose: bool # print extra information about the command's progress
] {
if $verbose {
print $"running ('toolkit fmt' | pretty-print-command)"
}

if $check {
try {
cargo fmt --all -- --check
} catch {
error make -u { msg: $"\nplease run ('toolkit fmt' | pretty-print-command) to fix formatting!" }
}
} else {
cargo fmt --all
}
}

# check that you're using the standard code style
#
# > it is important to make `clippy` happy :relieved:
export def clippy [
--verbose: bool # print extra information about the command's progress
--dataframe: bool # use the dataframe feature
] {
if $verbose {
print $"running ('toolkit clippy' | pretty-print-command)"
}
# clippy help
# To allow or deny a lint from the command line you can use `cargo clippy --`
# with:
# -W --warn OPT Set lint warnings
# -A --allow OPT Set lint allowed
# -D --deny OPT Set lint denied
# -F --forbid OPT Set lint forbidden
try {
if $dataframe {

cargo clippy --workspace --features=dataframe -- -D warnings -D clippy::missing_docs_in_private_items -D clippy::explicit_iter_loop -D clippy::explicit_into_iter_loop -D clippy::semicolon_if_nothing_returned -D clippy::doc_markdown -D clippy::manual_let_else
} else {
cargo clippy --workspace -- -D warnings -D clippy::missing_docs_in_private_items -D clippy::explicit_iter_loop -D clippy::explicit_into_iter_loop -D clippy::semicolon_if_nothing_returned -D clippy::doc_markdown -D clippy::manual_let_else
}
} catch {
error make -u { msg: $"\nplease fix the above ('clippy' | pretty-print-command) errors before continuing!" }
}
}

# check that all the tests pass
export def test [
--fast: bool # use the "nextext" `cargo` subcommand to speed up the tests (see [`cargo-nextest`](https://nexte.st/) and [`nextest-rs/nextest`](https://github.com/nextest-rs/nextest))
--dataframe: bool # use the dataframe feature
] {
if ($fast and $dataframe) {
cargo nextest run --all --features=dataframe
} else if ($fast) {
cargo nextest run --all
} else if ($dataframe) {
cargo test --workspace --features=dataframe
} else {
cargo test --workspace
}
}

# print the pipe input inside backticks, dimmed and italic, as a pretty command
def pretty-print-command [] {
$"`(ansi default_dimmed)(ansi default_italic)($in)(ansi reset)`"
}

# return a report about the check stage
#
# - fmt comes first
# - then clippy
# - and finally the tests
#
# without any option, `report` will return an empty report.
# otherwise, the truth values will be incremental, following
# the order above.
export def report [
--fail-fmt: bool
--fail-clippy: bool
--fail-test: bool
--no-fail: bool
] {
[fmt clippy test]
| wrap stage
| merge (
if $no_fail { [true true true true] }
else if $fail_fmt { [false $nothing $nothing $nothing] }
else if $fail_clippy { [true false $nothing $nothing] }
else if $fail_test { [true true false $nothing] }
else { [$nothing $nothing $nothing $nothing] }
| wrap success
)
| upsert emoji {|it|
if ($it.success == $nothing) {
":black_circle:"
} else if $it.success {
":green_circle:"
} else {
":red_circle:"
}
}
| each {|it|
$"- ($it.emoji) `toolkit ($it.stage)`"
}
| to text
}

export def main [] { help toolkit }

0 comments on commit c1f18dd

Please sign in to comment.