From 4d0633923d1011e71ea4d8d4136c017e42a54c6d Mon Sep 17 00:00:00 2001 From: Tim van der Meij Date: Wed, 12 Aug 2015 23:37:19 +0200 Subject: [PATCH] Updates to make this easier to read and add a small introduction --- Style-Guide.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Style-Guide.md b/Style-Guide.md index 3419d34..7564ef6 100644 --- a/Style-Guide.md +++ b/Style-Guide.md @@ -1,15 +1,17 @@ +This page outlines the style conventions that PDF.js follows to maintain a consistent codebase. We ask each contributor that creates a pull request to adhere to these conventions. Some of these conventions will also be checked automatically by a linting tool after each push to a branch of a pull request. + ## General -* Indentation - 2 spaces -* Line Length - 80 characters -* [Required License in File Header](https://github.com/mozilla/pdf.js/wiki/License-Headers) +* Indentation: 2 spaces +* Line length: 80 characters +* Required license in header: see https://github.com/mozilla/pdf.js/blob/master/web/viewer.js#L1-L16 ## Naming -* Variables and functions - lowerCamelCase -* Constructor-like functions - UpperCamelCase -* Constants - ALL_UPPER_CASE_WITH_UNDERSCORES +* Variables and functions: lowerCamelCase +* Constructor-like functions: UpperCamelCase +* Constants: ALL_UPPER_CASE_WITH_UNDERSCORES ## Braces -* Always use braces and put them on same line, even for single line control statements. +Always use braces and put them on same line, even for single line control statements: ```javascript if (someVar) { @@ -19,15 +21,15 @@ if (someVar) { } ``` -## White Space -* Space after control statements (if, else, while, for, ...) +## White space +Keep one space after control statements (if, else, while, for, et cetera): ```javascript if (someVar) { ``` ## Equalities -* Use only strict equalities (and inequalities), e.g. +Use only strict equalities (`===`) and inequalities (`!==`): ```javascript if (someVar === conditionA) { @@ -38,8 +40,7 @@ if (someVar === conditionA) { ``` ## Variables - -Variables must be defined only once within a function scope. Preferably at the top of the function. +Variables must be defined only once within a function scope, preferably at the top of the function. ## Classes The standard way of creating classes in PDF.js is the following. Please note that by class we mean an object that is class-like. Also, note the naming of all anonymous functions.