UNPKG

936 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag when deleting variables
3 * @author Ilya Volodin
4 */
5
6"use strict";
7
8//------------------------------------------------------------------------------
9// Rule Definition
10//------------------------------------------------------------------------------
11
12module.exports = {
13 meta: {
14 docs: {
15 description: "disallow deleting variables",
16 category: "Variables",
17 recommended: true,
18 url: "https://eslint.org/docs/rules/no-delete-var"
19 },
20
21 schema: [],
22
23 messages: {
24 unexpected: "Variables should not be deleted."
25 }
26 },
27
28 create(context) {
29
30 return {
31
32 UnaryExpression(node) {
33 if (node.operator === "delete" && node.argument.type === "Identifier") {
34 context.report({ node, messageId: "unexpected" });
35 }
36 }
37 };
38
39 }
40};