Release 0.4 – Including eslint in npm test on Mozilla Thimble

For release 0.4 I decided to work on issue 1921 in Mozilla Thimble.

The issue was that the grunt task that runs when you run npm test only ran jshint. This doesn’t do enough style profiling. We needed to add eslint in order to catch style errors that contributors might miss.

I fixed this issue by first installing grunt-eslint. After that I needed to modify the Gruntfile.js file to include the eslint task. I included the files that should be checked by eslint when npm test runs.

Here is how the eslint task looks in the Gruntfile.js file:

Screen Shot 2017-04-15 at 3.27.20 AM.png

In the .eslintrc.json file I added the rules that we needed to use. The only rule that I added was the indent rule. I specified that the indent of the files needed to be 2 spaces. I used the eslint indent rule to see how to turn the indent rule on and specify 2 spaces. Of course in the future many other rules can be added to this file as needed. All the eslint rules are available here: http://eslint.org/docs/rules/.

I also specified the ecmaVersion for the parser to be 6. I needed to include this in the .eslintrc.json file because if it is not there it will give many parsing errors like the keyword let is reserved and const is reserved.

Here is how the .eslintrc.json file looks:

Screen Shot 2017-04-15 at 3.26.19 AM.png

My pull request is available here: https://github.com/mozilla/thimble.mozilla.org/pull/1971 

In conclusion, I learnt that installing eslint for Mozilla Thimble was a similar process as how we installed eslint in lab 6. The difference here was that I needed to include the eslint task in the Gruntfile.js file. Using eslint in Mozilla Thimble will be very useful for future contributors since it checks their code style and warns if anything needs to be fixed. This can be especially useful for contributors that forget to use 2 spaces for indentation.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s