d02e7786b694c14d3d2386b37a1cbcb8e2273bc3
[platform/framework/web/crosswalk-tizen.git] /
1 /**
2  * @fileoverview Rule to restrict what can be thrown as an exception.
3  * @author Dieter Oberkofler
4  * @copyright 2015 Dieter Oberkofler. All rights reserved.
5  */
6
7 "use strict";
8
9 //------------------------------------------------------------------------------
10 // Rule Definition
11 //------------------------------------------------------------------------------
12
13 module.exports = function(context) {
14
15     return {
16
17         "ThrowStatement": function(node) {
18
19             if (node.argument.type === "Literal") {
20                 context.report(node, "Do not throw a literal.");
21             } else if (node.argument.type === "Identifier") {
22                 if (node.argument.name === "undefined") {
23                     context.report(node, "Do not throw undefined.");
24                 }
25             }
26
27         }
28
29     };
30
31 };