Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Commit

Permalink
feat: report errors on duplicate actions in resolves (#48)
Browse files Browse the repository at this point in the history
Fixes #37
  • Loading branch information
OmarTawfik committed Mar 12, 2019
1 parent 87ea513 commit 5e7db6d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/analysis/properties-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ class PropertiesAnalyzer extends BoundNodeVisitor {
}

protected visitResolves(node: BoundResolves): void {
const localActions = new Set<string>();
for (const action of node.actions) {
if (!this.actions.has(action.value)) {
this.bag.actionDoesNotExist(action.value, action.syntax.range);
}

if (localActions.has(action.value)) {
this.bag.duplicateActions(action.value, action.syntax.range);
} else {
localActions.add(action.value);
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/util/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export enum DiagnosticCode {
ActionDoesNotExist,
TooManySecrets,
DuplicateSecrets,
DuplicateActions,
ReservedEnvironmentVariable,
UnrecognizedEvent,
}
Expand Down Expand Up @@ -229,6 +230,14 @@ export class DiagnosticBag {
});
}

public duplicateActions(duplicate: string, range: TextRange): void {
this.items.push({
range,
code: DiagnosticCode.DuplicateActions,
message: `This 'resolves' property has duplicate '${duplicate}' actions.`,
});
}

public reservedEnvironmentVariable(range: TextRange): void {
this.items.push({
range,
Expand Down
24 changes: 24 additions & 0 deletions test/properties-analysis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,30 @@ ERROR: Environment variables starting with 'GITHUB_' are reserved.
6 | GITHUBNOUNDERSCORE = \\"2\\"
7 | SOMETHING_ELSE = \\"3\\"
"
`);
});

it("reports errors on duplicate resolve actions", () => {
expectDiagnostics(`
action "b" {
uses = "./ci"
}
workflow "c" {
on = "fork"
resolves = [
"b",
"b"
]
}`).toMatchInlineSnapshot(`
"
ERROR: This 'resolves' property has duplicate 'b' actions.
7 | resolves = [
8 | \\"b\\",
9 | \\"b\\"
| ^^^
10 | ]
11 | }
"
`);
});
});

0 comments on commit 5e7db6d

Please sign in to comment.