Skip to content

Commit

Permalink
Merge branch 'master' into summary-feature
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Sep 22, 2019
2 parents 6df9b44 + 1230af1 commit 81b587a
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) use crate::{
recipe_context::RecipeContext, recipe_resolver::RecipeResolver, runtime_error::RuntimeError,
search_error::SearchError, shebang::Shebang, state::State, string_literal::StringLiteral,
token::Token, token_kind::TokenKind, use_color::UseColor, variables::Variables,
verbosity::Verbosity,
verbosity::Verbosity, warning::Warning,
};

pub(crate) type CompilationResult<'a, T> = Result<T, CompilationError<'a>>;
Expand Down
5 changes: 3 additions & 2 deletions src/compilation_error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::common::*;

use crate::misc::{maybe_s, show_whitespace, write_error_context, Or};
use crate::misc::{maybe_s, show_whitespace, write_message_context, Or};

#[derive(Debug, PartialEq)]
pub(crate) struct CompilationError<'a> {
Expand Down Expand Up @@ -211,8 +211,9 @@ impl<'a> Display for CompilationError<'a> {

write!(f, "{}", message.suffix())?;

write_error_context(
write_message_context(
f,
Color::fmt(f).error(),
self.text,
self.offset,
self.line,
Expand Down
2 changes: 1 addition & 1 deletion src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub(crate) struct Justfile<'a> {
pub(crate) assignments: BTreeMap<&'a str, Expression<'a>>,
pub(crate) exports: BTreeSet<&'a str>,
pub(crate) aliases: BTreeMap<&'a str, Alias<'a>>,
pub(crate) deprecated_equals: bool,
pub(crate) warnings: Vec<Warning<'a>>,
}

impl<'a> Justfile<'a> where {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ mod token_kind;
mod use_color;
mod variables;
mod verbosity;
mod warning;

pub use crate::run::run;

Expand Down
8 changes: 4 additions & 4 deletions src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ pub(crate) fn conjoin<T: Display>(
Ok(())
}

pub(crate) fn write_error_context(
pub(crate) fn write_message_context(
f: &mut Formatter,
color: Color,
text: &str,
offset: usize,
line: usize,
Expand All @@ -66,7 +67,6 @@ pub(crate) fn write_error_context(
let width = if width == 0 { 1 } else { width };

let line_number = line.ordinal();
let red = Color::fmt(f).error();
match text.lines().nth(line) {
Some(line) => {
let mut i = 0;
Expand Down Expand Up @@ -102,10 +102,10 @@ pub(crate) fn write_error_context(
" {0:1$}{2}{3:^<4$}{5}",
"",
space_column,
red.prefix(),
color.prefix(),
"",
space_width,
red.suffix()
color.suffix()
)?;
}
None => {
Expand Down
24 changes: 15 additions & 9 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) struct Parser<'a> {
exports: BTreeSet<&'a str>,
aliases: BTreeMap<&'a str, Alias<'a>>,
alias_tokens: BTreeMap<&'a str, Token<'a>>,
deprecated_equals: bool,
warnings: Vec<Warning<'a>>,
}

impl<'a> Parser<'a> {
Expand All @@ -32,7 +32,7 @@ impl<'a> Parser<'a> {
exports: empty(),
aliases: empty(),
alias_tokens: empty(),
deprecated_equals: false,
warnings: Vec::new(),
text,
}
}
Expand Down Expand Up @@ -421,8 +421,10 @@ impl<'a> Parser<'a> {
Name => {
if token.lexeme() == "export" {
let next = self.tokens.next().unwrap();
if next.kind == Name && self.accepted(Equals) {
self.deprecated_equals = true;
if next.kind == Name && self.peek(Equals) {
self.warnings.push(Warning::DeprecatedEquals {
equals: self.tokens.next().unwrap(),
});
self.assignment(next, true)?;
doc = None;
} else if next.kind == Name && self.accepted(ColonEquals) {
Expand All @@ -435,8 +437,10 @@ impl<'a> Parser<'a> {
}
} else if token.lexeme() == "alias" {
let next = self.tokens.next().unwrap();
if next.kind == Name && self.accepted(Equals) {
self.deprecated_equals = true;
if next.kind == Name && self.peek(Equals) {
self.warnings.push(Warning::DeprecatedEquals {
equals: self.tokens.next().unwrap(),
});
self.alias(next)?;
doc = None;
} else if next.kind == Name && self.accepted(ColonEquals) {
Expand All @@ -447,8 +451,10 @@ impl<'a> Parser<'a> {
self.recipe(&token, doc, false)?;
doc = None;
}
} else if self.accepted(Equals) {
self.deprecated_equals = true;
} else if self.peek(Equals) {
self.warnings.push(Warning::DeprecatedEquals {
equals: self.tokens.next().unwrap(),
});
self.assignment(token, false)?;
doc = None;
} else if self.accepted(ColonEquals) {
Expand Down Expand Up @@ -515,7 +521,7 @@ impl<'a> Parser<'a> {
assignments: self.assignments,
exports: self.exports,
aliases: self.aliases,
deprecated_equals: self.deprecated_equals,
warnings: self.warnings,
})
}
}
Expand Down
22 changes: 6 additions & 16 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,22 +318,12 @@ pub fn run() {
}
});

if justfile.deprecated_equals {
let warning = color.warning().stderr();
let message = color.message().stderr();

eprintln!(
"{}",
warning.paint(
"warning: `=` in assignments, exports, and aliases is being phased out on favor of `:=`"
)
);

eprintln!(
"{}",
message
.paint("Please see this issue for more details: https://github.com/casey/just/issues/379")
);
for warning in &justfile.warnings {
if color.stderr().active() {
eprintln!("{:#}", warning);
} else {
eprintln!("{}", warning);
}
}

if matches.is_present("SUMMARY") {
Expand Down
5 changes: 3 additions & 2 deletions src/runtime_error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::common::*;

use crate::misc::{maybe_s, ticks, write_error_context, And, Or, Tick};
use crate::misc::{maybe_s, ticks, write_message_context, And, Or, Tick};

#[derive(Debug)]
pub(crate) enum RuntimeError<'a> {
Expand Down Expand Up @@ -387,8 +387,9 @@ impl<'a> Display for RuntimeError<'a> {
write!(f, "{}", message.suffix())?;

if let Some(token) = error_token {
write_error_context(
write_message_context(
f,
Color::fmt(f).error(),
token.text,
token.offset,
token.line,
Expand Down
56 changes: 56 additions & 0 deletions src/warning.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use crate::common::*;
use crate::misc::write_message_context;

use Warning::*;

#[derive(Debug)]
pub(crate) enum Warning<'a> {
DeprecatedEquals { equals: Token<'a> },
}

impl Warning<'_> {
fn context(&self) -> Option<&Token> {
match self {
DeprecatedEquals { equals } => Some(equals),
}
}
}

impl Display for Warning<'_> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
let warning = Color::fmt(f).warning();
let message = Color::fmt(f).message();

write!(f, "{} {}", warning.paint("warning:"), message.prefix())?;

match self {
DeprecatedEquals { .. } => {
writeln!(
f,
"`=` in assignments, exports, and aliases is being phased out on favor of `:=`"
)?;
write!(
f,
"Please see this issue for more details: https://github.com/casey/just/issues/379"
)?;
}
}

write!(f, "{}", message.suffix())?;

if let Some(token) = self.context() {
writeln!(f)?;
write_message_context(
f,
Color::fmt(f).warning(),
token.text,
token.offset,
token.line,
token.column,
token.lexeme().len(),
)?;
}

Ok(())
}
}
9 changes: 9 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2414,6 +2414,9 @@ default:
stdout: "bar\n",
stderr: "warning: `=` in assignments, exports, and aliases is being phased out on favor of `:=`
Please see this issue for more details: https://github.com/casey/just/issues/379
|
3 | foo = 'bar'
| ^
echo bar
",
status: EXIT_SUCCESS,
Expand All @@ -2434,6 +2437,9 @@ default:
stdout: "bar\n",
stderr: "warning: `=` in assignments, exports, and aliases is being phased out on favor of `:=`
Please see this issue for more details: https://github.com/casey/just/issues/379
|
3 | export FOO = 'bar'
| ^
echo $FOO
",
status: EXIT_SUCCESS,
Expand All @@ -2454,6 +2460,9 @@ default:
stdout: "default\n",
stderr: "warning: `=` in assignments, exports, and aliases is being phased out on favor of `:=`
Please see this issue for more details: https://github.com/casey/just/issues/379
|
3 | alias foo = default
| ^
echo default
",
status: EXIT_SUCCESS,
Expand Down

0 comments on commit 81b587a

Please sign in to comment.