source: imaps-frontend/node_modules/eslint/lib/rules/no-class-assign.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**
2 * @fileoverview A rule to disallow modifying variables of class declarations
3 * @author Toru Nagashima
4 */
5
6"use strict";
7
8const astUtils = require("./utils/ast-utils");
9
10//------------------------------------------------------------------------------
11// Rule Definition
12//------------------------------------------------------------------------------
13
14/** @type {import('../shared/types').Rule} */
15module.exports = {
16 meta: {
17 type: "problem",
18
19 docs: {
20 description: "Disallow reassigning class members",
21 recommended: true,
22 url: "https://eslint.org/docs/latest/rules/no-class-assign"
23 },
24
25 schema: [],
26
27 messages: {
28 class: "'{{name}}' is a class."
29 }
30 },
31
32 create(context) {
33
34 const sourceCode = context.sourceCode;
35
36 /**
37 * Finds and reports references that are non initializer and writable.
38 * @param {Variable} variable A variable to check.
39 * @returns {void}
40 */
41 function checkVariable(variable) {
42 astUtils.getModifyingReferences(variable.references).forEach(reference => {
43 context.report({ node: reference.identifier, messageId: "class", data: { name: reference.identifier.name } });
44
45 });
46 }
47
48 /**
49 * Finds and reports references that are non initializer and writable.
50 * @param {ASTNode} node A ClassDeclaration/ClassExpression node to check.
51 * @returns {void}
52 */
53 function checkForClass(node) {
54 sourceCode.getDeclaredVariables(node).forEach(checkVariable);
55 }
56
57 return {
58 ClassDeclaration: checkForClass,
59 ClassExpression: checkForClass
60 };
61
62 }
63};
Note: See TracBrowser for help on using the repository browser.