1 | /**
|
2 | * @fileoverview Marks all var declarations that are not at the top level
|
3 | * invalid.
|
4 | *
|
5 | * This Source Code Form is subject to the terms of the Mozilla Public
|
6 | * License, v. 2.0. If a copy of the MPL was not distributed with this
|
7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
8 | */
|
9 |
|
10 | ;
|
11 |
|
12 | // -----------------------------------------------------------------------------
|
13 | // Rule Definition
|
14 | // -----------------------------------------------------------------------------
|
15 |
|
16 | var helpers = require("../helpers");
|
17 |
|
18 | module.exports = function(context) {
|
19 | // ---------------------------------------------------------------------------
|
20 | // Public
|
21 | // --------------------------------------------------------------------------
|
22 |
|
23 | return {
|
24 | "VariableDeclaration": function(node) {
|
25 | if (node.kind === "var") {
|
26 | if (helpers.getIsGlobalScope(context.getAncestors())) {
|
27 | return;
|
28 | }
|
29 |
|
30 | context.report(node, "Unexpected var, use let or const instead.");
|
31 | }
|
32 | }
|
33 | };
|
34 | };
|