This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Rules and make IReporter injectable
- Loading branch information
1 parent
b58d1a2
commit d2bb6c8
Showing
22 changed files
with
251 additions
and
213 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
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,41 @@ | ||
import { injectable } from "inversify"; | ||
import IReporter from "./interfaces/IReporter"; | ||
|
||
/** | ||
* The standard console reporter | ||
*/ | ||
@injectable() | ||
export default class ConsoleReporter implements IReporter { | ||
/** | ||
* Show a debug message | ||
* @param str The message | ||
*/ | ||
public debug(...str: any[]): void { | ||
// tslint:disable-next-line:no-console | ||
console.debug(...str); | ||
} | ||
/** | ||
* Show a info message | ||
* @param str The message | ||
*/ | ||
public info(...str: any[]): void { | ||
// tslint:disable-next-line:no-console | ||
console.info(...str); | ||
} | ||
/** | ||
* Show a warn message | ||
* @param str The message | ||
*/ | ||
public warn(...str: any[]): void { | ||
// tslint:disable-next-line:no-console | ||
console.warn(...str); | ||
} | ||
/** | ||
* Show a error message | ||
* @param str The message | ||
*/ | ||
public error(...str: any[]): void { | ||
// tslint:disable-next-line:no-console | ||
console.error(...str); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { inject, injectable } from "inversify"; | ||
import { TYPES } from "../../types"; | ||
import IValidationRuleConfig from "../config/interfaces/IValidationRuleConfig"; | ||
import IReporter from "../reporter/interfaces/IReporter"; | ||
import IRule from "./interfaces/IRule"; | ||
import IValidableScript from "./interfaces/IValidableScript"; | ||
|
||
/** | ||
* This class validates a single IRule against a ValidableScript with a rule configuration. | ||
*/ | ||
@injectable() | ||
export default class RuleValidator { | ||
|
||
/** | ||
* Reporter used by the class to warn about validations. | ||
*/ | ||
@inject(TYPES.IReporter) | ||
private _reporter: IReporter; | ||
|
||
/** | ||
* Validates a single rule against a ValidableScript | ||
* @param element The element to check the rule against | ||
* @param ruleConfig The rule configuration | ||
*/ | ||
public validate(rule: IRule, script: IValidableScript, config: IValidationRuleConfig): boolean { | ||
if (!rule.isValid(script)) { | ||
// Rule is invalid | ||
if (config.warn) { | ||
// Should warn about invalid rule | ||
this._reporter.warn(rule.getWarnMessage(script)); | ||
} | ||
return !(config.ignore); | ||
} | ||
return true; | ||
} | ||
} |
Oops, something went wrong.