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.
feat: report errors on too many secrets (#27)
Closes #9
- Loading branch information
1 parent
6aac339
commit 8ece721
Showing
11 changed files
with
315 additions
and
19 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/*! | ||
* Copyright 2019 Omar Tawfik. Please see LICENSE file at the root of this repository. | ||
*/ | ||
|
||
import { | ||
BaseBoundNode, | ||
BoundKind, | ||
BoundDocument, | ||
BoundVersion, | ||
BoundWorkflow, | ||
BoundAction, | ||
BoundOn, | ||
BoundResolves, | ||
BoundUses, | ||
BoundNeeds, | ||
BoundRuns, | ||
BoundArgs, | ||
BoundEnv, | ||
BoundSecrets, | ||
} from "./bound-nodes"; | ||
import { BaseSyntaxNode } from "../parsing/syntax-nodes"; | ||
|
||
export abstract class BoundNodeVisitor { | ||
protected visit(node: BaseBoundNode<BaseSyntaxNode>): void { | ||
switch (node.kind) { | ||
case BoundKind.Document: { | ||
return this.visitDocument(node as BoundDocument); | ||
} | ||
case BoundKind.Version: { | ||
return this.visitVersion(node as BoundVersion); | ||
} | ||
case BoundKind.Workflow: { | ||
return this.visitWorkflow(node as BoundWorkflow); | ||
} | ||
case BoundKind.Action: { | ||
return this.visitAction(node as BoundAction); | ||
} | ||
case BoundKind.On: { | ||
return this.visitOn(node as BoundOn); | ||
} | ||
case BoundKind.Resolves: { | ||
return this.visitResolves(node as BoundResolves); | ||
} | ||
case BoundKind.Uses: { | ||
return this.visitUses(node as BoundUses); | ||
} | ||
case BoundKind.Needs: { | ||
return this.visitNeeds(node as BoundNeeds); | ||
} | ||
case BoundKind.Runs: { | ||
return this.visitRuns(node as BoundRuns); | ||
} | ||
case BoundKind.Args: { | ||
return this.visitArgs(node as BoundArgs); | ||
} | ||
case BoundKind.Env: { | ||
return this.visitEnv(node as BoundEnv); | ||
} | ||
case BoundKind.Secrets: { | ||
return this.visitSecrets(node as BoundSecrets); | ||
} | ||
default: { | ||
throw new Error(`Unexpected bound kind: '${node.kind}'`); | ||
} | ||
} | ||
} | ||
|
||
protected visitDocument(node: BoundDocument): void { | ||
return this.visitDefault(node); | ||
} | ||
|
||
protected visitVersion(node: BoundVersion): void { | ||
return this.visitDefault(node); | ||
} | ||
|
||
protected visitWorkflow(node: BoundWorkflow): void { | ||
return this.visitDefault(node); | ||
} | ||
|
||
protected visitAction(node: BoundAction): void { | ||
return this.visitDefault(node); | ||
} | ||
|
||
protected visitOn(node: BoundOn): void { | ||
return this.visitDefault(node); | ||
} | ||
|
||
protected visitResolves(node: BoundResolves): void { | ||
return this.visitDefault(node); | ||
} | ||
|
||
protected visitUses(node: BoundUses): void { | ||
return this.visitDefault(node); | ||
} | ||
|
||
protected visitNeeds(node: BoundNeeds): void { | ||
return this.visitDefault(node); | ||
} | ||
|
||
protected visitRuns(node: BoundRuns): void { | ||
return this.visitDefault(node); | ||
} | ||
|
||
protected visitArgs(node: BoundArgs): void { | ||
return this.visitDefault(node); | ||
} | ||
|
||
protected visitEnv(node: BoundEnv): void { | ||
return this.visitDefault(node); | ||
} | ||
|
||
protected visitSecrets(node: BoundSecrets): void { | ||
return this.visitDefault(node); | ||
} | ||
|
||
private visitDefault(node: BaseBoundNode<BaseSyntaxNode>): void { | ||
node.children.forEach(child => { | ||
this.visit(child); | ||
}); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/*! | ||
* Copyright 2019 Omar Tawfik. Please see LICENSE file at the root of this repository. | ||
*/ | ||
|
||
import { BoundNodeVisitor } from "../bound-node-visitor"; | ||
import { DiagnosticBag } from "../../util/diagnostics"; | ||
import { BoundSecrets, BoundDocument } from "../bound-nodes"; | ||
import { MAXIMUM_SUPPORTED_SECRETS } from "../../util/constants"; | ||
|
||
export class TooManySecretsVisitor extends BoundNodeVisitor { | ||
private definedAlready = new Set<string>(); | ||
private alreadyReported = false; | ||
|
||
public constructor(document: BoundDocument, private readonly bag: DiagnosticBag) { | ||
super(); | ||
this.visit(document); | ||
} | ||
|
||
protected visitSecrets(node: BoundSecrets): void { | ||
if (!this.alreadyReported) { | ||
for (const arg of node.args) { | ||
this.definedAlready.add(arg); | ||
if (this.definedAlready.size > MAXIMUM_SUPPORTED_SECRETS) { | ||
this.bag.tooManySecrets(node.syntax.key.range); | ||
this.alreadyReported = true; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
super.visitSecrets(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/*! | ||
* Copyright 2019 Omar Tawfik. Please see LICENSE file at the root of this repository. | ||
*/ | ||
|
||
export function filterUndefined<T>(...items: (T | undefined)[]): T[] { | ||
const result = Array<T>(); | ||
|
||
items.forEach(item => { | ||
if (item) { | ||
result.push(item); | ||
} | ||
}); | ||
|
||
return result; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/*! | ||
* Copyright 2019 Omar Tawfik. Please see LICENSE file at the root of this repository. | ||
*/ | ||
|
||
export const MAXIMUM_SUPPORTED_VERSION = 0; | ||
export const MAXIMUM_SUPPORTED_SECRETS = 100; |
Oops, something went wrong.