Ah, OK, it only works when I specify a rule in the /* eslint-disable */
block. Seems fishy:

    /*eslint-disable */
    var Baz = 3;
    /* eslint-enable */

Gives me this (which is bad):
    $ eslint --rulesdir rules app.js; echo $?
    0


But...

    /*eslint-disable no-unused-vars */
    var Baz = 3;
    /* eslint-enable */

Gives me this (which is good):
    $ eslint --rulesdir rules app.js; echo $?

    app.js
      12:0  error  Unexpected `eslint-disable` in content  no-eslint-disable
      14:0  error  Unexpected `eslint-enable` in content   no-eslint-disable

    ✖ 2 problems

    1


On Thu, Sep 25, 2014 at 2:02 PM, Peter deHaan <[email protected]> wrote:

> That gives me:
>
> $ DEBUG=eslint:* eslint --rulesdir rules app.js
>   eslint:cli-engine Loading rules from rules +0ms
>   eslint:cli-engine Processing app.js +8ms
>   eslint:cli-engine Linting /Users/pdehaan/dev/tmp/eslint-custom/app.js
> +0ms
>   eslint:config Constructing config for
> /Users/pdehaan/dev/tmp/eslint-custom/app.js +1ms
>   eslint:config Using .eslintrc files +0ms
>   eslint:config Using /Users/pdehaan/dev/tmp/eslint-custom/.eslintrc +0ms
>   eslint:config Merging command line environment settings +4ms
> errata! `eslint-disable`
> errata! `eslint-enable`
>
> app.js
>   5:4  error  foo is defined but never used  no-unused-vars
>
> ✖ 1 problem
>
>
> It's a bit perplexing.
> My console log works, but not the context.report(). The context.report()
> works if I move it outside of that `if` block, but then obviously throws
> too many warnings (naturally)...
>
> OK, I think I sorted it out. It just doesn't work.
> Changing my source code (and rule) from "eslint-disable" to
> "fslint-disable" makes it work as expected, and now I get this:
>
>   12:0   error  Unexpected `eslint-disable` or `eslint-enable` in content
>  no-eslint-disable
>   14:0   error  Unexpected `eslint-disable` or `eslint-enable` in content
>  no-eslint-disable
>
>
> :shrug:
>
>
> On Thu, Sep 25, 2014 at 1:41 PM, Nicholas Zakas <
> [email protected]> wrote:
>
>> Try running with
>>
>> ```
>> $ DEBUG=eslint:* eslint --rulesdir rules app.js
>> ```
>>
>> And see what info you find.
>>
>> On Thu, Sep 25, 2014 at 12:37 PM, Peter deHaan <[email protected]>
>> wrote:
>>
>>> Hello,
>>>
>>> I'm trying to create a custom ESLint rule (v0.8.2) which prevents the
>>> use of /* eslint-disable */ comments, but for some reason my
>>> context.report() is not reporting violations as errors/warnings.
>>> Does anybody have a couple minutes to take a look?
>>>
>>> My .eslintrc file is pretty simple:
>>>
>>> env:
>>>   node: true
>>> rules:
>>>   no-alert: 1
>>>   no-eslint-disable: 2
>>>
>>>
>>>
>>> My rules/no-eslint-disable.js is:
>>>
>>> "use strict";
>>> module.exports = function (context) {
>>>   var eslintEnableDisable = /^eslint-(enable|disable)/;
>>>
>>>   function checkComment(node) {
>>>     var value = node.value.trim();
>>>     if (eslintEnableDisable.test(value)) {
>>>       context.report(node, "Unexpected `eslint-disable` or `eslint-enable` 
>>> in content.");
>>>       console.error("errata!");
>>>     }
>>>   }
>>>
>>>   return {
>>>     "BlockComment": checkComment,
>>>     "LineComment": checkComment
>>>   };};
>>>
>>>
>>>
>>> My app.js test case is:
>>>
>>> /** * This is a copyright header. */
>>> var foo = "bar"; // nice var bro
>>> /*and a regular doc comment which may span multiple lines or include 
>>> commented out code.var bar = "foo"; // circular much? */
>>> /* eslint-disable */var window = alert;/* eslint-enable */
>>>
>>>
>>>
>>> When I run ESLint with my custom rule, I see my console.error()s but not
>>> the warnings/errors via context.report().
>>>
>>> $ eslint --rulesdir rules app.js
>>> errata! `eslint-disable`
>>> errata! `eslint-enable`
>>>
>>> app.js
>>>   5:4  error  foo is defined but never used  no-unused-vars
>>>
>>> ✖ 1 problem
>>>
>>> $ eslint -v # v0.8.2
>>>
>>> --
>>> 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.
>>>
>>
>>
>>
>> --
>>
>> ______________________________
>> Nicholas C. Zakas
>> @slicknet
>>
>> Author, Professional JavaScript for Web Developers
>> Buy it at Amazon.com:
>> http://www.amazon.com/Professional-JavaScript-Developers-Nicholas-Zakas/dp/1118026691/ref=sr_1_3
>>
>
>

-- 
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