-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jamund Ferguson
committed
May 25, 2016
1 parent
7b96139
commit 04c7005
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Borrowed from here: | ||
// https://github.com/colonyamerican/eslint-plugin-cah/issues/3 | ||
|
||
'use strict' | ||
|
||
module.exports = function (context) { | ||
var MESSAGE = '"{{name}}" is not defined.' | ||
|
||
/** | ||
* Checks for and reports reassigned constants | ||
* | ||
* @param {Scope} scope - an escope Scope object | ||
* @returns {void} | ||
* @private | ||
*/ | ||
function isDeclared (scope, ref) { | ||
return scope.variables.some(function (variable) { | ||
if (variable.name !== ref.identifier.name) { | ||
return false | ||
} | ||
|
||
if (!variable.defs || !variable.defs.length) { | ||
return false | ||
} | ||
|
||
return true | ||
}) | ||
} | ||
|
||
return { | ||
'Program:exit': function () { | ||
var scope = context.getScope() | ||
|
||
scope.through.forEach(function (ref) { | ||
if (ref.identifier.name !== 'Promise') { | ||
return | ||
} | ||
|
||
if (!isDeclared(scope, ref)) { | ||
context.report(ref.identifier, MESSAGE, { name: ref.identifier.name }) | ||
} | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict' | ||
|
||
var rule = require('../rules/no-native') | ||
var RuleTester = require('eslint').RuleTester | ||
|
||
var ruleTester = new RuleTester() | ||
ruleTester.run('no-native', rule, { | ||
valid: [ | ||
'var Promise = null; function x() { return Promise.resolve("hi"); }', | ||
'var Promise = window.Promise || require("bluebird"); var x = Promise.reject();' | ||
], | ||
|
||
invalid: [ | ||
{ | ||
code: 'new Promise(function(reject, resolve) { })', | ||
errors: [ { message: '"Promise" is not defined.' } ] | ||
}, | ||
{ | ||
code: 'Promise.resolve()', | ||
errors: [ { message: '"Promise" is not defined.' } ] | ||
} | ||
] | ||
}) |