Remove call to sed in justfile (#1078)

This commit is contained in:
Casey Rodarmor 2022-01-30 12:16:10 -08:00 committed by GitHub
parent d7897b4510
commit 27cd8fd554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 48 additions and 54 deletions

View File

@ -1,3 +1 @@
cognitive-complexity-threshold = 1337 cognitive-complexity-threshold = 1337
doc-valid-idents = ["FreeBSD"]

View File

@ -48,15 +48,16 @@ man:
view-man: man view-man: man
man man/just.1 man man/just.1
version := `sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/\1/p' Cargo.toml | head -1`
# add git log messages to changelog # add git log messages to changelog
changes: changes:
git log --pretty=format:%s >> CHANGELOG.md 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 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 +nightly generate-lockfile -Z minimal-versions
cargo ltest cargo ltest
git checkout Cargo.lock git checkout Cargo.lock
@ -105,11 +106,7 @@ install-dev-deps:
# install system development dependencies with homebrew # install system development dependencies with homebrew
install-dev-deps-homebrew: install-dev-deps-homebrew:
brew tap "rhysd/actionlint" "https://github.com/rhysd/actionlint" brew install help2man
brew install actionlint help2man shellcheck
actionlint:
SHELLCHECK_OPTS='-e SC2006 -e SC2002 -e SC2050' actionlint
# everyone's favorite animate paper clip # everyone's favorite animate paper clip
clippy: clippy:

View File

@ -1,3 +1,6 @@
#![allow(clippy::unknown_clippy_lints)]
#![allow(clippy::unnecessary_wraps)]
use crate::common::*; use crate::common::*;
use Function::*; use Function::*;

View File

@ -91,7 +91,7 @@ impl<'src> Justfile<'src> {
} }
let dotenv = if config.load_dotenv { let dotenv = if config.load_dotenv {
load_dotenv(&config, &self.settings, &search.working_directory)? load_dotenv(config, &self.settings, &search.working_directory)?
} else { } else {
BTreeMap::new() BTreeMap::new()
}; };
@ -129,7 +129,7 @@ impl<'src> Justfile<'src> {
binary, arguments, .. binary, arguments, ..
} => { } => {
let mut command = if config.shell_command { 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.arg(binary);
command command
} else { } else {
@ -168,7 +168,7 @@ impl<'src> Justfile<'src> {
print!("{}", value); print!("{}", value);
} else { } else {
return Err(Error::EvalUnknownVariable { return Err(Error::EvalUnknownVariable {
suggestion: self.suggest_variable(&variable), suggestion: self.suggest_variable(variable),
variable: variable.clone(), variable: variable.clone(),
}); });
} }
@ -261,7 +261,7 @@ impl<'src> Justfile<'src> {
let mut ran = BTreeSet::new(); let mut ran = BTreeSet::new();
for (recipe, arguments) in grouped { 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(()) Ok(())
@ -344,7 +344,7 @@ impl<'src> Justfile<'src> {
} }
let mut invocation = vec![recipe.name().to_owned()]; 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()); invocation.push(argument.to_owned());
} }

View File

@ -15,7 +15,7 @@ where
S: Serializer, S: Serializer,
K: Keyed<'src>, K: Keyed<'src>,
{ {
serializer.serialize_str(&keyed.key()) serializer.serialize_str(keyed.key())
} }
pub(crate) fn serialize_option<'src, S, K>( pub(crate) fn serialize_option<'src, S, K>(

View File

@ -174,7 +174,7 @@ impl<'src> Lexer<'src> {
/// Get current indentation /// Get current indentation
fn indentation(&self) -> &'src str { fn indentation(&self) -> &'src str {
self.indentation.last().cloned().unwrap() self.indentation.last().unwrap()
} }
/// Are we currently indented /// Are we currently indented

View File

@ -1,5 +1,6 @@
#![deny(clippy::all, clippy::pedantic)] #![deny(clippy::all, clippy::pedantic)]
#![allow( #![allow(
clippy::doc_markdown,
clippy::enum_glob_use, clippy::enum_glob_use,
clippy::if_not_else, clippy::if_not_else,
clippy::missing_errors_doc, clippy::missing_errors_doc,

View File

@ -15,7 +15,7 @@ pub(crate) fn load_dotenv(
} }
if let Some(path) = &config.dotenv_path { if let Some(path) = &config.dotenv_path {
return load_from_file(config, settings, &path); return load_from_file(config, settings, path);
} }
let filename = config let filename = config

View File

@ -56,6 +56,6 @@ impl<'src> Serialize for Name<'src> {
where where
S: Serializer, S: Serializer,
{ {
serializer.serialize_str(&self.lexeme()) serializer.serialize_str(self.lexeme())
} }
} }

View File

@ -10,8 +10,8 @@ pub(crate) trait Node<'src> {
impl<'src> Node<'src> for Ast<'src> { impl<'src> Node<'src> for Ast<'src> {
fn tree(&self) -> Tree<'src> { fn tree(&self) -> Tree<'src> {
Tree::atom("justfile") Tree::atom("justfile")
.extend(self.items.iter().map(|item| item.tree())) .extend(self.items.iter().map(Node::tree))
.extend(self.warnings.iter().map(|warning| warning.tree())) .extend(self.warnings.iter().map(Node::tree))
} }
} }
@ -179,7 +179,7 @@ impl<'src> Node<'src> for UnresolvedRecipe<'src> {
} }
if !self.body.is_empty() { 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 t
@ -200,7 +200,7 @@ impl<'src> Node<'src> for Parameter<'src> {
impl<'src> Node<'src> for Line<'src> { impl<'src> Node<'src> for Line<'src> {
fn tree(&self) -> Tree<'src> { fn tree(&self) -> Tree<'src> {
Tree::list(self.fragments.iter().map(|fragment| fragment.tree())) Tree::list(self.fragments.iter().map(Node::tree))
} }
} }

View File

@ -60,7 +60,7 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
expected: self expected: self
.expected .expected
.iter() .iter()
.cloned() .copied()
.filter(|kind| *kind != ByteOrderMark) .filter(|kind| *kind != ByteOrderMark)
.collect::<Vec<TokenKind>>(), .collect::<Vec<TokenKind>>(),
found: self.next()?.kind, found: self.next()?.kind,
@ -77,7 +77,7 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
fn rest(&self) -> impl Iterator<Item = Token<'src>> + 'tokens { fn rest(&self) -> impl Iterator<Item = Token<'src>> + 'tokens {
self.tokens[self.next..] self.tokens[self.next..]
.iter() .iter()
.cloned() .copied()
.filter(|token| token.kind != Whitespace) .filter(|token| token.kind != Whitespace)
} }
@ -654,10 +654,10 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
}; };
Ok(Parameter { Ok(Parameter {
name,
kind,
default, default,
export, export,
kind,
name,
}) })
} }
@ -777,7 +777,7 @@ impl<'tokens, 'src> Parser<'tokens, 'src> {
self.expect(BracketR)?; self.expect(BracketR)?;
Ok(Set { Ok(Set {
value: Setting::Shell(setting::Shell { command, arguments }), value: Setting::Shell(setting::Shell { arguments, command }),
name, name,
}) })
} else { } else {

View File

@ -87,7 +87,7 @@ impl<'src: 'run, 'run> RecipeResolver<'src, 'run> {
if let Some(resolved) = self.resolved_recipes.get(name) { if let Some(resolved) = self.resolved_recipes.get(name) {
// dependency already resolved // dependency already resolved
dependencies.push(Rc::clone(&resolved)); dependencies.push(Rc::clone(resolved));
} else if stack.contains(&name) { } else if stack.contains(&name) {
let first = stack[0]; let first = stack[0];
stack.push(first); stack.push(first);
@ -97,7 +97,7 @@ impl<'src: 'run, 'run> RecipeResolver<'src, 'run> {
circle: stack circle: stack
.iter() .iter()
.skip_while(|name| **name != dependency.recipe.lexeme()) .skip_while(|name| **name != dependency.recipe.lexeme())
.cloned() .copied()
.collect(), .collect(),
}), }),
); );

View File

@ -46,7 +46,7 @@ impl<'src, 'run> Scope<'src, 'run> {
} }
pub(crate) fn names(&self) -> impl Iterator<Item = &str> { 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>> { pub(crate) fn parent(&self) -> Option<&'run Scope<'src, 'run>> {

View File

@ -18,7 +18,7 @@ impl Search {
) -> SearchResult<Self> { ) -> SearchResult<Self> {
match search_config { match search_config {
SearchConfig::FromInvocationDirectory => { SearchConfig::FromInvocationDirectory => {
let justfile = Self::justfile(&invocation_directory)?; let justfile = Self::justfile(invocation_directory)?;
let working_directory = Self::working_directory_from_justfile(&justfile)?; let working_directory = Self::working_directory_from_justfile(&justfile)?;
@ -68,7 +68,7 @@ impl Search {
) -> SearchResult<Self> { ) -> SearchResult<Self> {
match search_config { match search_config {
SearchConfig::FromInvocationDirectory => { 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); let justfile = working_directory.join(DEFAULT_JUSTFILE_NAME);
@ -174,7 +174,7 @@ impl Search {
io_error, io_error,
directory: directory.to_owned(), 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 { if entry.file_name() == project_root_child {
return Ok(directory.to_owned()); return Ok(directory.to_owned());
} }

View File

@ -46,7 +46,7 @@ impl Subcommand {
Self::changelog(); Self::changelog();
return Ok(()); return Ok(());
} }
Completions { shell } => return Self::completions(&shell), Completions { shell } => return Self::completions(shell),
Init => return Self::init(config), Init => return Self::init(config),
_ => {} _ => {}
} }
@ -59,7 +59,7 @@ impl Subcommand {
let src = loader.load(&search.justfile)?; let src = loader.load(&search.justfile)?;
let tokens = Lexer::lex(&src)?; let tokens = Lexer::lex(src)?;
let ast = Parser::parse(&tokens)?; let ast = Parser::parse(&tokens)?;
let justfile = Analyzer::analyze(ast.clone())?; let justfile = Analyzer::analyze(ast.clone())?;
@ -74,16 +74,16 @@ impl Subcommand {
Self::choose(config, justfile, &search, overrides, chooser.as_deref())?; Self::choose(config, justfile, &search, overrides, chooser.as_deref())?;
} }
Command { overrides, .. } | Evaluate { overrides, .. } => { Command { overrides, .. } | Evaluate { overrides, .. } => {
justfile.run(config, &search, overrides, &[])? justfile.run(config, &search, overrides, &[])?;
} }
Dump => Self::dump(config, ast, justfile)?, 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), List => Self::list(config, justfile),
Run { Run {
arguments, arguments,
overrides, overrides,
} => justfile.run(config, &search, overrides, arguments)?, } => 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), Summary => Self::summary(config, justfile),
Variables => Self::variables(justfile), Variables => Self::variables(justfile),
Changelog | Completions { .. } | Edit | Init => unreachable!(), Changelog | Completions { .. } | Edit | Init => unreachable!(),
@ -107,7 +107,7 @@ impl Subcommand {
.public_recipes(config.unsorted) .public_recipes(config.unsorted)
.iter() .iter()
.filter(|recipe| recipe.min_arguments() == 0) .filter(|recipe| recipe.min_arguments() == 0)
.cloned() .copied()
.collect::<Vec<&Recipe<Dependency>>>(); .collect::<Vec<&Recipe<Dependency>>>();
if recipes.is_empty() { if recipes.is_empty() {
@ -121,7 +121,7 @@ impl Subcommand {
let result = justfile let result = justfile
.settings .settings
.shell_command(&config) .shell_command(config)
.arg(&chooser) .arg(&chooser)
.current_dir(&search.working_directory) .current_dir(&search.working_directory)
.stdin(Stdio::piped()) .stdin(Stdio::piped())
@ -132,8 +132,8 @@ impl Subcommand {
Ok(child) => child, Ok(child) => child,
Err(io_error) => { Err(io_error) => {
return Err(Error::ChooserInvoke { return Err(Error::ChooserInvoke {
shell_binary: justfile.settings.shell_binary(&config).to_owned(), shell_binary: justfile.settings.shell_binary(config).to_owned(),
shell_arguments: justfile.settings.shell_arguments(&config).join(" "), shell_arguments: justfile.settings.shell_arguments(config).join(" "),
chooser, chooser,
io_error, io_error,
}); });
@ -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(); let doc_color = config.color.stdout().doc();
print!("{}", config.list_heading); print!("{}", config.list_heading);
@ -392,7 +392,7 @@ impl Subcommand {
doc_color.paint("#"), doc_color.paint("#"),
doc_color.paint(doc), doc_color.paint(doc),
padding = max_line_width 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))
); );
}; };

View File

@ -87,11 +87,7 @@ impl Recipe {
private: recipe.private, private: recipe.private,
shebang: recipe.shebang, shebang: recipe.shebang,
quiet: recipe.quiet, quiet: recipe.quiet,
dependencies: recipe dependencies: recipe.dependencies.iter().map(Dependency::new).collect(),
.dependencies
.iter()
.map(|dependency| Dependency::new(dependency))
.collect(),
lines: recipe.body.iter().map(Line::new).collect(), lines: recipe.body.iter().map(Line::new).collect(),
parameters: recipe.parameters.iter().map(Parameter::new).collect(), parameters: recipe.parameters.iter().map(Parameter::new).collect(),
aliases, aliases,

View File

@ -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 IntoIter = btree_map::Iter<'table, &'table str, V>;
type Item = (&'table &'table str, &'table V); type Item = (&'table &'table str, &'table V);
#[must_use]
fn into_iter(self) -> btree_map::Iter<'table, &'table str, V> { fn into_iter(self) -> btree_map::Iter<'table, &'table str, V> {
self.map.iter() self.map.iter()
} }

View File

@ -14,7 +14,7 @@ pub fn unindent(text: &str) -> String {
let common_indentation = lines let common_indentation = lines
.iter() .iter()
.filter(|line| !blank(line)) .filter(|line| !blank(line))
.cloned() .copied()
.map(indentation) .map(indentation)
.fold( .fold(
None, None,

View File

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