1 | /**
|
2 | * Disallows function declarations.
|
3 | *
|
4 | * Type: `Boolean`
|
5 | *
|
6 | * Value: `true`
|
7 | *
|
8 | * #### Example
|
9 | *
|
10 | * ```js
|
11 | * "disallowFunctionDeclarations": true
|
12 | * ```
|
13 | *
|
14 | * ##### Valid
|
15 | *
|
16 | * ```js
|
17 | * var expressed = function() {
|
18 | *
|
19 | * };
|
20 | *
|
21 | * var expressed = function deeply() {
|
22 | *
|
23 | * };
|
24 | *
|
25 | * $('#foo').click(function bar() {
|
26 | *
|
27 | * });
|
28 | * ```
|
29 | *
|
30 | * ##### Invalid
|
31 | *
|
32 | * ```js
|
33 | * function stated() {
|
34 | *
|
35 | * }
|
36 | * ```
|
37 | */
|
38 |
|
39 | var assert = require('assert');
|
40 |
|
41 | module.exports = function() {};
|
42 |
|
43 | module.exports.prototype = {
|
44 | configure: function(options) {
|
45 | assert(
|
46 | options === true,
|
47 | this.getOptionName() + ' option requires a true value or should be removed'
|
48 | );
|
49 | },
|
50 |
|
51 | getOptionName: function() {
|
52 | return 'disallowFunctionDeclarations';
|
53 | },
|
54 |
|
55 | check: function(file, errors) {
|
56 | file.iterateNodesByType('FunctionDeclaration', function(node) {
|
57 | errors.add('Illegal function declaration', node);
|
58 | });
|
59 | }
|
60 | };
|