JavaScript style guide support

Description of support

Pretty Diff offers some conformance support to the requirements of several popular style guides. The objective is to automate certain particular requirements of style guide conformance so that code authors can focus on more important things. Pretty Diff does not attempt to magically fix code to be 100% conformant to any style guide.

This support is provided by use of an option, styleguide to the prettydiff.js and jspretty.js libraries. When this option is passed with an accepted value the settings of other various options are overwritten. This forcefulness is intentional so that code is modified according to rules applied by a group setting in opposition to an individual's preferences.

If your organization has a style guide you would like represented by the Pretty Diff tool please open an issue on Github. Please include a link to the style guide documentation and any additional information or requests. All I ask in payment is your kind support in spreading awareness of this tool.

A styleguide setting can be automatically defined within the code without specifying anything in the Pretty Diff options. Setting the style guide in this way binds a setting to a code file and prevents interference from any potentially conflicting settings defined elsewhere. Assuming you wish to specify google as a style guide value just add a code comment like the following above the first line of code:

/* styleguide:google*/


Pretty Diff suggests use of something like JSCS to achieve complete conformance to a code style. The JSCS tool is a validator designed to yell at code authors when their code violates style rules and it does not alter a code sample. Using the style guide feature of Pretty Diff together with JSCS can help a code author to achieve 100% conformance to code style rules while allowing the code author to automate away many minor code style violations.

Manipulating code is risky business. Changing code can result in unplanned consequences they may alter or break the code from the author's intentions. Due to this risk there are certain alterations that Pretty Diff will intentionally not perform. In those cases a code author should be held accountable to make decisions about why code was written in a particular way. Here is an incomplete list of things Pretty Diff intentionally does not change.


Pretty Diff will not hoist or move around reference declarations in the code. References declared with the var are naturally hoisted by JavaScript interpreters, but references declared with the ES6 keyword let will not be hoisted. Moving around references declarations with let is a change in logic that can alter how a given set of code is interpreted.

Variable order

Pretty Diff will not reorder consecutively declared variables. This change can result in an error when one variable makes use of another variable at declaration time, and changing variable order in this case will break the code.

Logic sequence

Pretty Diff will not change the order or logic, except for trivial and predictable syntax changes. The one major exception to this rule is that Pretty Diff can alphabetize object properties.

Contributions and requests

If you have ideas for additional automation rules or rule sets please open a Github issue or submit a pull request.

Supported style guide rules

See the most current style guide definitions at the top of the jspretty.js file. The options present for each style guide rule follow the Pretty Diff options listed in the documentation.