-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
2,650 additions
and
4,190 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 @@ | ||
CHANGELOG.md |
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,37 @@ | ||
import { createRule } from '../utils' | ||
|
||
const NAME = 'forbid-throw-new-error' | ||
|
||
const value = createRule({ | ||
create(context) { | ||
return { | ||
Identifier(node) { | ||
if (node.name === "Error") { | ||
context.report({ | ||
loc: node.loc, | ||
messageId: 'default', | ||
}) | ||
} | ||
}, | ||
} | ||
}, | ||
defaultOptions: [], | ||
meta: { | ||
docs: { | ||
description: 'Prevents throwing default errors', | ||
recommended: false, | ||
requiresTypeChecking: false, | ||
}, | ||
messages: { | ||
default: 'You must throw a domain specific error', | ||
}, | ||
schema: [{ additionalProperties: false }], | ||
type: 'problem', | ||
}, | ||
name: NAME, | ||
}) | ||
|
||
export default { | ||
name: NAME, | ||
value, | ||
} |
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,27 @@ | ||
import dedent from 'dedent' | ||
|
||
import rule from '../../../rules/forbid-throw-new-error' | ||
import { | ||
TS_FILE_PATH, | ||
tsRuleTester, | ||
} from '../utils' | ||
|
||
tsRuleTester.run(rule.name, rule.value, { | ||
invalid: [ | ||
{ | ||
code: dedent`throw new Error("Something failed");`, | ||
errors: [ | ||
{ | ||
column: 11, | ||
line: 1, | ||
messageId: 'default', | ||
}, | ||
], | ||
filename: TS_FILE_PATH, | ||
}, | ||
], | ||
valid: [{ | ||
code: dedent`throw new CustomError("Something failed");`, | ||
filename: TS_FILE_PATH, | ||
}], | ||
}) |
Oops, something went wrong.