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 calls to the Object constructor
|
---|
3 | * @author Matt DuVall <http://www.mattduvall.com/>
|
---|
4 | * @deprecated in ESLint v8.50.0
|
---|
5 | */
|
---|
6 |
|
---|
7 | "use strict";
|
---|
8 |
|
---|
9 | //------------------------------------------------------------------------------
|
---|
10 | // Requirements
|
---|
11 | //------------------------------------------------------------------------------
|
---|
12 |
|
---|
13 | const astUtils = require("./utils/ast-utils");
|
---|
14 |
|
---|
15 | //------------------------------------------------------------------------------
|
---|
16 | // Rule Definition
|
---|
17 | //------------------------------------------------------------------------------
|
---|
18 |
|
---|
19 | /** @type {import('../shared/types').Rule} */
|
---|
20 | module.exports = {
|
---|
21 | meta: {
|
---|
22 | type: "suggestion",
|
---|
23 |
|
---|
24 | docs: {
|
---|
25 | description: "Disallow `Object` constructors",
|
---|
26 | recommended: false,
|
---|
27 | url: "https://eslint.org/docs/latest/rules/no-new-object"
|
---|
28 | },
|
---|
29 |
|
---|
30 | deprecated: true,
|
---|
31 |
|
---|
32 | replacedBy: [
|
---|
33 | "no-object-constructor"
|
---|
34 | ],
|
---|
35 |
|
---|
36 | schema: [],
|
---|
37 |
|
---|
38 | messages: {
|
---|
39 | preferLiteral: "The object literal notation {} is preferable."
|
---|
40 | }
|
---|
41 | },
|
---|
42 |
|
---|
43 | create(context) {
|
---|
44 |
|
---|
45 | const sourceCode = context.sourceCode;
|
---|
46 |
|
---|
47 | return {
|
---|
48 | NewExpression(node) {
|
---|
49 | const variable = astUtils.getVariableByName(
|
---|
50 | sourceCode.getScope(node),
|
---|
51 | node.callee.name
|
---|
52 | );
|
---|
53 |
|
---|
54 | if (variable && variable.identifiers.length > 0) {
|
---|
55 | return;
|
---|
56 | }
|
---|
57 |
|
---|
58 | if (node.callee.name === "Object") {
|
---|
59 | context.report({
|
---|
60 | node,
|
---|
61 | messageId: "preferLiteral"
|
---|
62 | });
|
---|
63 | }
|
---|
64 | }
|
---|
65 | };
|
---|
66 | }
|
---|
67 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.