1 | /**
|
2 | * @fileoverview A rule to disallow modifying variables of class declarations
|
3 | * @author Toru Nagashima
|
4 | * @copyright 2015 Toru Nagashima. All rights reserved.
|
5 | */
|
6 |
|
7 | ;
|
8 |
|
9 | var astUtils = require("../ast-utils");
|
10 |
|
11 | //------------------------------------------------------------------------------
|
12 | // Rule Definition
|
13 | //------------------------------------------------------------------------------
|
14 |
|
15 | module.exports = function(context) {
|
16 |
|
17 | /**
|
18 | * Finds and reports references that are non initializer and writable.
|
19 | * @param {Variable} variable - A variable to check.
|
20 | * @returns {void}
|
21 | */
|
22 | function checkVariable(variable) {
|
23 | astUtils.getModifyingReferences(variable.references).forEach(function(reference) {
|
24 | context.report(
|
25 | reference.identifier,
|
26 | "'{{name}}' is a class.",
|
27 | {name: reference.identifier.name});
|
28 |
|
29 | });
|
30 | }
|
31 |
|
32 | /**
|
33 | * Finds and reports references that are non initializer and writable.
|
34 | * @param {ASTNode} node - A ClassDeclaration/ClassExpression node to check.
|
35 | * @returns {void}
|
36 | */
|
37 | function checkForClass(node) {
|
38 | context.getDeclaredVariables(node).forEach(checkVariable);
|
39 | }
|
40 |
|
41 | return {
|
42 | "ClassDeclaration": checkForClass,
|
43 | "ClassExpression": checkForClass
|
44 | };
|
45 |
|
46 | };
|
47 |
|
48 | module.exports.schema = [];
|