Skip to content

Commit 09ae567

Browse files
add editor config and eslint rules
1 parent 3cbe16a commit 09ae567

File tree

11 files changed

+167
-44
lines changed

11 files changed

+167
-44
lines changed

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.{sh,markdown, md}]
12+
indent_size = 4
13+
trim_trailing_whitespace = false

.eslintrc

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
"rules": {
3+
"no-console": 2,
4+
"no-alert": 2,
5+
"no-debugger": 2,
6+
"comma-dangle": [2, "never"],
7+
"quotes": [2, "single", "avoid-escape"],
8+
"no-unused-vars": [2, {"args": "after-used", "argsIgnorePattern": "^_"}],
9+
"no-empty": 2,
10+
"no-cond-assign": [2, "always"],
11+
"no-constant-condition": 2,
12+
"no-dupe-keys": 2,
13+
"no-extra-parens": 2,
14+
"no-extra-semi": 2,
15+
"no-inner-declarations": 2,
16+
"no-irregular-whitespace": 2,
17+
"no-negated-in-lhs": 2,
18+
"no-sparse-arrays": 2,
19+
"no-unexpected-multiline": 2,
20+
"no-unreachable": 2,
21+
"valid-typeof": 2,
22+
"block-scoped-var": 2,
23+
"consistent-return": 2,
24+
"curly": 2,
25+
"dot-location": [2, "property"],
26+
"eqeqeq": [2, "smart"],
27+
"no-else-return": 2,
28+
"no-implicit-coercion": [2, {"boolean": true, "number": true, "string": true}],
29+
"no-lone-blocks": 2,
30+
"no-magic-numbers": [2, {"ignore": [8080]}],
31+
"no-loop-func": 2,
32+
"no-multi-spaces": 2,
33+
"no-multi-str": 2,
34+
"no-new-wrappers": 2,
35+
"no-new": 2,
36+
"no-throw-literal": 2,
37+
"no-redeclare": 2,
38+
"no-useless-call": 2,
39+
"no-useless-concat": 2,
40+
"vars-on-top": 2,
41+
"yoda": 2,
42+
"no-catch-shadow": 2,
43+
"no-shadow-restricted-names": 2,
44+
"no-shadow": 2,
45+
"no-use-before-define": 2,
46+
"array-bracket-spacing": [2, "never"],
47+
"block-spacing": 2,
48+
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
49+
"camelcase": [2, {"properties": "always"}],
50+
"comma-spacing": [2, {"before": false, "after": true}],
51+
"comma-style": [2, "last"],
52+
"computed-property-spacing": [2, "never"],
53+
"consistent-this": [2, "self"],
54+
"eol-last": 2,
55+
"indent": [2, 2, {"SwitchCase": 1}],
56+
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
57+
"new-cap": 2,
58+
"new-parens": 2,
59+
"newline-after-var": [2, "always"],
60+
"no-lonely-if": 2,
61+
"no-multiple-empty-lines": [2, {"max": 1, "maxEOF": 1}],
62+
"no-negated-condition": 2,
63+
"no-nested-ternary": 2,
64+
"no-spaced-func": 2,
65+
"no-trailing-spaces": 2,
66+
"no-unneeded-ternary": 2,
67+
"object-curly-spacing": [2, "never"],
68+
"operator-linebreak": [2, "before"],
69+
"padded-blocks": [2, "never"],
70+
"quote-props": [2, "consistent-as-needed"],
71+
"semi-spacing": 2,
72+
"space-after-keywords": 2,
73+
"space-before-blocks": 2,
74+
"space-before-function-paren": [2, { "anonymous": "always", "named": "never" }],
75+
"space-before-keywords": [2, "always"],
76+
"space-in-parens": [2, "never"],
77+
"space-infix-ops": 2,
78+
"space-return-throw-case": 2,
79+
"space-unary-ops": 2,
80+
"linebreak-style": [2, "unix"],
81+
"semi": [2, "always"],
82+
"backbone/initialize-on-top": [2, {
83+
"View": ["width", "tagName", "className", "attributes", "template", "alwaysSuppressHighlightErrors", "subViews", "events", "constructor"],
84+
"Model": ["defaults"],
85+
"Collection": ["model"]
86+
}],
87+
"backbone/events-on-top": [2, ["tagName", "className", "attributes", "template", "alwaysSuppressHighlightErrors", "subViews"]]
88+
},
89+
"env": {
90+
"browser": true,
91+
"jquery": true,
92+
"jasmine": true
93+
},
94+
"plugins": [
95+
"backbone"
96+
],
97+
"globals": {
98+
"Backbone": true,
99+
"_": true,
100+
"requirejs": true,
101+
"require": true,
102+
"define": true,
103+
"ejs": true,
104+
"module": true,
105+
"process": true
106+
},
107+
"settings": {
108+
"backbone": {
109+
"Collection": [
110+
],
111+
"Model": [
112+
],
113+
"View": [
114+
]
115+
}
116+
},
117+
"extends": "eslint:recommended"
118+
}

app/js/app.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ define([
22
'backbone',
33
'router'
44
], function (Backbone, Router) {
5-
return function() {
5+
return function () {
66
this.initialize = function () {
77
Router.initialize();
88
Backbone.history.start();
9-
}
9+
};
1010
};
1111
});

app/js/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ requirejs.config({
1919
requirejs([
2020
'app',
2121
'ejs'
22-
], function(App) {
22+
], function (App) {
2323
new App().initialize();
2424
});

app/js/router.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ define([
33
'views/app_view'
44
], function (Backbone, AppView) {
55
var Router = Backbone.Router.extend({
6-
routes: {
7-
"(?:params)": "index"
8-
},
9-
10-
index: function () {
11-
var appView = new AppView();
12-
appView.render();
13-
}
6+
routes: {
7+
'(?:params)': 'index'
148
},
9+
10+
index: function () {
11+
var appView = new AppView();
12+
13+
appView.render();
14+
}
15+
},
1516
{
1617
initialize: function () {
1718
return new Router();
1819
}
1920
});
2021

2122
return Router;
22-
});
23+
});

app/js/views/app_view.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ define([
44
'text!templates/app_view.ejs'
55
], function ($, Backbone, indexTemplate) {
66
return Backbone.View.extend({
7-
el: $('#todo-app'),
7+
el: this.$('#todo-app'),
88

99
currentDate: function () {
1010
return new Date();
1111
},
1212

1313
render: function () {
1414
var compiledTemplate = ejs.render(indexTemplate, {view: this, model: this.model}, {});
15+
1516
this.$el.empty();
1617
this.$el.append(compiledTemplate);
17-
return this
18+
return this;
1819
}
1920
});
2021
});

server.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
var connect = require('connect'),
22
http = require('http'),
33
app;
4+
var port = process.env.PORT || 8080;
45

56
app = connect()
67
.use(connect.static('app'))
78
.use('/js/lib/', connect.static('node_modules/requirejs/'))
89
.use('/js/templates/', connect.static('app/js/templates/'))
910
.use('/node_modules', connect.static('node_modules'));
1011

11-
var port = process.env.PORT || 8080;
12-
13-
http.createServer(app).listen(port, function() {
14-
console.log('Running on http://localhost:' + port);
12+
http.createServer(app).listen(port, function () {
13+
console.log('Running on http://localhost:' + port); // eslint-disable-line no-console
1514
});

spec/js/router_spec.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ define([
1414
describe('routes', function () {
1515
beforeEach(function () {
1616
subject = function () {
17-
return instance.routes
18-
}
17+
return instance.routes;
18+
};
1919
});
2020

2121
it('has a index route', function () {
@@ -25,11 +25,11 @@ define([
2525

2626
describe('navigate to empty route', function () {
2727
beforeEach(function () {
28-
Backbone.history.start({silent:true, pushState:true});
28+
Backbone.history.start({silent: true, pushState: true});
2929

3030
subject = function () {
31-
instance.navigate('', true)
32-
}
31+
instance.navigate('', true);
32+
};
3333
});
3434

3535
it('calls render on the index view', function () {
@@ -38,6 +38,6 @@ define([
3838
subject();
3939

4040
expect(renderSpy).toHaveBeenCalled();
41-
})
42-
})
41+
});
42+
});
4343
});

spec/js/views/app_view_spec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ define([
88
instance = new Index({el: $('body')});
99
subject = function () {
1010
return instance;
11-
}
11+
};
1212
});
1313

1414
describe('render', function () {
15-
it ('will get rendered', function () {
15+
it('will get rendered', function () {
1616
subject().render();
1717
expect(subject().$el.text()).toEqual(jasmine.stringMatching(/The current date is:/));
18-
})
18+
});
1919
});
2020

2121
describe('currentDate', function () {
2222
beforeEach(function () {
2323
subject = function () {
2424
return instance.currentDate();
25-
}
25+
};
2626
});
2727

2828
it('returns a date', function () {

spec/karma.conf.js

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Karma configuration
22
// Generated on Sun Apr 05 2015 22:10:43 GMT+0300 (EEST)
33

4-
module.exports = function(config) {
4+
module.exports = function (config) {
55
config.set({
66

77
// base path, that will be used to resolve files and exclude
@@ -36,36 +36,29 @@ module.exports = function(config) {
3636
'spec/test_main.js'
3737
],
3838

39-
4039
// list of files to exclude
4140
exclude: [
4241
'app/js/main.js',
4342
'spec/*.conf.js'
4443
],
4544

46-
4745
// test results reporter to use
4846
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
4947
reporters: ['dots', 'coverage'], // to use coverage, replace `html` with `coverage`
5048

51-
5249
// web server port
5350
port: 9876,
5451

55-
5652
// enable / disable colors in the output (reporters and logs)
5753
colors: true,
5854

59-
6055
// level of logging
6156
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
6257
logLevel: config.LOG_INFO,
6358

64-
6559
// enable / disable watching file and executing tests whenever any file changes
6660
autoWatch: true,
6761

68-
6962
// Start these browsers, currently available:
7063
// - Chrome
7164
// - ChromeCanary
@@ -76,11 +69,9 @@ module.exports = function(config) {
7669
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
7770
browsers: ['PhantomJS'],
7871

79-
8072
// If browser does not capture in given timeout [ms], kill it
8173
captureTimeout: 60000,
8274

83-
8475
// Continuous Integration mode
8576
// if true, it capture browsers, run tests and exit
8677
singleRun: false,
@@ -90,8 +81,8 @@ module.exports = function(config) {
9081
},
9182

9283
coverageReporter: {
93-
type : 'html',
94-
dir : 'spec/coverage'
84+
type: 'html',
85+
dir: 'spec/coverage'
9586
}
9687
});
9788
};

spec/test_main.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
var allTestFiles = [];
22
var TEST_REGEXP = /spec\.js$/;
33

4-
var pathToModule = function(path) {
4+
var pathToModule = function (path) {
55
return path.replace(/^\/base\//, '../../').replace(/\.js$/, '');
66
};
77

8-
Object.keys(window.__karma__.files).forEach(function(file) {
8+
Object.keys(window.__karma__.files).forEach(function (file) {
99
if (TEST_REGEXP.test(file)) {
1010
// Normalize paths to RequireJS module names.
1111
allTestFiles.push(pathToModule(file));
@@ -36,4 +36,4 @@ require.config({
3636

3737
// we have to kickoff jasmine, as it is asynchronous
3838
callback: window.__karma__.start
39-
});
39+
});

0 commit comments

Comments
 (0)