Skip to content

Commit

Permalink
Using the AirBnB JavaScript style guide. Added JSCS and JSHint config…
Browse files Browse the repository at this point in the history
…s, as well as an editorconfig file.
  • Loading branch information
Kevin Renskers committed Apr 2, 2015
1 parent 5cf34d1 commit 3d39aa0
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 95 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true


[*]

# Change these settings to your own preference
indent_style = space
indent_size = 2

# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
67 changes: 67 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"disallowEmptyBlocks": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowQuotedKeysInObjects": true,
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpaceBeforeBinaryOperators": [
","
],
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"disallowYodaConditions": true,
"disallowKeywords": [ "with" ],
"disallowMultipleLineBreaks": true,
"disallowMultipleVarDecl": true,
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": true,
"requireBlocksOnNewline": 1,
"requireCommaBeforeLineBreak": true,
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceAfterBinaryOperators": true,
"requireCamelCaseOrUpperCaseIdentifiers": true,
"requireLineFeedAtFileEnd": true,
"requireCapitalizedConstructors": true,
"requireDotNotation": true,
"requireSpacesInForStatement": true,
"requireSpaceBetweenArguments": true,
"requireCurlyBraces": [
"do"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"case",
"return",
"try",
"catch",
"typeof"
],
"requirePaddingNewLinesBeforeLineComments": {
"allExcept": "firstAfterCurly"
},
"safeContextKeyword": "_this",
"validateLineBreaks": "LF",
"validateQuoteMarks": "'",
"validateIndentation": 2
}
101 changes: 101 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{

// --------------------------------------------------------------------
// JSHint Configuration, Strict Edition
// --------------------------------------------------------------------
//
// This is a options template for [JSHint][1], using [JSHint example][2]
// and [Ory Band's example][3] as basis and setting config values to
// be most strict:
//
// * set all enforcing options to true
// * set all relaxing options to false
// * set all environment options to false, except the browser value
// * set all JSLint legacy options to false
//
// [1]: http://www.jshint.com/
// [2]: https://github.com/jshint/node-jshint/blob/master/example/config.json
// [3]: https://github.com/oryband/dotfiles/blob/master/jshintrc
//
// @author http://michael.haschke.biz/
// @license http://unlicense.org/

// == Enforcing Options ===============================================
//
// These options tell JSHint to be more strict towards your code. Use
// them if you want to allow only a safe subset of JavaScript, very
// useful when your codebase is shared with a big number of developers
// with different skill levels.

"bitwise": true, // Prohibit bitwise operators (&, |, ^, etc.).
"curly": true, // Require {} for every new block or scope.
"eqeqeq": true, // Require triple equals i.e. `===`.
"forin": true, // Tolerate `for in` loops without `hasOwnPrototype`.
"immed": true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
"latedef": true, // Prohibit variable use before definition.
"newcap": true, // Require capitalization of all constructor functions e.g. `new F()`.
"noarg": true, // Prohibit use of `arguments.caller` and `arguments.callee`.
"noempty": true, // Prohibit use of empty blocks.
"nonew": true, // Prohibit use of constructors for side-effects.
"plusplus": true, // Prohibit use of `++` & `--`.
"regexp": true, // Prohibit `.` and `[^...]` in regular expressions.
"undef": true, // Require all non-global variables be declared before they are used.
"strict": true, // Require `use strict` pragma in every file.
"trailing": true, // Prohibit trailing whitespaces.
"quotmark": "single", // Enforce use of single quotation marks for strings.
"unused": true, // Warn when variables are defined but never used.
"maxlen": 120, // Enforce line length to 100 characters
"camelcase": true, // Force all variable names to use either camelCase style or UPPER_CASE with underscores.

// == Relaxing Options ================================================
//
// These options allow you to suppress certain types of warnings. Use
// them only if you are absolutely positive that you know what you are
// doing.

"asi": false, // Tolerate Automatic Semicolon Insertion (no semicolons).
"boss": false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
"debug": false, // Allow debugger statements e.g. browser breakpoints.
"eqnull": false, // Tolerate use of `== null`.
"es5": false, // Allow EcmaScript 5 syntax.
"esnext": false, // Allow ES.next specific features such as `const` and `let`.
"evil": false, // Tolerate use of `eval`.
"expr": false, // Tolerate `ExpressionStatement` as Programs.
"funcscope": false, // Tolerate declarations of variables inside of control structures while accessing them later from the outside.
"globalstrict": true, // Allow global "use strict" (also enables 'strict').
"iterator": false, // Allow usage of __iterator__ property.
"lastsemic": false, // Tolerat missing semicolons when the it is omitted for the last statement in a one-line block.
"laxbreak": false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
"laxcomma": false, // Suppress warnings about comma-first coding style.
"loopfunc": false, // Allow functions to be defined within loops.
"multistr": false, // Tolerate multi-line strings.
"onecase": false, // Tolerate switches with just one case.
"proto": false, // Tolerate __proto__ property. This property is deprecated.
"regexdash": false, // Tolerate unescaped last dash i.e. `[-...]`.
"scripturl": false, // Tolerate script-targeted URLs.
"smarttabs": false, // Tolerate mixed tabs and spaces when the latter are used for alignmnent only.
"shadow": false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
"sub": false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
"supernew": false, // Tolerate `new function () { ... };` and `new Object;`.
"validthis": false, // Tolerate strict violations when the code is running in strict mode and you use this in a non-constructor function.

// == Environments ====================================================
//
// These options pre-define global variables that are exposed by
// popular JavaScript libraries and runtime environments—such as
// browser or node.js.

"browser": true, // Standard browser globals e.g. `window`, `document`.
"couch": false, // Enable globals exposed by CouchDB.
"devel": false, // Allow development statements e.g. `console.log();`.
"dojo": false, // Enable globals exposed by Dojo Toolkit.
"jquery": false, // Enable globals exposed by jQuery JavaScript library.
"mootools": false, // Enable globals exposed by MooTools JavaScript framework.
"node": true, // Enable globals available when code is running inside of the NodeJS runtime environment.
"nonstandard": false, // Define non-standard but widely adopted globals such as escape and unescape.
"prototypejs": false, // Enable globals exposed by Prototype JavaScript framework.
"rhino": false, // Enable globals available when your code is running inside of the Rhino runtime environment.
"wsh": false, // Enable globals available when your code is running as a script for the Windows Script Host.

"indent": 2 // Specify indentation spacing
}
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Review the error and fix your RAML file, or open a new issue at [raml-js-parser]
raml2html is an open source project and your contribution is very much appreciated.

1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
2. Fork the repository on Github and make your changes on the **develop** branch (or branch off of it).
Please retain the code style that is used in the project.
2. Fork the repository on Github and make your changes on the **develop** branch (or branch off of it).
Please retain the [code style](https://github.com/airbnb/javascript) that is used in the project and `npm run lint` before committing.
3. Add an example of the new feature to example.raml (if applicable)
4. Send a pull request (with the **develop** branch as the target).

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ Review the error and fix your RAML file, or open a new issue at [raml-js-parser]
raml2html is an open source project and your contribution is very much appreciated.
1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
2. Fork the repository on Github and make your changes on the **develop** branch (or branch off of it).
Please retain the code style that is used in the project.
2. Fork the repository on Github and make your changes on the **develop** branch (or branch off of it).
Please retain the [code style](https://github.com/airbnb/javascript) that is used in the project and `npm run lint` before committing.
3. Add an example of the new feature to example.raml (if applicable)
4. Send a pull request (with the **develop** branch as the target).
Expand Down
23 changes: 11 additions & 12 deletions examples/script.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
'use strict';

/*
Example of using raml2html as a script.
Example of using raml2html as a script.
*/

var raml2html = require('../lib/raml2html');


// raml2html.render() needs a config object with at least a `template` property (a string or handlebars template object).
// raml2html.render() needs a config object with at least a `template` property (a string or handlebars template object)
// Instead of creating this config object ourselves, we can just ask for raml2html.getDefaultConfig():
var config1 = raml2html.getDefaultConfig();

raml2html.render('example.raml', config1, function(result) {
console.log('1: ', result.length);
console.log('1: ', result.length);
}, function(error) {
console.log('error! ', error);
console.log('error! ', error);
});


// If you want to use your own templates that follow the same structure, helpers and partials,
// you could do something like this:
var config2 = raml2html.getDefaultConfig(false, require('../lib/template.handlebars'));

raml2html.render('example.raml', config2, function(result) {
console.log('2: ', result.length);
console.log('2: ', result.length);
}, function(error) {
console.log('error! ', error);
console.log('error! ', error);
});


// If you want to customize everything, just create the config object yourself from scratch.
// Check raml2html.getDefaultConfig for the possible properties (https, helpers, partials, processOutput).
// The template property should be a string containing the template or a Handlebars template object.
var config3 = {
template: '<h1>Hello!</h1>'
template: '<h1>Hello!</h1>'
};

raml2html.render('example.raml', config3, function(result) {
console.log('3: ', result.length);
console.log('3: ', result.length);
}, function(error) {
console.log('error! ', error);
console.log('error! ', error);
});
Loading

0 comments on commit 3d39aa0

Please sign in to comment.