1 |
|
2 |
|
3 |
|
4 | 'use strict'
|
5 |
|
6 | const getDocsUrl = require('./lib/get-docs-url')
|
7 |
|
8 | function isDeclared(scope, ref) {
|
9 | return scope.variables.some(variable => {
|
10 | if (variable.name !== ref.identifier.name) {
|
11 | return false
|
12 | }
|
13 |
|
14 | if (!variable.defs || !variable.defs.length) {
|
15 | return false
|
16 | }
|
17 |
|
18 | return true
|
19 | })
|
20 | }
|
21 |
|
22 | module.exports = {
|
23 | meta: {
|
24 | docs: {
|
25 | url: getDocsUrl('no-native')
|
26 | },
|
27 | messages: {
|
28 | name: '"{{name}}" is not defined.'
|
29 | }
|
30 | },
|
31 | create(context) {
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | return {
|
40 | 'Program:exit'() {
|
41 | const scope = context.getScope()
|
42 |
|
43 | scope.implicit.left.forEach(ref => {
|
44 | if (ref.identifier.name !== 'Promise') {
|
45 | return
|
46 | }
|
47 |
|
48 | if (!isDeclared(scope, ref)) {
|
49 | context.report({
|
50 | node: ref.identifier,
|
51 | messageId: 'name',
|
52 | data: { name: ref.identifier.name }
|
53 | })
|
54 | }
|
55 | })
|
56 | }
|
57 | }
|
58 | }
|
59 | }
|