Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending jshint with custom checks

In the Python world there are multiple static code analysis tools that can be easily extended with custom checks via writing plugins or extensions, for example:

  • pylint
  • flake8

In the JavaScript world, as far as I understand, jshint is the number one tool for static code analysis. I've been using it for a while and it definitely helps to find lots of code style violations, but, recently, I've encountered the need to extend jshint with a custom check. How can I do that? Is it extendable?


I've looked through the documentation and the only thing I've found is how to write a custom reporter which is not what I'm looking for.

As a workaround, I guess I can fork the jshint repo, implement the check, and use the fork in the project maintaining updates from the upstream.

like image 427
alecxe Avatar asked Dec 03 '14 17:12

alecxe


People also ask

How can I customize the check report via extensions?

Here’s what I did to customize the check report via extensions: Duplicate the Cheque_US SSRS report to a model that extends the Application Suite model. I called my new report MyCheque_US and added some text to indicate that it was the custom report—that way I could tell at a glance if I was looking at the stock report or my custom report.

How does JSHint look for a file?

In case of .jshintrc, JSHint will start looking for this file in the same directory as the file that's being linted. If not found, it will move one level up the directory tree all the way up to the filesystem root.

How do The JSHint options work?

Trying to figure out how JSHint options work can be confusing and frustrating (and we're working on fixing that!) so please read the following couple of paragraphs carefully. JSHint has two types of options: enforcing and relaxing. The former are used to make JSHint more strict while the latter are used to suppress some warnings.

How do I Configure my JSHint warnings?

JSHint comes with a default set of warnings but it was designed to be very configurable. There are three main ways to configure your copy of JSHint: you can either specify the configuration file manually via the --config flag, use a special file.jshintrc or put your config into your projects package.json file under the jshintConfig property.


1 Answers

If I were you I would try to use something like ESLint. The ES stands for ECMAScript, which is where the rules for the JS language come from. Every single rule in ESLint is standalone (so you can use what you like), and you can use the default rules as a guideline or skeleton to create your own rule and plug it in.

Try ESLint.

like image 199
RadleyMith Avatar answered Sep 28 '22 09:09

RadleyMith