Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/compile_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ impl Display for CompileError<'_> {
}
DuplicateArgAttribute { arg, first } => write!(
f,
"recipe attribute for argument `{arg}` first used on line {} is duplicated on line {}",
"attribute for argument `{arg}` first used on line {} is duplicated on line {}",
first.ordinal(),
self.token.line.ordinal(),
),
DuplicateAttribute { attribute, first } => write!(
f,
"recipe attribute `{attribute}` first used on line {} is duplicated on line {}",
"attribute `{attribute}` first used on line {} is duplicated on line {}",
first.ordinal(),
self.token.line.ordinal(),
),
Expand All @@ -162,6 +162,12 @@ impl Display for CompileError<'_> {
"function `{function}` has duplicate parameter `{parameter}`"
)
}
DuplicateGroupAttribute { group, first } => write!(
f,
"`[group({group})]` attribute first used on line {} is duplicated on line {}",
first.ordinal(),
self.token.line.ordinal(),
),
DuplicateOption { recipe, option } => {
write!(
f,
Expand Down
4 changes: 4 additions & 0 deletions src/compile_error_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ pub(crate) enum CompileErrorKind<'src> {
function: &'src str,
parameter: &'src str,
},
DuplicateGroupAttribute {
first: usize,
group: StringLiteral<'src>,
},
DuplicateOption {
recipe: &'src str,
option: Switch,
Expand Down
12 changes: 12 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,7 @@ impl<'run, 'src> Parser<'run, 'src> {
/// Item attributes, i.e., `[macos]` or `[confirm: "warning!"]`
fn parse_attributes(&mut self) -> CompileResult<'src, Option<(Token<'src>, AttributeSet<'src>)>> {
let mut arg_attributes = BTreeMap::new();
let mut group_attributes = BTreeMap::new();
let mut attributes = Vec::new();
let mut kinds = BTreeMap::new();

Expand Down Expand Up @@ -1842,6 +1843,17 @@ impl<'run, 'src> Parser<'run, 'src> {
arg_attributes.insert(arg.cooked.clone(), name.line);
}

if let Attribute::Group(group) = &attribute {
if let Some(&first) = group_attributes.get(&group.cooked) {
return Err(name.error(CompileErrorKind::DuplicateGroupAttribute {
group: group.clone(),
first,
}));
}

group_attributes.insert(group.cooked.clone(), name.line);
}

kinds.insert(attribute.kind(), name.line);

attributes.push((attribute, name));
Expand Down
2 changes: 1 addition & 1 deletion tests/arg_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ fn duplicate_attribute_error() {
.args(["foo", "BAR"])
.stderr(
"
error: recipe attribute for argument `bar` first used on line 1 is duplicated on line 2
error: attribute for argument `bar` first used on line 1 is duplicated on line 2
——▶ justfile:2:2
│
2 │ [arg('bar', pattern='BAR')]
Expand Down
6 changes: 3 additions & 3 deletions tests/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn duplicate_attributes_are_disallowed() {
)
.stderr(
"
error: recipe attribute `no-exit-message` first used on line 1 is duplicated on line 2
error: attribute `no-exit-message` first used on line 1 is duplicated on line 2
——▶ justfile:2:2
│
2 │ [no-exit-message]
Expand Down Expand Up @@ -118,7 +118,7 @@ fn multiple_attributes_one_line_duplicate_check() {
)
.stderr(
"
error: recipe attribute `linux` first used on line 1 is duplicated on line 2
error: attribute `linux` first used on line 1 is duplicated on line 2
——▶ justfile:2:2
│
2 │ [linux]
Expand Down Expand Up @@ -421,7 +421,7 @@ fn duplicate_non_repeatable_attributes_are_forbidden() {
)
.stderr(
"
error: recipe attribute `confirm` first used on line 1 is duplicated on line 2
error: attribute `confirm` first used on line 1 is duplicated on line 2
——▶ justfile:2:2
│
2 │ [confirm: 'no']
Expand Down
22 changes: 22 additions & 0 deletions tests/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,25 @@ fn reject_extra_arguments() {
.stderr("error: `--groups` used with unexpected argument: `baz`\n")
.failure();
}

#[test]
fn forbid_duplicate_groups() {
Test::new()
.justfile(
"
[group('a')]
[group('a')]
foo:
",
)
.stderr(
"
error: `[group('a')]` attribute first used on line 1 is duplicated on line 2
——▶ justfile:2:2
│
2 │ [group('a')]
│ ^^^^^
",
)
.failure();
}
2 changes: 1 addition & 1 deletion tests/working_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ fn attribute_duplicate() {
",
)
.stderr(
"error: recipe attribute `working-directory` first used on line 1 is duplicated on line 2
"error: attribute `working-directory` first used on line 1 is duplicated on line 2
——▶ justfile:2:2
│
2 │ [working-directory('baz')]
Expand Down
Loading