Thank you so much for the quick reply! :) I'll have to take a peek at how much metadata is provided by these methods. Seems like there are a few ways to tackle this rule:
1. getSource on first function ancestor and make sure all "var"s are at the top and ensuring each line preceded by a ";" starts with "var". 2. getSource on first function ancestor and make sure all scoped variables returned by getScope are at the top. 3. Use a theoretical getSiblingStatement and make sure all previous statements are "var"s. 4. Something I haven't thought of. Any advice on what might be the best approach? Danny On Wednesday, March 12, 2014 11:16:34 AM UTC-5, Ilya Volodin wrote: > > Context and all of the methods under it is something specific to ESLint. > There's a RuleContext.js file that sets up context and define some of the > methods. Others are defined directly in eslint.js. You can take a look at > other rules to get an example of usage of some of the methods in context, > but in short: > getScope - retrieve scope of the current program, this is retrieved by > EScope (https://github.com/Constellation/escope) > getSource - retrieve a string with source code of the node (+/- some > characters) > getAncestors - retrieves a list of parent AST nodes for a given node. > > Thanks, > > Ilya Volodin > > On Tuesday, March 11, 2014 8:47:35 PM UTC-4, Danny Fritz wrote: > >> I'm trying to create a rule to enforce all vars are specified at the top >> of the functional scope. This is very similar to one-var, but allows more >> than one var as long as they are all at the top. >> >> Here is a blog post on the issue. >> http://danielhough.co.uk/blog/single-var-pattern-rant/ >> >> I'm having a really hard to figuring out how to create a custom rule >> follwoing this: >> http://eslint.org/docs/developer-guide/working-with-rules.html. I have >> the basic framework setup and am running tests on my custom rule, but I am >> very confused about what the various `context` methods do. I'm seeing >> `getScope`, `getSource`, `getAncestors`, among others. Are these defined in >> AST or ESLint? >> >> Any help appreciated. >> >> Danny >> > -- 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.
