Skip to content

Commit

Permalink
Add additional continuous integration checks (#574)
Browse files Browse the repository at this point in the history
Add GitHub Actions checks:

- Clippy is placated
- Rustfmt doesn't produce any changes
- Shell completion scripts are current
  • Loading branch information
casey authored Jan 15, 2020
1 parent 85e8015 commit ed991cb
Show file tree
Hide file tree
Showing 24 changed files with 173 additions and 106 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Rust

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: clippy, rustfmt
override: true
- name: Version
run: |
rustup --version
cargo --version
cargo clippy --version
- name: Lint
run: cargo clippy
- name: Format
run: cargo fmt -- --check
- name: Completion Scripts
run: |
for script in completions/*; do
shell=${script##*.}
cargo run -- --completions $shell > $script
done
git diff --no-ext-diff --quiet --exit-code
6 changes: 5 additions & 1 deletion man/just.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.11.
.TH JUST "1" "December 2019" "just 0.5.4" "JUST MANUAL"
.TH JUST "1" "January 2020" "just 0.5.4" "JUST MANUAL"
.SH NAME
just \- save and run commands
.SH DESCRIPTION
Expand Down Expand Up @@ -57,6 +57,10 @@ Print version information
.TP
Print colorful output [default: auto]
[possible values: auto, always, never]
.HP
\fB\-\-completions\fR <SHELL>
.IP
Print shell completion script for <SHELL> [possible values: zsh, bash, fish, powershell, elvish]
.TP
\fB\-f\fR, \fB\-\-justfile\fR <JUSTFILE>
Use <JUSTFILE> as justfile.
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
tab_spaces = 2
max_width = 100
max_width = 100
4 changes: 2 additions & 2 deletions src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<'src> Analyzer<'src> {

let mut settings = Settings::new();

for (_, set) in self.sets.into_iter() {
for (_, set) in self.sets {
match set.value {
Setting::Shell(shell) => {
assert!(settings.shell.is_none());
Expand Down Expand Up @@ -191,7 +191,7 @@ impl<'src> Analyzer<'src> {

// Make sure the target recipe exists
match recipes.get(alias.target.lexeme()) {
Some(target) => Ok(alias.resolve(target.clone())),
Some(target) => Ok(alias.resolve(Rc::clone(target))),
None => Err(token.error(UnknownAliasTarget {
alias: alias.name.lexeme(),
target: alias.target.lexeme(),
Expand Down
52 changes: 26 additions & 26 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ pub(crate) struct Color {
}

impl Color {
fn restyle(self, style: Style) -> Color {
Color { style, ..self }
fn restyle(self, style: Style) -> Self {
Self { style, ..self }
}

fn redirect(self, stream: Stream) -> Color {
Color {
fn redirect(self, stream: Stream) -> Self {
Self {
atty: atty::is(stream),
..self
}
Expand All @@ -31,76 +31,76 @@ impl Color {
}
}

pub(crate) fn fmt(fmt: &Formatter) -> Color {
pub(crate) fn fmt(fmt: &Formatter) -> Self {
if fmt.alternate() {
Color::always()
Self::always()
} else {
Color::never()
Self::never()
}
}

pub(crate) fn auto() -> Color {
Color {
pub(crate) fn auto() -> Self {
Self {
use_color: UseColor::Auto,
..default()
}
}

pub(crate) fn always() -> Color {
Color {
pub(crate) fn always() -> Self {
Self {
use_color: UseColor::Always,
..default()
}
}

pub(crate) fn never() -> Color {
Color {
pub(crate) fn never() -> Self {
Self {
use_color: UseColor::Never,
..default()
}
}

pub(crate) fn stderr(self) -> Color {
pub(crate) fn stderr(self) -> Self {
self.redirect(Stream::Stderr)
}

pub(crate) fn stdout(self) -> Color {
pub(crate) fn stdout(self) -> Self {
self.redirect(Stream::Stdout)
}

pub(crate) fn doc(self) -> Color {
pub(crate) fn doc(self) -> Self {
self.restyle(Style::new().fg(Blue))
}

pub(crate) fn error(self) -> Color {
pub(crate) fn error(self) -> Self {
self.restyle(Style::new().fg(Red).bold())
}

pub(crate) fn warning(self) -> Color {
pub(crate) fn warning(self) -> Self {
self.restyle(Style::new().fg(Yellow).bold())
}

pub(crate) fn banner(self) -> Color {
pub(crate) fn banner(self) -> Self {
self.restyle(Style::new().fg(Cyan).bold())
}

pub(crate) fn command(self) -> Color {
pub(crate) fn command(self) -> Self {
self.restyle(Style::new().bold())
}

pub(crate) fn parameter(self) -> Color {
pub(crate) fn parameter(self) -> Self {
self.restyle(Style::new().fg(Cyan))
}

pub(crate) fn message(self) -> Color {
pub(crate) fn message(self) -> Self {
self.restyle(Style::new().bold())
}

pub(crate) fn annotation(self) -> Color {
pub(crate) fn annotation(self) -> Self {
self.restyle(Style::new().fg(Purple))
}

pub(crate) fn string(self) -> Color {
pub(crate) fn string(self) -> Self {
self.restyle(Style::new().fg(Green))
}

Expand All @@ -126,8 +126,8 @@ impl Color {
}

impl Default for Color {
fn default() -> Color {
Color {
fn default() -> Self {
Self {
use_color: UseColor::Auto,
atty: false,
style: Style::new(),
Expand Down
20 changes: 10 additions & 10 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl Config {
}
}

pub(crate) fn from_matches(matches: &ArgMatches) -> ConfigResult<Config> {
pub(crate) fn from_matches(matches: &ArgMatches) -> ConfigResult<Self> {
let invocation_directory = env::current_dir().context(config_error::CurrentDir)?;

let verbosity = Verbosity::from_flag_occurrences(matches.occurrences_of(arg::VERBOSE));
Expand Down Expand Up @@ -368,7 +368,7 @@ impl Config {
|| matches.occurrences_of(arg::SHELL) > 0
|| matches.occurrences_of(arg::SHELL_ARG) > 0;

Ok(Config {
Ok(Self {
dry_run: matches.is_present(arg::DRY_RUN),
highlight: !matches.is_present(arg::NO_HIGHLIGHT),
quiet: matches.is_present(arg::QUIET),
Expand All @@ -394,7 +394,7 @@ impl Config {
Search::find(&self.search_config, &self.invocation_directory).eprint(self.color)?;

if self.subcommand == Edit {
return self.edit(&search);
return Self::edit(&search);
}

let src = fs::read_to_string(&search.justfile)
Expand All @@ -415,16 +415,16 @@ impl Config {
}

match &self.subcommand {
Dump => self.dump(justfile),
Dump => Self::dump(justfile),
Completions { shell } => Self::completions(&shell),
Evaluate { overrides } => self.run(justfile, &search, overrides, &Vec::new()),
Run {
arguments,
overrides,
} => self.run(justfile, &search, overrides, arguments),
List => self.list(justfile),
Show { ref name } => self.show(&name, justfile),
Summary => self.summary(justfile),
Show { ref name } => Self::show(&name, justfile),
Summary => Self::summary(justfile),
Edit | Init => unreachable!(),
}
}
Expand All @@ -439,12 +439,12 @@ impl Config {
Ok(())
}

fn dump(&self, justfile: Justfile) -> Result<(), i32> {
fn dump(justfile: Justfile) -> Result<(), i32> {
println!("{}", justfile);
Ok(())
}

pub(crate) fn edit(&self, search: &Search) -> Result<(), i32> {
pub(crate) fn edit(search: &Search) -> Result<(), i32> {
let editor = env::var_os("VISUAL")
.or_else(|| env::var_os("EDITOR"))
.unwrap_or_else(|| "vim".into());
Expand Down Expand Up @@ -601,7 +601,7 @@ impl Config {
}
}

fn show(&self, name: &str, justfile: Justfile) -> Result<(), i32> {
fn show(name: &str, justfile: Justfile) -> Result<(), i32> {
if let Some(alias) = justfile.get_alias(name) {
let recipe = justfile.get_recipe(alias.target.name.lexeme()).unwrap();
println!("{}", alias);
Expand All @@ -619,7 +619,7 @@ impl Config {
}
}

fn summary(&self, justfile: Justfile) -> Result<(), i32> {
fn summary(justfile: Justfile) -> Result<(), i32> {
if justfile.count() == 0 {
eprintln!("Justfile contains no recipes.");
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/config_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ pub(crate) enum ConfigError {
}

impl ConfigError {
pub(crate) fn internal(message: impl Into<String>) -> ConfigError {
ConfigError::Internal {
pub(crate) fn internal(message: impl Into<String>) -> Self {
Self::Internal {
message: message.into(),
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/enclosure.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// `Self` cannot be used where type takes generic arguments
#![allow(clippy::use_self)]

use crate::common::*;

pub struct Enclosure<T: Display> {
Expand All @@ -7,7 +10,7 @@ pub struct Enclosure<T: Display> {

impl<T: Display> Enclosure<T> {
pub fn tick(value: T) -> Enclosure<T> {
Enclosure {
Self {
enclosure: "`",
value,
}
Expand Down
16 changes: 8 additions & 8 deletions src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ impl<'src, 'run> Evaluator<'src, 'run> {
}
}
Expression::Call { thunk } => {
use Thunk::*;

let context = FunctionContext {
dotenv: self.dotenv,
invocation_directory: &self.config.invocation_directory,
search: self.search,
};

use Thunk::*;
match thunk {
Nullary { name, function, .. } => {
function(&context).map_err(|message| RuntimeError::FunctionCall {
Expand Down Expand Up @@ -183,13 +184,12 @@ impl<'src, 'run> Evaluator<'src, 'run> {
let mut rest = arguments;
for parameter in parameters {
let value = if rest.is_empty() {
match parameter.default {
Some(ref default) => evaluator.evaluate_expression(default)?,
None => {
return Err(RuntimeError::Internal {
message: "missing parameter without default".to_string(),
});
}
if let Some(ref default) = parameter.default {
evaluator.evaluate_expression(default)?
} else {
return Err(RuntimeError::Internal {
message: "missing parameter without default".to_string(),
});
}
} else if parameter.variadic {
let value = rest.to_vec().join(" ");
Expand Down
3 changes: 2 additions & 1 deletion src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ fn env_var_or_default(
key: &str,
default: &str,
) -> Result<String, String> {
use std::env::VarError::*;

if let Some(value) = context.dotenv.get(key) {
return Ok(value.clone());
}

use std::env::VarError::*;
match env::var(key) {
Err(NotPresent) => Ok(default.to_string()),
Err(NotUnicode(os_string)) => Err(format!(
Expand Down
4 changes: 2 additions & 2 deletions src/interrupt_guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::common::*;
pub(crate) struct InterruptGuard;

impl InterruptGuard {
pub(crate) fn new() -> InterruptGuard {
pub(crate) fn new() -> Self {
InterruptHandler::instance().block();
InterruptGuard
Self
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/interrupt_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ pub(crate) struct InterruptHandler {

impl InterruptHandler {
pub(crate) fn install() -> Result<(), ctrlc::Error> {
ctrlc::set_handler(|| InterruptHandler::instance().interrupt())
ctrlc::set_handler(|| Self::instance().interrupt())
}

pub(crate) fn instance() -> MutexGuard<'static, InterruptHandler> {
pub(crate) fn instance() -> MutexGuard<'static, Self> {
lazy_static! {
static ref INSTANCE: Mutex<InterruptHandler> = Mutex::new(InterruptHandler::new());
}
Expand All @@ -29,8 +29,8 @@ impl InterruptHandler {
}
}

fn new() -> InterruptHandler {
InterruptHandler {
fn new() -> Self {
Self {
blocks: 0,
interrupted: false,
}
Expand Down
Loading

0 comments on commit ed991cb

Please sign in to comment.