From 1e718fc6fc036127034531fe1e3f7c1d067d72b9 Mon Sep 17 00:00:00 2001 From: theghostbel Date: Mon, 16 Mar 2015 12:39:55 +0200 Subject: [PATCH 1/3] Update README.md --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 99e286d73b..b2cd0c39dd 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,7 @@ -[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/airbnb/javascript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) - -# Airbnb JavaScript Style Guide() { +# Tallink JavaScript Style Guide() { *A mostly reasonable approach to JavaScript* - ## Table of Contents 1. [Types](#types) From 3c4bde76e72baffd22d331b733eeac82fa80983e Mon Sep 17 00:00:00 2001 From: theghostbel Date: Wed, 25 Mar 2015 08:25:46 +0200 Subject: [PATCH 2/3] Use self as this --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b2cd0c39dd..144ceaa4ad 100644 --- a/README.md +++ b/README.md @@ -1161,12 +1161,12 @@ this._firstName = 'Panda'; ``` - - When saving a reference to `this` use `_this`. + - When saving a reference to `this` use `self`. ```javascript // bad function() { - var self = this; + var _this = this; return function() { console.log(self); }; @@ -1182,9 +1182,9 @@ // good function() { - var _this = this; + var self = this; return function() { - console.log(_this); + console.log(self); }; } ``` From ae0ce26226cacaad507069dd798c0a399c215cee Mon Sep 17 00:00:00 2001 From: Victor Rusakovich Date: Mon, 30 Mar 2015 10:49:29 +0300 Subject: [PATCH 3/3] Updated config, added examples --- linters/jshintrc => .jshintrc | 9 +-- README.md | 5 ++ examples.js | 24 ++++++ .../SublimeLinter.sublime-settings | 73 ------------------- package.json | 16 ++-- 5 files changed, 40 insertions(+), 87 deletions(-) rename linters/jshintrc => .jshintrc (89%) create mode 100644 examples.js delete mode 100644 linters/SublimeLinter/SublimeLinter.sublime-settings diff --git a/linters/jshintrc b/.jshintrc similarity index 89% rename from linters/jshintrc rename to .jshintrc index cc6e398b40..5479b85063 100644 --- a/linters/jshintrc +++ b/.jshintrc @@ -49,11 +49,6 @@ // Warn when variables are defined but never used. "unused": true, - /* - * RELAXING OPTIONS - * ================= - */ - - // Suppress warnings about == null comparisons. - "eqnull": true + // This option requires all for in loops to filter object's items. + "forin": true } diff --git a/README.md b/README.md index 144ceaa4ad..1a304065ce 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # Tallink JavaScript Style Guide() { +*How to use?* + +Clone this repo, run "npm install" and then "gulp lint". You'll get errors from examples.js, where some of examples of +wrong code usage are collected. + *A mostly reasonable approach to JavaScript* ## Table of Contents diff --git a/examples.js b/examples.js new file mode 100644 index 0000000000..c1ba0a184c --- /dev/null +++ b/examples.js @@ -0,0 +1,24 @@ +x = true; +var not_a_camel_case = null; +if (not_a_camel_case == null) window.alert(x); + +var justResult = justAFunction({x: true}); + +function justAFunction(obj) { + var result = z + 1; + var z = result + "wrong quotes"; + + for (globalKey in obj) { + // no if => argues + z = globalKey; + } + + for (var localKey in obj) { + if (obj.hasOwnProperty(localKey)) { + // has if => passes + z = lateDefFunction(localKey); + } + } + + var lateDefFunction = function() {} +} diff --git a/linters/SublimeLinter/SublimeLinter.sublime-settings b/linters/SublimeLinter/SublimeLinter.sublime-settings deleted file mode 100644 index 12360f3f1c..0000000000 --- a/linters/SublimeLinter/SublimeLinter.sublime-settings +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Airbnb JSHint settings for use with SublimeLinter and Sublime Text 2. - * - * 1. Install SublimeLinter at https://github.com/SublimeLinter/SublimeLinter - * 2. Open user preferences for the SublimeLinter package in Sublime Text 2 - * * For Mac OS X go to _Sublime Text 2_ > _Preferences_ > _Package Settings_ > _SublimeLinter_ > _Settings - User_ - * 3. Paste the contents of this file into your settings file - * 4. Save the settings file - * - * @version 0.3.0 - * @see https://github.com/SublimeLinter/SublimeLinter - * @see http://www.jshint.com/docs/ - */ -{ - "jshint_options": - { - /* - * ENVIRONMENTS - * ================= - */ - - // Define globals exposed by modern browsers. - "browser": true, - - // Define globals exposed by jQuery. - "jquery": true, - - // Define globals exposed by Node.js. - "node": true, - - /* - * ENFORCING OPTIONS - * ================= - */ - - // Force all variable names to use either camelCase style or UPPER_CASE - // with underscores. - "camelcase": true, - - // Prohibit use of == and != in favor of === and !==. - "eqeqeq": true, - - // Suppress warnings about == null comparisons. - "eqnull": true, - - // Enforce tab width of 2 spaces. - "indent": 2, - - // Prohibit use of a variable before it is defined. - "latedef": true, - - // Require capitalized names for constructor functions. - "newcap": true, - - // Enforce use of single quotation marks for strings. - "quotmark": "single", - - // Prohibit trailing whitespace. - "trailing": true, - - // Prohibit use of explicitly undeclared variables. - "undef": true, - - // Warn when variables are defined but never used. - "unused": true, - - // Enforce line length to 80 characters - "maxlen": 80, - - // Enforce placing 'use strict' at the top function scope - "strict": true - } -} diff --git a/package.json b/package.json index 2fe47fb268..9c49a6ea92 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "airbnb-style", + "name": "tallink-js-code-style", "version": "1.0.0", "description": "A mostly reasonable approach to JavaScript.", "scripts": { @@ -7,17 +7,19 @@ }, "repository": { "type": "git", - "url": "https://github.com/airbnb/javascript.git" + "url": "https://github.com/theghostbel/js-code-style.git" }, "keywords": [ "style guide", "lint", - "airbnb" + "talink" ], "author": "Harrison Shoff (https://twitter.com/hshoff)", "license": "MIT", - "bugs": { - "url": "https://github.com/airbnb/javascript/issues" - }, - "homepage": "https://github.com/airbnb/javascript" + "homepage": "https://github.com/theghostbel/js-code-style", + "devDependencies": { + "gulp": "^3.8.11", + "gulp-jshint": "^1.9.4", + "jshint-stylish": "^1.0.1" + } }