Unfortunately, we cannot add variables while traversing, because other rules which are using variables are going to be confused. We should handle that before the scope analysis of ESLint.
As I mentioned in this issue[^1], maybe you can use the preprocessor of ESLint plugins. Or as @BYK mentioned, maybe you can use `babel-eslint` parser and your custom Babel plugin. [^1]: https://github.com/eslint/eslint/issues/3743#issuecomment-139790931 2016年2月25日(木) 19:10 Burak Yiğit Kaya <[email protected]>: > You can probably use BabelJS (with your plugin for Babel) to do this btw. > > On Thu, Feb 25, 2016 at 3:17 AM Nicholas Zakas <[email protected]> > wrote: > >> Sorry, we don't have a way for you to alter scope variables >> programmatically. >> >> On Wed, Feb 24, 2016, 5:12 PM Jérôme Odier <[email protected]> >> wrote: >> >>> Dear Nicholas, >>> >>> Thanks a lot for responding. I successfully wrote the new rule. It >>> detects my class factory call and extacts the class name (first parameter >>> of the factory function). From know, I would like to know how to >>> programmatically add a new global function (the new class) in the scope. Is >>> there a method to do that ? >>> >>> Best regard, >>> Jérôme >>> >>> >>> Le mercredi 24 février 2016 19:31:21 UTC+1, Nicholas Zakas a écrit : >>> >>>> Anything that can be determined using static analysis can be made into >>>> a rule. Here are the docs on creating your own rules: >>>> http://eslint.org/docs/developer-guide/working-with-rules >>>> >>>> -N >>>> >>> On Wed, Feb 24, 2016 at 7:31 AM Jérôme Odier <[email protected]> >>>> wrote: >>>> >>> Hi! >>>>> >>>>> I would like to know if it is possible and how to write a plugin for >>>>> supporting class factories. For instance, in our application, we do: >>>>> >>>>> $class('MyClass', { >>>>> >>>>> foo: function() { >>>>> >>>>> }, >>>>> >>>>> bar: function() { >>>>> >>>>> } >>>>> >>>>> }); >>>>> >>>>> var myInstance = new MyClass(); >>>>> >>>>> Thanks a lot for your help. >>>>> >>>>> Best regards >>>>> >>>>> -- >>>>> 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. >>>>> >>>> -- >>> 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. >>> >> -- >> 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. >> > -- > 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. > -- 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.
