eslint-plugin-flow-vars
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "eslint-plugin-flow-vars", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Solves the problem of false positives with `no-undef` and `no-unused-vars` when using babel-eslint", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
'use strict'; | ||
module.exports = function(context) { | ||
var imported = Object.create(null); | ||
var types = Object.create(null); | ||
function markUsedIfType(ident) { | ||
if (types[ident.name]) { | ||
context.markVariableAsUsed(ident.name); | ||
types[ident.name] = null; | ||
} | ||
} | ||
function markTypeAsUsed(node) { | ||
context.markVariableAsUsed(node.id.name); | ||
} | ||
function markUsedIfImported(ident) { | ||
if (imported[ident.name]) { | ||
context.markVariableAsUsed(ident.name); | ||
imported[ident.name] = null; | ||
} | ||
} | ||
return { | ||
@@ -23,11 +23,14 @@ DeclareClass: markTypeAsUsed, | ||
var specifier = node.specifiers[i]; | ||
imported[specifier.local.name] = true; | ||
types[specifier.local.name] = true; | ||
} | ||
} | ||
}, | ||
TypeAlias: function(node) { | ||
types[node.id.name] = true; | ||
}, | ||
GenericTypeAnnotation: function(node) { | ||
if (node.id.type === 'Identifier') { | ||
markUsedIfImported(node.id); | ||
markUsedIfType(node.id); | ||
} else if (node.id.type === 'QualifiedTypeIdentifier') { | ||
markUsedIfImported(node.id.qualification); | ||
markUsedIfType(node.id.qualification); | ||
} | ||
@@ -34,0 +37,0 @@ } |
3804
88