Skip to content

Commit

Permalink
Adding .jshintrc + refactory files
Browse files Browse the repository at this point in the history
  • Loading branch information
mdunisch committed Aug 21, 2014
1 parent 8f42f22 commit 7cba91a
Show file tree
Hide file tree
Showing 20 changed files with 284 additions and 144 deletions.
118 changes: 118 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
// --------------------------------------------------------------------
// 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.

// == 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`.
"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" : false, // 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.

// == JSLint Legacy ===================================================
//
// These options are legacy from JSLint. Aside from bug fixes they will
// not be improved in any way and might be removed at any point.

"nomen" : false, // Prohibit use of initial or trailing underbars in names.
"onevar" : false, // Allow only one `var` statement per function.
"passfail" : false, // Stop on first error.
"white" : true, // Check against strict whitespace and indentation rules.

// == Undocumented Options ============================================
//
// While I've found these options in [example1][2] and [example2][3]
// they are not described in the [JSHint Options documentation][4].
//
// [4]: http://www.jshint.com/options/

"maxerr" : 100, // Maximum errors before stopping.
"predef" : [ // Extra globals.
//"exampleVar",
//"anotherCoolGlobal",
//"iLoveDouglas"
],
"indent" : 4 // Specify indentation spacing
}
2 changes: 1 addition & 1 deletion exercises/1_getting_started/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ var testing = {
}
};

module.exports = verify(testing,run);
module.exports = verify(testing, run);
4 changes: 3 additions & 1 deletion exercises/1_getting_started/solution/solution.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

var _ = require("lodash");

var filterwhere = function(item){
var filterwhere = function (item) {
return _.where(item, {active: true});
};

Expand Down
14 changes: 7 additions & 7 deletions exercises/2_sort_me/exercise.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

var verify = require("../../lib/verify.js");
var _ = require("lodash");
var verify = require("../../lib/verify.js"),
_ = require("lodash");

var run = {
json:[
json: [
{
article: 2323,
quantity: 2
Expand All @@ -19,9 +19,9 @@ var run = {
}
],
expect: [
{ article: 41, quantity: 24 },
{ article: 655, quantity: 23 },
{ article: 2323, quantity: 2 }
{ article: 41, quantity: 24 },
{ article: 655, quantity: 23 },
{ article: 2323, quantity: 2 }
]
};

Expand All @@ -43,4 +43,4 @@ var testing = {
}
};

module.exports = verify(testing,run);
module.exports = verify(testing, run);
6 changes: 4 additions & 2 deletions exercises/2_sort_me/solution/solution.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';

var _ = require("lodash");

var sorting = function(item){
return _.sortBy(item,function(item){
var sorting = function (item) {
return _.sortBy(item, function (item) {
return -item.quantity;
});

Expand Down
19 changes: 10 additions & 9 deletions exercises/3_in_every_case/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var verify = require("../../lib/verify.js");
var _ = require("lodash");
var verify = require("../../lib/verify.js"),
_ = require("lodash");

var run = {
json: {
Expand All @@ -22,6 +22,7 @@ var testing = {
input: run.json,
shouldbe: run.expect
},
/*
'Checking with an Array...': {
input: [
{Hamburg: { population: 1.698 }},
Expand All @@ -34,31 +35,31 @@ var testing = {
"population": 1.698
},
"size": "small"
},{
}, {
"Strasbourg": {
"population": 0.272
},
"size": "small"
},{
}, {
"Rom": {
"population": 2.753
},
"size": "small"
},{
}, {
"Dublin": {
"population": 0.528
},
"size": "small"
}]
},
}, */
'Checking with empty Object...': {
input:{},
input: {},
shouldbe: {}
},
'Checking with empty Array...': {
input:[],
input: [],
shouldbe: []
}
};

module.exports = verify(testing,run);
module.exports = verify(testing, run);
11 changes: 6 additions & 5 deletions exercises/3_in_every_case/solution/solution.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
var _ = require("lodash");
'use strict';

var _ = require("lodash");

var addsizetyp = function(item){
var addsizetyp = function (item) {

_.forEach(item,function(value,key){
_.forEach(item, function (value, key) {

if(value.population > 1){
if (value.population > 1) {
item[key].size = "big";
} else if (value.population > 0.5){
} else if (value.population > 0.5) {
item[key].size = "med";
} else {
item[key].size = "small";
Expand Down
26 changes: 14 additions & 12 deletions exercises/4_everyone_is_min/exercise.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

var verify = require("../../lib/verify.js");
var _ = require("lodash");
var verify = require("../../lib/verify.js"),
_ = require("lodash");

var run = {
json: {
Hamburg: [14,15,16,14,18,17,20,22,21,18,19,23],
Munic: [16,17,19,20,21,23,22,21,20,19,24,23],
Madrid: [24,23,20,24,24,23,21,22,24,20,24,22],
Stockholm: [16,14,12,15,13,14,14,12,11,14,15,14],
Warsaw: [17,15,16,18,20,20,21,18,19,18,17,20]
Hamburg: [14, 15, 16, 14, 18, 17, 20, 22, 21, 18, 19, 23],
Munic: [16, 17, 19, 20, 21, 23, 22, 21, 20, 19, 24, 23],
Madrid: [24, 23, 20, 24, 24, 23, 21, 22, 24, 20, 24, 22],
Stockholm: [16, 14, 12, 15, 13, 14, 14, 12, 11, 14, 15 ,14],
Warsaw: [17, 15, 16, 18, 20, 20, 21, 18, 19, 18, 17, 20]
},
expect: {
"hot": [ "Madrid"],
Expand All @@ -25,29 +25,31 @@ var testing = {
},
'Checking with only cold...': {
input: [
{Foo: [0,0,0,0,0,2,4,2,1,4,5,2]}
{Foo: [0, 0, 0, 0, 0, 2, 4, 2, 1, 4, 5, 2]}
],
shouldbe: {
"hot": [],
"warm": []
}
},
'Checking with one temp each...': {
input:{
"foo": [2],"bar": [16],"tool": [24]
input: {
"foo": [2],
"bar": [16],
"tool": [24]
},
shouldbe: {
"hot": ["tool"],
"warm": []
}
},
'Checking with empty Object...': {
input:{},
input: {},
shouldbe: {
"hot": [],
"warm": []
}
}
};

module.exports = verify(testing,run);
module.exports = verify(testing, run);
13 changes: 7 additions & 6 deletions exercises/4_everyone_is_min/solution/solution.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
var _ = require("lodash");
'use strict';

var _ = require("lodash");

var tempsort = function(item){
var tempsort = function (item) {
var result = {
hot: [],
warm: []
};

function check_temp(item){
function check_temp (item) {
return item > 19;
}

_.forEach(item,function(town,townname){
_.forEach(item, function (town, townname) {

if(_.every(town,check_temp)){
if (_.every(town, check_temp)) {
result.hot.push(townname);
}else if(_.some(town,check_temp)){
} else if (_.some(town, check_temp)) {
result.warm.push(townname);
}

Expand Down
11 changes: 6 additions & 5 deletions exercises/5_count_the_comments/exercise.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

var verify = require("../../lib/verify.js");
var _ = require("lodash");
var verify = require("../../lib/verify.js"),
_ = require("lodash");

var run = {

Expand Down Expand Up @@ -39,7 +39,8 @@ var testing = {
{
username: "foo",
comment: "lalalala"
}],
}
],
shouldbe: [
{
"username": "foo",
Expand All @@ -48,7 +49,7 @@ var testing = {
]
},
'Testing counting right...': {
input:[
input: [
{
username: "foo",
comment: "lalalala"
Expand All @@ -75,4 +76,4 @@ var testing = {
}
};

module.exports = verify(testing,run);
module.exports = verify(testing, run);
Loading

0 comments on commit 7cba91a

Please sign in to comment.