{"id":2341,"date":"2018-01-21T23:48:38","date_gmt":"2018-01-22T04:48:38","guid":{"rendered":"http:\/\/osric.com\/chris\/accidental-developer\/?p=2341"},"modified":"2018-01-21T23:48:38","modified_gmt":"2018-01-22T04:48:38","slug":"using-jshint-with-travis-ci","status":"publish","type":"post","link":"https:\/\/osric.com\/chris\/accidental-developer\/2018\/01\/using-jshint-with-travis-ci\/","title":{"rendered":"Using jshint with Travis CI"},"content":{"rendered":"<p>I thought I&#8217;d give <a href=\"https:\/\/travis-ci.org\/\">Travis CI<\/a> a try. It&#8217;s a tool that hooks into GitHub and runs automated tests on your code every time you push a commit. I found a <a href=\"https:\/\/github.com\/dwyl\/learn-travis\">straightforward tutorial<\/a> that basically said I&#8217;d need 2 files in addition to my existing code:<\/p>\n<ol>\n<li><code>.travis.yml<\/code><\/li>\n<li><code>package.json<\/code><\/li>\n<\/ol>\n<p>Simple! I configured Travis CI to run <a href=\"http:\/\/jshint.com\/\">JSHint<\/a> (a Javascript code linter, similar to <a href=\"http:\/\/jslint.com\/\">JSLint<\/a>) on the Javascript files in my <a href=\"https:\/\/github.com\/cherdt\/simple-steganography\">Simple Steganography<\/a> project.<\/p>\n<p>I pushed a commit and discovered my files did not pass JSHint. However, I thought they should be. My files were previously configured for JSLint, and JSHint can read JSLint directives. At the top of my Javascript files I had the directives:<\/p>\n<p><code>\/*jslint<br \/>\n    bitwise, browser<br \/>\n*\/<\/code><\/p>\n<p>These indicate that bitwise operators should be allowed, and to assume the code is running in a web browser.<\/p>\n<p>JSHint (via Travis-CI) reported the following errors:<\/p>\n<p><code>js\/decode.js: line 3, col 1, Bad option value.<br \/>\njs\/decode.js: line 3, col 1, Bad option value.<\/code><\/p>\n<p>The <a href=\"http:\/\/jshint.com\/docs\/#inline-configuration\">JSHint docs on inline configuration<\/a> indicate that the formatting should be <code>option: Boolean<\/code>, so I reformatted the configuration directives:<\/p>\n<p>\/*jslint<br \/>\n    bitwise: false,<br \/>\n    browser: true<br \/>\n*\/<\/p>\n<p>JSHint (via Travis-CI) reported several errors regarding bitwise operators:<\/p>\n<p><code>js\/encode.js: line 179, col 37, Unexpected use of '&amp;'.<br \/>\njs\/encode.js: line 179, col 42, Unexpected use of '^'.<br \/>\njs\/encode.js: line 179, col 53, Unexpected use of '&amp;'.<br \/>\njs\/encode.js: line 180, col 51, Unexpected use of '|'.<br \/>\njs\/encode.js: line 182, col 51, Unexpected use of '&amp;'.<\/code><\/p>\n<p>I changed the JSHint configuration directives to:<\/p>\n<p>\/*jslint<br \/>\n    bitwise: true,<br \/>\n    browser: true<br \/>\n*\/<\/p>\n<p>This worked, and my JSHint tests passed! I added a build status image to my GitHub repo:<br \/>\n<img decoding=\"async\" src=\"https:\/\/travis-ci.org\/cherdt\/simple-steganography.svg?branch=master\" alt=\"GitHub build status for Simple Steganography project\" \/><\/p>\n<p>The page describing the <a href=\"http:\/\/jshint.com\/docs\/options\/\">JSHint Options<\/a> definitely leads me to believe that <em>enabling<\/em> the bitwise option would <em>enforce<\/em> bitwise errors. This is the opposite of the behavior I&#8217;m seeing. The problem is either with the documentation, the behavior, or my reading comprehension! I opened <a href=\"https:\/\/github.com\/jshint\/jshint\/issues\/3242\">a GitHub issue on the JSHint project<\/a> describing what I experienced.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I thought I&#8217;d give Travis CI a try. It&#8217;s a tool that hooks into GitHub and runs automated tests on your code every time you push a commit. I found a straightforward tutorial that basically said I&#8217;d need 2 files in addition to my existing code: .travis.yml package.json Simple! I configured Travis CI to run &hellip; <a href=\"https:\/\/osric.com\/chris\/accidental-developer\/2018\/01\/using-jshint-with-travis-ci\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Using jshint with Travis CI<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[56],"tags":[482,479,480,481],"class_list":["post-2341","post","type-post","status-publish","format-standard","hentry","category-testing","tag-github","tag-jshint","tag-jslint","tag-travis-ci"],"_links":{"self":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/2341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/comments?post=2341"}],"version-history":[{"count":4,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/2341\/revisions"}],"predecessor-version":[{"id":2346,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/posts\/2341\/revisions\/2346"}],"wp:attachment":[{"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/media?parent=2341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/categories?post=2341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/osric.com\/chris\/accidental-developer\/wp-json\/wp\/v2\/tags?post=2341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}