javascriptnode.jseslintcomments

Can I create an eslint comment that is interpreted as an error?


We have branch protection and pre-push hooks in our system that force us to have no eslint errors or warnings in order to push to main/master.

Sometimes, while debugging something, I will modify a parameter in the code to make debugging easier. For instance, a timeout in a network resource would normally trigger while I'm debugging, so I either disable it or make the timeout very large.

The problem is I know one of these days I'm going to forget I did that and my temporary change will make its way into the code despite everyone's well-intentioned code reviews.

I'm thinking it would be great if I could add a comment at the line where I spiked the setting that would force an eslint error and prevent me from pushing my branch.

Something like:

// eslint-force-error DON'T LET ME CHECK THIS IN!!!!
network.timeout = 1000000; // 1000;

Before I can push, I would have to pay attention to this, and that's when I revert these two lines and rest easy that I didn't break something that shows up much later.

I don't think eslint has something precisely like this, but is there some meta-behavior with some other comment I can take advantage of?


Solution

  • You can use the no-warning-comments rule, and configure it to a list of prefixes you want to disallow in your comments. E.g.:

     "rules": {
        "no-warning-comments": ["error", {"terms": ["FIXME", "NOPE"]}]
     }