Skip to content

Commit

Permalink
Invalid Attribute changes
Browse files Browse the repository at this point in the history
  • Loading branch information
neunenak committed Jul 14, 2024
1 parent e0cd52c commit 0ad2393
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
13 changes: 6 additions & 7 deletions src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ impl<'src> Analyzer<'src> {
for attribute in attributes {
if !matches!(attribute, Attribute::Doc(..)) {
//TODO make this error more general
let alias = name.lexeme();
return Err(name.token.error(AliasInvalidAttribute {
alias,
return Err(name.token.error(InvalidAttribute {
item_kind: "Module",
item_name: name.lexeme(),
attribute: attribute.clone(),
}));
}
Expand Down Expand Up @@ -266,12 +266,11 @@ impl<'src> Analyzer<'src> {
}

fn analyze_alias(alias: &Alias<'src, Name<'src>>) -> CompileResult<'src> {
let name = alias.name.lexeme();

for attribute in &alias.attributes {
if *attribute != Attribute::Private {
return Err(alias.name.token.error(AliasInvalidAttribute {
alias: name,
return Err(alias.name.token.error(InvalidAttribute {
item_kind: "Alias",
item_name: alias.name.lexeme(),
attribute: attribute.clone(),
}));
}
Expand Down
16 changes: 9 additions & 7 deletions src/compile_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ impl Display for CompileError<'_> {
use CompileErrorKind::*;

match &*self.kind {
AliasInvalidAttribute { alias, attribute } => {
write!(
f,
"Alias `{alias}` has invalid attribute `{}`",
attribute.name(),
)
}
InvalidAttribute {
item_name,
item_kind,
attribute,
} => write!(
f,
"{item_kind} `{item_name}` has invalid attribute `{}`",
attribute.name(),
),
AliasShadowsRecipe { alias, recipe_line } => write!(
f,
"Alias `{alias}` defined on line {} shadows recipe `{alias}` defined on line {}",
Expand Down
9 changes: 5 additions & 4 deletions src/compile_error_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ use super::*;

#[derive(Debug, PartialEq)]
pub(crate) enum CompileErrorKind<'src> {
AliasInvalidAttribute {
alias: &'src str,
attribute: Attribute<'src>,
},
AliasShadowsRecipe {
alias: &'src str,
recipe_line: usize,
Expand Down Expand Up @@ -76,6 +72,11 @@ pub(crate) enum CompileErrorKind<'src> {
Internal {
message: String,
},
InvalidAttribute {
item_kind: &'static str,
item_name: &'src str,
attribute: Attribute<'src>,
},
InvalidEscapeSequence {
character: char,
},
Expand Down
21 changes: 14 additions & 7 deletions tests/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,10 +815,12 @@ fn comments_can_follow_modules() {
fn doc_comment_on_module() {
Test::new()
.write("foo.just", "")
.justfile("
.justfile(
"
# Comment
mod foo
")
",
)
.test_round_trip(false)
.arg("--unstable")
.arg("--list")
Expand All @@ -830,11 +832,13 @@ fn doc_comment_on_module() {
fn doc_attribute_on_module() {
Test::new()
.write("foo.just", "")
.justfile(r#"
.justfile(
r#"
# Suppressed comment
[doc: "Comment"]
mod foo
"#)
"#,
)
.test_round_trip(false)
.arg("--unstable")
.arg("--list")
Expand All @@ -846,13 +850,16 @@ fn doc_attribute_on_module() {
fn bad_module_attribute_fails() {
Test::new()
.write("foo.just", "")
.justfile(r#"
.justfile(
r#"
[no-cd]
mod foo
"#)
"#,
)
.test_round_trip(false)
.arg("--unstable")
.arg("--list")
.stdout("Available recipes:\n foo ... # Comment\n")
.stderr("error: Module `foo` has invalid attribute `no-cd`\n ——▶ justfile:2:5\n\n2 │ mod foo\n │ ^^^\n")
.status(EXIT_FAILURE)
.run();
}

0 comments on commit 0ad2393

Please sign in to comment.