If you really want to add a global variable you have to add the variable to 
the global scope instead of the current scope.

module.exports = function(context) {
    var globalScope;

    return {
        Program: function () {
            globalScope = context.getScope();
        }

        ExpressionStatement: function(node) {
            var source = context.getSource(node);
            var matches = source.match(/^(?:Cu|
Components\.utils)\.import\(".*\/(\w+)\.\w+"\);?$/);

            if (matches) {
                var name = matches[1];

                var variables = globalScope.variables;
                var variable = new escope.Variable(name, scope);

                variable.eslintExplicitGlobal = false;
                variable.writeable = true;

                variables.push(variable);
            }
        }
    };
};



On Friday, May 22, 2015 at 12:29:41 PM UTC+2, Mike Ratcliffe wrote:
>
> This seems to work but is it the right way to do it?
>
> var escope = 
> require("/usr/local/lib/node_modules/eslint/node_modules/escope");
>
> module.exports = function(context) {
>     return {
>         ExpressionStatement: function(node) {
>             var source = context.getSource(node);
>             var matches = 
> source.match(/^(?:Cu|Components\.utils)\.import\(".*\/(\w+)\.\w+"\);?$/);
>
>             if (matches) {
>                 var name = matches[1];
>                 var scope = context.getScope();
>                 var variables = scope.variables;
>                 var variable = new escope.Variable(name, scope);
>
>                 variable.eslintExplicitGlobal = false;
>                 variable.writeable = true;
>
>                 variables.push(variable);
>             }
>         }
>     };
> };
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"ESLint" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to