UNPKG

867 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 docs: {
9 url: getDocsUrl('no-new-statics')
10 },
11 fixable: 'code'
12 },
13 create(context) {
14 return {
15 NewExpression(node) {
16 if (
17 node.callee.type === 'MemberExpression' &&
18 node.callee.object.name === 'Promise' &&
19 PROMISE_STATICS[node.callee.property.name]
20 ) {
21 context.report({
22 node,
23 message: "Avoid calling 'new' on 'Promise.{{ name }}()'",
24 data: { name: node.callee.property.name },
25 fix(fixer) {
26 return fixer.replaceTextRange(
27 [node.start, node.start + 'new '.length],
28 ''
29 )
30 }
31 })
32 }
33 }
34 }
35 }
36}