Ran clippy and fixed issues. I <3 clippy!
This commit is contained in:
parent
8d8f38b3d8
commit
f74ece6629
13
justfile
13
justfile
@ -7,12 +7,21 @@ test-quine:
|
|||||||
backtrace:
|
backtrace:
|
||||||
RUST_BACKTRACE=1 cargo test --lib
|
RUST_BACKTRACE=1 cargo test --lib
|
||||||
|
|
||||||
publish:
|
publish: clippy
|
||||||
# make sure version is up to date
|
# make sure version is up to date
|
||||||
grep 'version("'`sed -En 's/version = "([^"]+)"/\1/p' Cargo.toml`'")' src/app.rs
|
grep 'version("'`sed -En 's/version = "([^"]+)"/\1/p' Cargo.toml`'")' src/app.rs
|
||||||
git push github master
|
git push github master:master
|
||||||
cargo publish
|
cargo publish
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
rustup run nightly cargo clippy
|
||||||
|
|
||||||
|
install-clippy:
|
||||||
|
rustup run nightly cargo install clippy
|
||||||
|
|
||||||
|
install-nightly:
|
||||||
|
rustup install nightly
|
||||||
|
|
||||||
# make a quine, compile it, and verify it
|
# make a quine, compile it, and verify it
|
||||||
quine: create
|
quine: create
|
||||||
cc tmp/gen0.c -o tmp/gen0
|
cc tmp/gen0.c -o tmp/gen0
|
||||||
|
11
notes
11
notes
@ -9,16 +9,20 @@ notes
|
|||||||
although maybe only after a '--': j build -- a=hello
|
although maybe only after a '--': j build -- a=hello
|
||||||
- parse lines into {{fragments}} and allow argument substitution
|
- parse lines into {{fragments}} and allow argument substitution
|
||||||
- change error messages to underline problem token
|
- change error messages to underline problem token
|
||||||
- should i use // comments, since that's what's used in rust?
|
|
||||||
- allow calling recipes in a justfile in a different directory:
|
- allow calling recipes in a justfile in a different directory:
|
||||||
- just ../foo # ../justfile:foo
|
- just ../foo # ../justfile:foo
|
||||||
- just xyz/foo # xyz/justfile:foo
|
- just xyz/foo # xyz/justfile:foo
|
||||||
- just xyz/ # xyz/justfile:DEFAULT
|
- just xyz/ # xyz/justfile:DEFAULT
|
||||||
|
- this is going to be hard. should a single recipe with a slash
|
||||||
|
require that all recipes have slashes?
|
||||||
|
or should non-slash recipes still run in this directory?
|
||||||
|
will need to change things a great deal
|
||||||
- assignment
|
- assignment
|
||||||
. export environment variables
|
. export environment variables
|
||||||
. no barewords
|
. no barewords
|
||||||
- indentation is line continuation
|
- indentation is line continuation
|
||||||
- static errors when variables are missing {{}}, even if recipe isn't run
|
- static errors when variables are missing {{}}, even if recipe isn't run
|
||||||
|
- write some tests to test the binary itself and all command line flags
|
||||||
|
|
||||||
- change name back to 'just'
|
- change name back to 'just'
|
||||||
. suggest j as alias
|
. suggest j as alias
|
||||||
@ -58,8 +62,3 @@ later:
|
|||||||
may be nice to allow all recipes in a given langauge to share
|
may be nice to allow all recipes in a given langauge to share
|
||||||
functions, variables, etc. could have a "prelude" recipe
|
functions, variables, etc. could have a "prelude" recipe
|
||||||
which was included as a prefix to other recipes
|
which was included as a prefix to other recipes
|
||||||
- windows support: currently calling 'sh', which won't work on windows
|
|
||||||
the answer will probably be to write a 'sh' clone and to only
|
|
||||||
call binaries from cargo
|
|
||||||
- run recipes asyncronously
|
|
||||||
- lint with clippy once it runs on stable
|
|
||||||
|
39
src/lib.rs
39
src/lib.rs
@ -72,7 +72,7 @@ enum Fragment<'a> {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn error_from_signal<'a>(recipe: &'a str, exit_status: process::ExitStatus) -> RunError<'a> {
|
fn error_from_signal(recipe: &str, exit_status: process::ExitStatus) -> RunError {
|
||||||
use std::os::unix::process::ExitStatusExt;
|
use std::os::unix::process::ExitStatusExt;
|
||||||
match exit_status.signal() {
|
match exit_status.signal() {
|
||||||
Some(signal) => RunError::Signal{recipe: recipe, signal: signal},
|
Some(signal) => RunError::Signal{recipe: recipe, signal: signal},
|
||||||
@ -81,7 +81,7 @@ fn error_from_signal<'a>(recipe: &'a str, exit_status: process::ExitStatus) -> R
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn error_from_signal<'a>(recipe: &'a str, exit_status: process::ExitStatus) -> RunError<'a> {
|
fn error_from_signal(recipe: &str, exit_status: process::ExitStatus) -> RunError {
|
||||||
RunError::UnknownFailure{recipe: recipe}
|
RunError::UnknownFailure{recipe: recipe}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ impl<'a> Recipe<'a> {
|
|||||||
} else {
|
} else {
|
||||||
for command in &self.lines {
|
for command in &self.lines {
|
||||||
let mut command = *command;
|
let mut command = *command;
|
||||||
if !command.starts_with("@") {
|
if !command.starts_with('@') {
|
||||||
warn!("{}", command);
|
warn!("{}", command);
|
||||||
} else {
|
} else {
|
||||||
command = &command[1..];
|
command = &command[1..];
|
||||||
@ -369,7 +369,7 @@ struct Justfile<'a> {
|
|||||||
impl<'a> Justfile<'a> {
|
impl<'a> Justfile<'a> {
|
||||||
fn first(&self) -> Option<&'a str> {
|
fn first(&self) -> Option<&'a str> {
|
||||||
let mut first: Option<&Recipe<'a>> = None;
|
let mut first: Option<&Recipe<'a>> = None;
|
||||||
for (_, recipe) in self.recipes.iter() {
|
for recipe in self.recipes.values() {
|
||||||
if let Some(first_recipe) = first {
|
if let Some(first_recipe) = first {
|
||||||
if recipe.line_number < first_recipe.line_number {
|
if recipe.line_number < first_recipe.line_number {
|
||||||
first = Some(recipe)
|
first = Some(recipe)
|
||||||
@ -409,7 +409,7 @@ impl<'a> Justfile<'a> {
|
|||||||
missing.push(*recipe);
|
missing.push(*recipe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if missing.len() > 0 {
|
if !missing.is_empty() {
|
||||||
return Err(RunError::UnknownRecipes{recipes: missing});
|
return Err(RunError::UnknownRecipes{recipes: missing});
|
||||||
}
|
}
|
||||||
let recipes = names.iter().map(|name| self.recipes.get(name).unwrap()).collect::<Vec<_>>();
|
let recipes = names.iter().map(|name| self.recipes.get(name).unwrap()).collect::<Vec<_>>();
|
||||||
@ -437,31 +437,31 @@ enum RunError<'a> {
|
|||||||
|
|
||||||
impl<'a> Display for RunError<'a> {
|
impl<'a> Display for RunError<'a> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
match self {
|
match *self {
|
||||||
&RunError::UnknownRecipes{ref recipes} => {
|
RunError::UnknownRecipes{ref recipes} => {
|
||||||
if recipes.len() == 1 {
|
if recipes.len() == 1 {
|
||||||
try!(write!(f, "Justfile does not contain recipe: {}", recipes[0]));
|
try!(write!(f, "Justfile does not contain recipe: {}", recipes[0]));
|
||||||
} else {
|
} else {
|
||||||
try!(write!(f, "Justfile does not contain recipes: {}", recipes.join(" ")));
|
try!(write!(f, "Justfile does not contain recipes: {}", recipes.join(" ")));
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
&RunError::Code{recipe, code} => {
|
RunError::Code{recipe, code} => {
|
||||||
try!(write!(f, "Recipe \"{}\" failed with code {}", recipe, code));
|
try!(write!(f, "Recipe \"{}\" failed with code {}", recipe, code));
|
||||||
},
|
},
|
||||||
&RunError::Signal{recipe, signal} => {
|
RunError::Signal{recipe, signal} => {
|
||||||
try!(write!(f, "Recipe \"{}\" wast terminated by signal {}", recipe, signal));
|
try!(write!(f, "Recipe \"{}\" wast terminated by signal {}", recipe, signal));
|
||||||
}
|
}
|
||||||
&RunError::UnknownFailure{recipe} => {
|
RunError::UnknownFailure{recipe} => {
|
||||||
try!(write!(f, "Recipe \"{}\" failed for an unknown reason", recipe));
|
try!(write!(f, "Recipe \"{}\" failed for an unknown reason", recipe));
|
||||||
},
|
},
|
||||||
&RunError::IoError{recipe, ref io_error} => {
|
RunError::IoError{recipe, ref io_error} => {
|
||||||
try!(match io_error.kind() {
|
try!(match io_error.kind() {
|
||||||
io::ErrorKind::NotFound => write!(f, "Recipe \"{}\" could not be run because j could not find `sh` the command:\n{}", recipe, io_error),
|
io::ErrorKind::NotFound => write!(f, "Recipe \"{}\" could not be run because j could not find `sh` the command:\n{}", recipe, io_error),
|
||||||
io::ErrorKind::PermissionDenied => write!(f, "Recipe \"{}\" could not be run because j could not run `sh`:\n{}", recipe, io_error),
|
io::ErrorKind::PermissionDenied => write!(f, "Recipe \"{}\" could not be run because j could not run `sh`:\n{}", recipe, io_error),
|
||||||
_ => write!(f, "Recipe \"{}\" could not be run because of an IO error while launching the `sh`:\n{}", recipe, io_error),
|
_ => write!(f, "Recipe \"{}\" could not be run because of an IO error while launching the `sh`:\n{}", recipe, io_error),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
&RunError::TmpdirIoError{recipe, ref io_error} =>
|
RunError::TmpdirIoError{recipe, ref io_error} =>
|
||||||
try!(write!(f, "Recipe \"{}\" could not be run because of an IO error while trying to create a temporary directory or write a file to that directory`:\n{}", recipe, io_error)),
|
try!(write!(f, "Recipe \"{}\" could not be run because of an IO error while trying to create a temporary directory or write a file to that directory`:\n{}", recipe, io_error)),
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -572,15 +572,12 @@ fn tokenize(text: &str) -> Result<Vec<Token>, Error> {
|
|||||||
if column == 0 {
|
if column == 0 {
|
||||||
if let Some(class) = match (indent, indentation(rest)) {
|
if let Some(class) = match (indent, indentation(rest)) {
|
||||||
// ignore: was no indentation and there still isn't
|
// ignore: was no indentation and there still isn't
|
||||||
(None, Some("")) => {
|
// or current line is blank
|
||||||
None
|
(None, Some("")) | (_, None) => {
|
||||||
}
|
|
||||||
// ignore: current line is blank
|
|
||||||
(_, None) => {
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
// indent: was no indentation, now there is
|
// indent: was no indentation, now there is
|
||||||
(None, Some(current @ _)) => {
|
(None, Some(current)) => {
|
||||||
if mixed_whitespace(current) {
|
if mixed_whitespace(current) {
|
||||||
return error!(ErrorKind::MixedLeadingWhitespace{whitespace: current})
|
return error!(ErrorKind::MixedLeadingWhitespace{whitespace: current})
|
||||||
}
|
}
|
||||||
@ -688,7 +685,7 @@ fn tokenize(text: &str) -> Result<Vec<Token>, Error> {
|
|||||||
Ok(tokens)
|
Ok(tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse<'a>(text: &'a str) -> Result<Justfile, Error> {
|
fn parse(text: &str) -> Result<Justfile, Error> {
|
||||||
let tokens = try!(tokenize(text));
|
let tokens = try!(tokenize(text));
|
||||||
let filtered: Vec<_> = tokens.into_iter().filter(|token| token.class != Comment).collect();
|
let filtered: Vec<_> = tokens.into_iter().filter(|token| token.class != Comment).collect();
|
||||||
if let Some(token) = filtered.iter().find(|token| {
|
if let Some(token) = filtered.iter().find(|token| {
|
||||||
@ -790,11 +787,11 @@ impl<'a> Parser<'a> {
|
|||||||
if self.accepted(Indent) {
|
if self.accepted(Indent) {
|
||||||
while !self.peek(Dedent) {
|
while !self.peek(Dedent) {
|
||||||
if let Some(line) = self.accept(Line) {
|
if let Some(line) = self.accept(Line) {
|
||||||
if lines.len() == 0 {
|
if lines.is_empty() {
|
||||||
if line.lexeme.starts_with("#!") {
|
if line.lexeme.starts_with("#!") {
|
||||||
shebang = true;
|
shebang = true;
|
||||||
}
|
}
|
||||||
} else if !shebang && (line.lexeme.starts_with(" ") || line.lexeme.starts_with("\t")) {
|
} else if !shebang && (line.lexeme.starts_with(' ') || line.lexeme.starts_with('\t')) {
|
||||||
return Err(line.error(ErrorKind::ExtraLeadingWhitespace));
|
return Err(line.error(ErrorKind::ExtraLeadingWhitespace));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user