Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tooling JavaScript to ensure consistency in cod...

Tooling JavaScript to ensure consistency in coding style

These slides inllustrate what are coding style, conventions and standards, why they matter and how to use JS_CodeSniffer to check tat your code doesn't violates given coding standard

Dmitry Sheiko

August 27, 2014
Tweet

More Decks by Dmitry Sheiko

Other Decks in Programming

Transcript

  1. Coding conventions mean guidelines for a specific programming language that

    recommend programming style indentation comments white-spaces naming conventions etc.
  2. 
 jQuery JavaScript 
 Style Guide 
 Idiomatic.js 
 Dojo

    Style Guide
 
 Google JavaScript 
 Style Guide
  3. Code conventions improve the readability and maintainability of the software,

    enabling engineers to understand the code more quickly
  4. Linter is to detect the code that may cause potential

    problems. To check the coding style one needs a code sniffer.
  5. Get detailed report on a target (file or directory) coding

    style according to jQuery JavaScript Style Guide:
 $jscs ./js/source/main.js --standard=Jquery 
 --report-full
  6. Get a report suitable for Jenkins CI-server:
 $jscs ./js/source --standard=Jquery

    — report=checkstyle —report-file=./build/ checkstyle.xml
  7. 1. Take a rule-set file in ./standard directory 2. Copy

    it under the name of your custom standard (MyConventions) 3. Modify the JSON to fulfil your requirements
  8. Place in the root of the project file .jscsrc:
 {

    "Indentation": false, "QuoteConventions": false }
  9. Apache Ant setup:
 
 <target name="jscs-ci" description="Find coding standard violations

    using JS_CodeSniffer and print human readable output."> <exec executable="jscs"> <arg value="--standard=Jquery" /> <arg value="--report=checkstyle" /> <arg value="--report-file=${basedir}/build/logs/checkstyle.xml" /> <arg path="${basedir}/src" /> </exec> </target>