Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor and polish the source code of the library #29

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix the visibility of nu_formatter items
- `trim_ascii_whitespaces` is never used outside `formatting`
- the `formatting` commands are only used internally
  • Loading branch information
amtoine committed Jun 16, 2023
commit fd032a012d0cc2a7f78bf47d24cea9ffc0c4c334
4 changes: 2 additions & 2 deletions src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use nu_protocol::{
/// format an array of bytes
///
/// Reading the file gives you a list of bytes
pub fn format_inner(contents: &[u8], _config: &Config) -> Vec<u8> {
pub(crate) fn format_inner(contents: &[u8], _config: &Config) -> Vec<u8> {
let engine_state = engine::EngineState::new();
let mut working_set = StateWorkingSet::new(&engine_state);

Expand Down Expand Up @@ -129,7 +129,7 @@ fn add_newline_at_end_of_file(out: Vec<u8>) -> Vec<u8> {
/// the best way to format is to strip all the whitespace
/// and afterwards include the new lines and indentation correctly
/// according to the configuration
pub fn trim_ascii_whitespace(x: &[u8]) -> &[u8] {
fn trim_ascii_whitespace(x: &[u8]) -> &[u8] {
let Some(from) = x.iter().position(|x| !x.is_ascii_whitespace()) else { return &x[0..0] };
let to = x.iter().rposition(|x| !x.is_ascii_whitespace()).unwrap();
&x[from..=to]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::io::Write;
use std::path::PathBuf;

pub mod config;
pub mod formatting;
mod formatting;

/// format a Nushell file inplace
pub fn format_single_file(file: &PathBuf, config: &Config) {
Expand Down