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

Remove call to sed in justfile #1078

Merged
merged 3 commits into from
Jan 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 0 additions & 2 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
cognitive-complexity-threshold = 1337

doc-valid-idents = ["FreeBSD"]
15 changes: 6 additions & 9 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ man:
view-man: man
man man/just.1

version := `sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/\1/p' Cargo.toml | head -1`

# add git log messages to changelog
changes:
git log --pretty=format:%s >> CHANGELOG.md

check: actionlint fmt clippy test forbid
check: fmt clippy test forbid
#!/usr/bin/env bash
set -euxo pipefail
git diff --no-ext-diff --quiet --exit-code
grep '^\[{{ version }}\]' CHANGELOG.md
VERSION=`sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/\1/p' Cargo.toml | head -1`
grep "^\[$VERSION\]" CHANGELOG.md
cargo +nightly generate-lockfile -Z minimal-versions
cargo ltest
git checkout Cargo.lock
Expand Down Expand Up @@ -105,11 +106,7 @@ install-dev-deps:

# install system development dependencies with homebrew
install-dev-deps-homebrew:
brew tap "rhysd/actionlint" "https://github.com/rhysd/actionlint"
brew install actionlint help2man shellcheck

actionlint:
SHELLCHECK_OPTS='-e SC2006 -e SC2002 -e SC2050' actionlint
brew install help2man

# everyone's favorite animate paper clip
clippy:
Expand Down
3 changes: 3 additions & 0 deletions src/function.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![allow(clippy::unknown_clippy_lints)]
#![allow(clippy::unnecessary_wraps)]

use crate::common::*;

use Function::*;
Expand Down
10 changes: 5 additions & 5 deletions src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<'src> Justfile<'src> {
}

let dotenv = if config.load_dotenv {
load_dotenv(&config, &self.settings, &search.working_directory)?
load_dotenv(config, &self.settings, &search.working_directory)?
} else {
BTreeMap::new()
};
Expand Down Expand Up @@ -129,7 +129,7 @@ impl<'src> Justfile<'src> {
binary, arguments, ..
} => {
let mut command = if config.shell_command {
let mut command = self.settings.shell_command(&config);
let mut command = self.settings.shell_command(config);
command.arg(binary);
command
} else {
Expand Down Expand Up @@ -168,7 +168,7 @@ impl<'src> Justfile<'src> {
print!("{}", value);
} else {
return Err(Error::EvalUnknownVariable {
suggestion: self.suggest_variable(&variable),
suggestion: self.suggest_variable(variable),
variable: variable.clone(),
});
}
Expand Down Expand Up @@ -261,7 +261,7 @@ impl<'src> Justfile<'src> {

let mut ran = BTreeSet::new();
for (recipe, arguments) in grouped {
self.run_recipe(&context, recipe, arguments, &dotenv, &search, &mut ran)?;
self.run_recipe(&context, recipe, arguments, &dotenv, search, &mut ran)?;
}

Ok(())
Expand Down Expand Up @@ -344,7 +344,7 @@ impl<'src> Justfile<'src> {
}

let mut invocation = vec![recipe.name().to_owned()];
for argument in arguments.iter().cloned() {
for argument in arguments.iter().copied() {
invocation.push(argument.to_owned());
}

Expand Down
2 changes: 1 addition & 1 deletion src/keyed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ where
S: Serializer,
K: Keyed<'src>,
{
serializer.serialize_str(&keyed.key())
serializer.serialize_str(keyed.key())
}

pub(crate) fn serialize_option<'src, S, K>(
Expand Down
2 changes: 1 addition & 1 deletion src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<'src> Lexer<'src> {

/// Get current indentation
fn indentation(&self) -> &'src str {
self.indentation.last().cloned().unwrap()
self.indentation.last().unwrap()
}

/// Are we currently indented
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![deny(clippy::all, clippy::pedantic)]
#![allow(
clippy::doc_markdown,
clippy::enum_glob_use,
clippy::if_not_else,
clippy::missing_errors_doc,
Expand Down
2 changes: 1 addition & 1 deletion src/load_dotenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(crate) fn load_dotenv(
}

if let Some(path) = &config.dotenv_path {
return load_from_file(config, settings, &path);
return load_from_file(config, settings, path);
}

let filename = config
Expand Down
2 changes: 1 addition & 1 deletion src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ impl<'src> Serialize for Name<'src> {
where
S: Serializer,
{
serializer.serialize_str(&self.lexeme())
serializer.serialize_str(self.lexeme())
}
}
8 changes: 4 additions & 4 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pub(crate) trait Node<'src> {
impl<'src> Node<'src> for Ast<'src> {
fn tree(&self) -> Tree<'src> {
Tree::atom("justfile")
.extend(self.items.iter().map(|item| item.tree()))
.extend(self.warnings.iter().map(|warning| warning.tree()))
.extend(self.items.iter().map(Node::tree))
.extend(self.warnings.iter().map(Node::tree))
}
}

Expand Down Expand Up @@ -179,7 +179,7 @@ impl<'src> Node<'src> for UnresolvedRecipe<'src> {
}

if !self.body.is_empty() {
t.push_mut(Tree::atom("body").extend(self.body.iter().map(|line| line.tree())));
t.push_mut(Tree::atom("body").extend(self.body.iter().map(Node::tree)));
}

t
Expand All @@ -200,7 +200,7 @@ impl<'src> Node<'src> for Parameter<'src> {

impl<'src> Node<'src> for Line<'src> {
fn tree(&self) -> Tree<'src> {
Tree::list(self.fragments.iter().map(|fragment| fragment.tree()))
Tree::list(self.fragments.iter().map(Node::tree))
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
expected: self
.expected
.iter()
.cloned()
.copied()
.filter(|kind| *kind != ByteOrderMark)
.collect::<Vec<TokenKind>>(),
found: self.next()?.kind,
Expand All @@ -77,7 +77,7 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
fn rest(&self) -> impl Iterator<Item = Token<'src>> + 'tokens {
self.tokens[self.next..]
.iter()
.cloned()
.copied()
.filter(|token| token.kind != Whitespace)
}

Expand Down Expand Up @@ -654,10 +654,10 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
};

Ok(Parameter {
name,
kind,
default,
export,
kind,
name,
})
}

Expand Down Expand Up @@ -777,7 +777,7 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
self.expect(BracketR)?;

Ok(Set {
value: Setting::Shell(setting::Shell { command, arguments }),
value: Setting::Shell(setting::Shell { arguments, command }),
name,
})
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/recipe_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<'src: 'run, 'run> RecipeResolver<'src, 'run> {

if let Some(resolved) = self.resolved_recipes.get(name) {
// dependency already resolved
dependencies.push(Rc::clone(&resolved));
dependencies.push(Rc::clone(resolved));
} else if stack.contains(&name) {
let first = stack[0];
stack.push(first);
Expand All @@ -97,7 +97,7 @@ impl<'src: 'run, 'run> RecipeResolver<'src, 'run> {
circle: stack
.iter()
.skip_while(|name| **name != dependency.recipe.lexeme())
.cloned()
.copied()
.collect(),
}),
);
Expand Down
2 changes: 1 addition & 1 deletion src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'src, 'run> Scope<'src, 'run> {
}

pub(crate) fn names(&self) -> impl Iterator<Item = &str> {
self.bindings.keys().cloned()
self.bindings.keys().copied()
}

pub(crate) fn parent(&self) -> Option<&'run Scope<'src, 'run>> {
Expand Down
6 changes: 3 additions & 3 deletions src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Search {
) -> SearchResult<Self> {
match search_config {
SearchConfig::FromInvocationDirectory => {
let justfile = Self::justfile(&invocation_directory)?;
let justfile = Self::justfile(invocation_directory)?;

let working_directory = Self::working_directory_from_justfile(&justfile)?;

Expand Down Expand Up @@ -68,7 +68,7 @@ impl Search {
) -> SearchResult<Self> {
match search_config {
SearchConfig::FromInvocationDirectory => {
let working_directory = Self::project_root(&invocation_directory)?;
let working_directory = Self::project_root(invocation_directory)?;

let justfile = working_directory.join(DEFAULT_JUSTFILE_NAME);

Expand Down Expand Up @@ -174,7 +174,7 @@ impl Search {
io_error,
directory: directory.to_owned(),
})?;
for project_root_child in PROJECT_ROOT_CHILDREN.iter().cloned() {
for project_root_child in PROJECT_ROOT_CHILDREN.iter().copied() {
if entry.file_name() == project_root_child {
return Ok(directory.to_owned());
}
Expand Down
22 changes: 11 additions & 11 deletions src/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Subcommand {
Self::changelog();
return Ok(());
}
Completions { shell } => return Self::completions(&shell),
Completions { shell } => return Self::completions(shell),
Init => return Self::init(config),
_ => {}
}
Expand All @@ -59,7 +59,7 @@ impl Subcommand {

let src = loader.load(&search.justfile)?;

let tokens = Lexer::lex(&src)?;
let tokens = Lexer::lex(src)?;
let ast = Parser::parse(&tokens)?;
let justfile = Analyzer::analyze(ast.clone())?;

Expand All @@ -74,16 +74,16 @@ impl Subcommand {
Self::choose(config, justfile, &search, overrides, chooser.as_deref())?;
}
Command { overrides, .. } | Evaluate { overrides, .. } => {
justfile.run(config, &search, overrides, &[])?
justfile.run(config, &search, overrides, &[])?;
}
Dump => Self::dump(config, ast, justfile)?,
Format => Self::format(config, &search, &src, ast)?,
Format => Self::format(config, &search, src, ast)?,
List => Self::list(config, justfile),
Run {
arguments,
overrides,
} => justfile.run(config, &search, overrides, arguments)?,
Show { ref name } => Self::show(config, &name, justfile)?,
Show { ref name } => Self::show(config, name, justfile)?,
Summary => Self::summary(config, justfile),
Variables => Self::variables(justfile),
Changelog | Completions { .. } | Edit | Init => unreachable!(),
Expand All @@ -107,7 +107,7 @@ impl Subcommand {
.public_recipes(config.unsorted)
.iter()
.filter(|recipe| recipe.min_arguments() == 0)
.cloned()
.copied()
.collect::<Vec<&Recipe<Dependency>>>();

if recipes.is_empty() {
Expand All @@ -121,7 +121,7 @@ impl Subcommand {

let result = justfile
.settings
.shell_command(&config)
.shell_command(config)
.arg(&chooser)
.current_dir(&search.working_directory)
.stdin(Stdio::piped())
Expand All @@ -132,8 +132,8 @@ impl Subcommand {
Ok(child) => child,
Err(io_error) => {
return Err(Error::ChooserInvoke {
shell_binary: justfile.settings.shell_binary(&config).to_owned(),
shell_arguments: justfile.settings.shell_arguments(&config).join(" "),
shell_binary: justfile.settings.shell_binary(config).to_owned(),
shell_arguments: justfile.settings.shell_arguments(config).join(" "),
chooser,
io_error,
});
Expand Down Expand Up @@ -365,7 +365,7 @@ impl Subcommand {
}
}

let max_line_width = cmp::min(line_widths.values().cloned().max().unwrap_or(0), 30);
let max_line_width = cmp::min(line_widths.values().copied().max().unwrap_or(0), 30);

let doc_color = config.color.stdout().doc();
print!("{}", config.list_heading);
Expand All @@ -392,7 +392,7 @@ impl Subcommand {
doc_color.paint("#"),
doc_color.paint(doc),
padding = max_line_width
.saturating_sub(line_widths.get(name).cloned().unwrap_or(max_line_width))
.saturating_sub(line_widths.get(name).copied().unwrap_or(max_line_width))
);
};

Expand Down
6 changes: 1 addition & 5 deletions src/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ impl Recipe {
private: recipe.private,
shebang: recipe.shebang,
quiet: recipe.quiet,
dependencies: recipe
.dependencies
.iter()
.map(|dependency| Dependency::new(dependency))
.collect(),
dependencies: recipe.dependencies.iter().map(Dependency::new).collect(),
lines: recipe.body.iter().map(Line::new).collect(),
parameters: recipe.parameters.iter().map(Parameter::new).collect(),
aliases,
Expand Down
1 change: 0 additions & 1 deletion src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ impl<'table, V: Keyed<'table> + 'table> IntoIterator for &'table Table<'table, V
type IntoIter = btree_map::Iter<'table, &'table str, V>;
type Item = (&'table &'table str, &'table V);

#[must_use]
fn into_iter(self) -> btree_map::Iter<'table, &'table str, V> {
self.map.iter()
}
Expand Down
2 changes: 1 addition & 1 deletion src/unindent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn unindent(text: &str) -> String {
let common_indentation = lines
.iter()
.filter(|line| !blank(line))
.cloned()
.copied()
.map(indentation)
.fold(
None,
Expand Down
2 changes: 1 addition & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Test {

pub(crate) fn tree(self, mut tree: Tree) -> Self {
tree.map(|_name, content| unindent(content));
tree.instantiate(&self.tempdir.path()).unwrap();
tree.instantiate(self.tempdir.path()).unwrap();
self
}

Expand Down