This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
no-error.ts
54 lines (50 loc) · 2.24 KB
/
no-error.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @fileoverview
* We use our `ErrorHandler` to handle warnings, errors and fatal errors,
* which reacts appropriately and unified to the severity.
* Therefore, this handler should always be used instead of throwing an error yourself.
*
* @author Daniel Reichhart <[email protected]>
*/
/*
* ------------------------------------------------------------------------------
* Requirements
* ------------------------------------------------------------------------------
*/
import { RuleTester } from 'eslint';
import { noError } from '../../../lib/rules/no-error';
/*
* ------------------------------------------------------------------------------
* Tests
* ------------------------------------------------------------------------------
*/
const ruleTester = new RuleTester({ parserOptions: { ecmaFeatures: { jsx: true }, ecmaVersion: 6 } });
const error: RuleTester.TestCaseError = {
message: "Unallowed use of a error class. Please use the 'ErrorHandler' instead.",
type: 'NewExpression',
};
ruleTester.run('no-error', noError, {
invalid: [
{ code: "new Error('foo');", errors: [error] },
{ code: "new EvalError('foo');", errors: [error] },
{ code: "new InternalError('foo');", errors: [error] },
{ code: "new RangeError('foo');", errors: [error] },
{ code: "new ReferenceError('foo');", errors: [error] },
{ code: "new SyntaxError('foo');", errors: [error] },
{ code: "new TypeError('foo');", errors: [error] },
{ code: "new URIError('foo');", errors: [error] },
{ code: "throw new Error('foo');", errors: [error] },
{ code: "throw new EvalError('foo');", errors: [error] },
{ code: "throw new InternalError('foo');", errors: [error] },
{ code: "throw new RangeError('foo');", errors: [error] },
{ code: "throw new ReferenceError('foo');", errors: [error] },
{ code: "throw new SyntaxError('foo');", errors: [error] },
{ code: "throw new TypeError('foo');", errors: [error] },
{ code: "throw new URIError('foo');", errors: [error] },
],
valid: [
'new FooClass()',
"const Error = 'foo'",
"ErrorHandler.error({ code: FrontendErrorCodeEnum.BAD_HEX_COLOR, filename: 'ColorUtil.ts' });",
],
});