Skip to content

Commit

Permalink
Use unstable rustfmt configuration options (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Feb 11, 2020
1 parent aceee3e commit 3ec7dea
Show file tree
Hide file tree
Showing 62 changed files with 569 additions and 550 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Cargo.lock linguist-generated diff=nodiff
* -text
11 changes: 9 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v1
- name: Install
- name: Install Main Toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -42,8 +42,15 @@ jobs:
- name: Lint
if: matrix.os != 'windows-latest'
run: cargo run lint
- name: Install Rustfmt Toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
target: ${{ matrix.target }}
profile: minimal
components: rustfmt
- name: Format
run: cargo fmt --all -- --check
run: cargo +nightly fmt --all -- --check
- name: Completion Scripts
if: matrix.os != 'windows-latest'
run: |
Expand Down
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ build:
check:
cargo check

fmt:
cargo +nightly fmt --all

watch +COMMAND='test':
cargo watch --clear --exec "{{COMMAND}}"

Expand Down
24 changes: 22 additions & 2 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
tab_spaces = 2
max_width = 100
comment_width = 70
edition = "2018"
error_on_line_overflow = true
error_on_unformatted = true
format_code_in_doc_comments = true
format_macro_bodies = true
format_strings = true
match_arm_blocks = false
match_block_trailing_comma = true
max_width = 100
merge_imports = true
newline_style = "Unix"
normalize_comments = true
overflow_delimited_expr = true
reorder_impl_items = true
required_version = "1.4.11"
struct_field_align_threshold = 20
tab_spaces = 2
unstable_features = true
use_field_init_shorthand = true
use_try_shorthand = true
wrap_comments = true
2 changes: 1 addition & 1 deletion src/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::common::*;
/// An alias, e.g. `name := target`
#[derive(Debug, PartialEq)]
pub(crate) struct Alias<'src, T = Rc<Recipe<'src>>> {
pub(crate) name: Name<'src>,
pub(crate) name: Name<'src>,
pub(crate) target: T,
}

Expand Down
32 changes: 16 additions & 16 deletions src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use crate::common::*;
use CompilationErrorKind::*;

pub(crate) struct Analyzer<'src> {
recipes: Table<'src, UnresolvedRecipe<'src>>,
recipes: Table<'src, UnresolvedRecipe<'src>>,
assignments: Table<'src, Assignment<'src>>,
aliases: Table<'src, Alias<'src, Name<'src>>>,
sets: Table<'src, Set<'src>>,
aliases: Table<'src, Alias<'src, Name<'src>>>,
sets: Table<'src, Set<'src>>,
}

impl<'src> Analyzer<'src> {
Expand All @@ -18,10 +18,10 @@ impl<'src> Analyzer<'src> {

pub(crate) fn new() -> Analyzer<'src> {
Analyzer {
recipes: empty(),
recipes: empty(),
assignments: empty(),
aliases: empty(),
sets: empty(),
aliases: empty(),
sets: empty(),
}
}

Expand All @@ -34,19 +34,19 @@ impl<'src> Analyzer<'src> {
Item::Alias(alias) => {
self.analyze_alias(&alias)?;
self.aliases.insert(alias);
}
},
Item::Assignment(assignment) => {
self.analyze_assignment(&assignment)?;
self.assignments.insert(assignment);
}
},
Item::Recipe(recipe) => {
self.analyze_recipe(&recipe)?;
self.recipes.insert(recipe);
}
},
Item::Set(set) => {
self.analyze_set(&set)?;
self.sets.insert(set);
}
},
}
}

Expand Down Expand Up @@ -78,7 +78,7 @@ impl<'src> Analyzer<'src> {
Setting::Shell(shell) => {
assert!(settings.shell.is_none());
settings.shell = Some(shell);
}
},
}
}

Expand All @@ -95,7 +95,7 @@ impl<'src> Analyzer<'src> {
if let Some(original) = self.recipes.get(recipe.name.lexeme()) {
return Err(recipe.name.token().error(DuplicateRecipe {
recipe: original.name(),
first: original.line_number(),
first: original.line_number(),
}));
}

Expand All @@ -105,7 +105,7 @@ impl<'src> Analyzer<'src> {
for parameter in &recipe.parameters {
if parameters.contains(parameter.name.lexeme()) {
return Err(parameter.name.token().error(DuplicateParameter {
recipe: recipe.name.lexeme(),
recipe: recipe.name.lexeme(),
parameter: parameter.name.lexeme(),
}));
}
Expand Down Expand Up @@ -169,7 +169,7 @@ impl<'src> Analyzer<'src> {
if let Some(original) = self.sets.get(set.name.lexeme()) {
return Err(set.name.error(DuplicateSet {
setting: original.name.lexeme(),
first: original.name.line,
first: original.name.line,
}));
}

Expand All @@ -184,7 +184,7 @@ impl<'src> Analyzer<'src> {
// Make sure the alias doesn't conflict with any recipe
if let Some(recipe) = recipes.get(alias.name.lexeme()) {
return Err(token.error(AliasShadowsRecipe {
alias: alias.name.lexeme(),
alias: alias.name.lexeme(),
recipe_line: recipe.line_number(),
}));
}
Expand All @@ -193,7 +193,7 @@ impl<'src> Analyzer<'src> {
match recipes.get(alias.target.lexeme()) {
Some(target) => Ok(alias.resolve(Rc::clone(target))),
None => Err(token.error(UnknownAliasTarget {
alias: alias.name.lexeme(),
alias: alias.name.lexeme(),
target: alias.target.lexeme(),
})),
}
Expand Down
18 changes: 9 additions & 9 deletions src/assignment_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use CompilationErrorKind::*;

pub(crate) struct AssignmentResolver<'src: 'run, 'run> {
assignments: &'run Table<'src, Assignment<'src>>,
stack: Vec<&'src str>,
seen: BTreeSet<&'src str>,
evaluated: BTreeSet<&'src str>,
stack: Vec<&'src str>,
seen: BTreeSet<&'src str>,
evaluated: BTreeSet<&'src str>,
}

impl<'src: 'run, 'run> AssignmentResolver<'src, 'run> {
Expand Down Expand Up @@ -41,12 +41,12 @@ impl<'src: 'run, 'run> AssignmentResolver<'src, 'run> {
} else {
let message = format!("attempted to resolve unknown assignment `{}`", name);
let token = Token {
src: "",
src: "",
offset: 0,
line: 0,
line: 0,
column: 0,
length: 0,
kind: TokenKind::Unspecified,
kind: TokenKind::Unspecified,
};
return Err(CompilationError {
kind: Internal { message },
Expand Down Expand Up @@ -74,19 +74,19 @@ impl<'src: 'run, 'run> AssignmentResolver<'src, 'run> {
} else {
Err(name.token().error(UndefinedVariable { variable }))
}
}
},
Expression::Call { thunk } => match thunk {
Thunk::Nullary { .. } => Ok(()),
Thunk::Unary { arg, .. } => self.resolve_expression(arg),
Thunk::Binary { args: [a, b], .. } => {
self.resolve_expression(a)?;
self.resolve_expression(b)
}
},
},
Expression::Concatination { lhs, rhs } => {
self.resolve_expression(lhs)?;
self.resolve_expression(rhs)
}
},
Expression::StringLiteral { .. } | Expression::Backtick { .. } => Ok(()),
Expression::Group { contents } => self.resolve_expression(contents),
}
Expand Down
4 changes: 2 additions & 2 deletions src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ pub(crate) struct Binding<'src, V = String> {
/// Export binding as an environment variable to child processes
pub(crate) export: bool,
/// Binding name
pub(crate) name: Name<'src>,
pub(crate) name: Name<'src>,
/// Binding value
pub(crate) value: V,
pub(crate) value: V,
}

impl<'src, V> Keyed<'src> for Binding<'src, V> {
Expand Down
11 changes: 5 additions & 6 deletions src/color.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use crate::common::*;

use ansi_term::Color::*;
use ansi_term::{ANSIGenericString, Prefix, Style, Suffix};
use ansi_term::{ANSIGenericString, Color::*, Prefix, Style, Suffix};
use atty::Stream;

#[derive(Copy, Clone, Debug, PartialEq)]
pub(crate) struct Color {
use_color: UseColor,
atty: bool,
style: Style,
atty: bool,
style: Style,
}

impl Color {
Expand Down Expand Up @@ -129,8 +128,8 @@ impl Default for Color {
fn default() -> Self {
Self {
use_color: UseColor::Auto,
atty: false,
style: Style::new(),
atty: false,
style: Style::new(),
}
}
}
Loading

0 comments on commit 3ec7dea

Please sign in to comment.