This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: report errors on duplicate actions or workflows (#44)
Fixes #41
- Loading branch information
1 parent
a4e3a08
commit 5572f59
Showing
7 changed files
with
145 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/*! | ||
* Copyright 2019 Omar Tawfik. Please see LICENSE file at the root of this repository. | ||
*/ | ||
|
||
import { BoundNodeVisitor } from "../binding/bound-node-visitor"; | ||
import { DiagnosticBag } from "../util/diagnostics"; | ||
import { BoundDocument, BoundAction, BoundWorkflow } from "../binding/bound-nodes"; | ||
import { MAXIMUM_SUPPORTED_ACTIONS } from "../util/constants"; | ||
|
||
export function analyzeBlocks( | ||
document: BoundDocument, | ||
bag: DiagnosticBag, | ||
): { | ||
workflows: ReadonlySet<string>; | ||
actions: ReadonlySet<string>; | ||
} { | ||
const instance = new BlocksAnalyzer(document, bag); | ||
return { | ||
workflows: instance.workflows, | ||
actions: instance.actions, | ||
}; | ||
} | ||
|
||
class BlocksAnalyzer extends BoundNodeVisitor { | ||
private readonly allWorkflows = new Set<string>(); | ||
private readonly allActions = new Set<string>(); | ||
private actionsExceededMaximum = false; | ||
|
||
public constructor(document: BoundDocument, private readonly bag: DiagnosticBag) { | ||
super(); | ||
this.visit(document); | ||
} | ||
|
||
public get workflows(): ReadonlySet<string> { | ||
return this.allWorkflows; | ||
} | ||
|
||
public get actions(): ReadonlySet<string> { | ||
return this.allActions; | ||
} | ||
|
||
protected visitAction(node: BoundAction): void { | ||
if (this.allActions.has(node.name) || this.allWorkflows.has(node.name)) { | ||
this.bag.duplicateBlock(node.name, node.syntax.name.range); | ||
} else { | ||
this.allActions.add(node.name); | ||
} | ||
|
||
if (!this.actionsExceededMaximum && this.allActions.size > MAXIMUM_SUPPORTED_ACTIONS) { | ||
this.bag.tooManyActions(node.syntax.name.range); | ||
this.actionsExceededMaximum = true; | ||
} | ||
|
||
super.visitAction(node); | ||
} | ||
|
||
protected visitWorkflow(node: BoundWorkflow): void { | ||
if (this.allActions.has(node.name) || this.allWorkflows.has(node.name)) { | ||
this.bag.duplicateBlock(node.name, node.syntax.name.range); | ||
} else { | ||
this.allWorkflows.add(node.name); | ||
} | ||
|
||
super.visitWorkflow(node); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters