<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 5, 2015 at 5:52 AM, Mark Banner <span dir="ltr"><<a href="mailto:mbanner@mozilla.com" target="_blank">mbanner@mozilla.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="">On 04/12/2015 19:15, Patrick Brosset wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I just discovered the concept of pre-processors in eslint, I had no idea this even existed. Find out more info here:<br>
<a href="http://eslint.org/docs/developer-guide/working-with-plugins#processors-in-plugins" rel="noreferrer" target="_blank">http://eslint.org/docs/developer-guide/working-with-plugins#processors-in-plugins</a><br>
<br>
tl;dr;<br>
We can use this to process our source files before eslint rules are run on them.<br>
So, in particular, we can do things like:<br>
- filter out ifdef instructions,<br>
- define global variables from imported modules (from e.g. Cu.import)<br>
</blockquote></span>
There's already at least a partial plugin for Cu.import and friends:<br>
<br>
<a href="http://mxr.mozilla.org/mozilla-central/source/testing/eslint-plugin-mozilla/lib/rules/" rel="noreferrer" target="_blank">http://mxr.mozilla.org/mozilla-central/source/testing/eslint-plugin-mozilla/lib/rules/</a><span class=""><font color="#888888"><br>
<br></font></span></blockquote><div><br></div><div>Yes I know this particular rule. I think it'd be good to remove it though, and use a pre-processor instead because:<br></div><div><br>- Rules are normally supposed to output messages (actually check code) rather than change the environment (in this case, by declaring a new global variable for the Cu.import). This isn't a big problem in itself, but still it forces you to make sure that rule runs first.<br></div><div>- Adding variables to the ESLint's scope while it runs is hacky, it relies on unsupported internal APIs, and I've had to fix this last week already (bug 1230093).<br><br></div><div>Using a pre-processor instead makes it possible to re-write code before the rules are executed, and so we can use this to replace things eslint doesn't understand as variable declarations with actual variable declarations.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class=""><font color="#888888">
Mark.</font></span><div class=""><div class="h5"><br>
_______________________________________________<br>
firefox-dev mailing list<br>
<a href="mailto:firefox-dev@mozilla.org" target="_blank">firefox-dev@mozilla.org</a><br>
<a href="https://mail.mozilla.org/listinfo/firefox-dev" rel="noreferrer" target="_blank">https://mail.mozilla.org/listinfo/firefox-dev</a><br>
</div></div></blockquote></div><br></div></div>