UNPKG

915 BJavaScriptView Raw
1'use strict'
2
3const PROMISE_STATICS = require('./lib/promise-statics')
4const getDocsUrl = require('./lib/get-docs-url')
5
6module.exports = {
7 meta: {
8 type: 'problem',
9 docs: {
10 url: getDocsUrl('no-new-statics'),
11 },
12 fixable: 'code',
13 schema: [],
14 },
15 create(context) {
16 return {
17 NewExpression(node) {
18 if (
19 node.callee.type === 'MemberExpression' &&
20 node.callee.object.name === 'Promise' &&
21 PROMISE_STATICS[node.callee.property.name]
22 ) {
23 context.report({
24 node,
25 message: "Avoid calling 'new' on 'Promise.{{ name }}()'",
26 data: { name: node.callee.property.name },
27 fix(fixer) {
28 return fixer.replaceTextRange(
29 [node.range[0], node.range[0] + 'new '.length],
30 ''
31 )
32 },
33 })
34 }
35 },
36 }
37 },
38}