Skip to content

Commit 91f6d0c

Browse files
committed
Add jscs and fix all warnings.
1 parent 577d4e5 commit 91f6d0c

File tree

6 files changed

+112
-55
lines changed

6 files changed

+112
-55
lines changed

.editorconfig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ charset = utf-8
1010
trim_trailing_whitespace = true
1111
insert_final_newline = true
1212

13-
[*.js]
13+
[*.{js,json}]
1414
indent_style = space
1515
indent_size = 4
1616

17-
[*.json]
17+
[.{jshintrc,jscsrc}]
1818
indent_style = space
1919
indent_size = 4
2020

21+
[*.{yml,yaml}]
22+
indent_style = space
23+
indent_size = 2
24+
2125
[*.md]
2226
trim_trailing_whitespace = false

.jscsrc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"preset": "google",
3+
"fileExtensions": [
4+
".js"
5+
],
6+
"requireSemicolons": true,
7+
"requireParenthesesAroundIIFE": true,
8+
"maximumLineLength": 120,
9+
"validateLineBreaks": "LF",
10+
"validateIndentation": 4,
11+
"disallowTrailingComma": true,
12+
"disallowSpacesInsideObjectBrackets": null,
13+
"disallowImplicitTypeConversion": [
14+
"string"
15+
],
16+
"jsDoc": {
17+
"checkAnnotations": "closurecompiler",
18+
"checkParamNames": true,
19+
"requireParamTypes": true,
20+
"checkRedundantParams": true,
21+
"checkReturnTypes": true,
22+
"checkRedundantReturns": true,
23+
"requireReturnTypes": true,
24+
"checkTypes": "capitalizedNativeCase",
25+
"checkRedundantAccess": true,
26+
"requireNewlineAfterDescription": true
27+
}
28+
}

gulpfile.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,38 @@ var dependencies = [
2020
];
2121
var sources = 'stacktrace.js';
2222

23-
gulp.task('lint', function () {
23+
gulp.task('lint', function() {
2424
return gulp.src(sources)
2525
.pipe(jshint())
2626
.pipe(jshint.reporter('default'))
2727
.pipe(jshint.reporter('fail'));
2828
});
2929

30-
gulp.task('test', function (done) {
30+
gulp.task('test', function(done) {
3131
var server = new karma.Server({
3232
configFile: __dirname + '/karma.conf.js',
3333
singleRun: true
3434
}, done);
3535
server.start();
3636
});
3737

38-
gulp.task('test-pr', ['dist'], function (done) {
38+
gulp.task('test-pr', ['dist'], function(done) {
3939
new karma.Server({
4040
configFile: __dirname + '/karma.conf.js',
4141
browsers: ['Firefox', 'Chrome_Travis'],
4242
singleRun: true
4343
}, done).start();
4444
});
4545

46-
gulp.task('test-ci', ['dist'], function (done) {
46+
gulp.task('test-ci', ['dist'], function(done) {
4747
var server = new karma.Server({
4848
configFile: __dirname + '/karma.conf.ci.js',
4949
singleRun: true
5050
}, done);
5151
server.start();
5252
});
5353

54-
gulp.task('dist', function () {
54+
gulp.task('dist', function() {
5555
gulp.src(polyfills.concat(dependencies.concat(sources)))
5656
.pipe(sourcemaps.init())
5757
.pipe(concat(sources.replace('.js', '-with-promises-and-json-polyfills.min.js')))
@@ -69,11 +69,11 @@ gulp.task('dist', function () {
6969

7070
gulp.task('clean', del.bind(null, ['build', 'coverage', 'dist']));
7171

72-
gulp.task('ci', ['lint', 'test-ci'], function () {
72+
gulp.task('ci', ['lint', 'test-ci'], function() {
7373
gulp.src('./coverage/**/lcov.info')
7474
.pipe(coveralls());
7575
});
7676

77-
gulp.task('default', ['clean'], function (cb) {
77+
gulp.task('default', ['clean'], function(cb) {
7878
runSequence('lint', 'dist', 'test', cb);
7979
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"jasmine": "^2.3.2",
3939
"jasmine-ajax": "^3.2.0",
4040
"jasmine-core": "^2.3.4",
41+
"jscs": "^2.9.0",
4142
"json3": "^3.3.2",
4243
"karma": "^0.13.15",
4344
"karma-chrome-launcher": "^0.2.1",

spec/stacktrace-spec.js

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
// jscs:disable maximumLineLength
12
/* global Errors: false */
2-
describe('StackTrace', function () {
3+
describe('StackTrace', function() {
34

4-
beforeEach(function () {
5+
beforeEach(function() {
56
if (typeof Promise === 'undefined') {
67
ES6Promise.polyfill();
78
}
89
});
910

10-
describe('#get', function () {
11+
describe('#get', function() {
1112
it('gets stacktrace from current location', function testStackTraceGet(done) {
1213
StackTrace.get().then(callback, done.fail)['catch'](done.fail);
1314

@@ -18,20 +19,20 @@ describe('StackTrace', function () {
1819
});
1920
});
2021

21-
describe('#fromError', function () {
22+
describe('#fromError', function() {
2223
beforeEach(function() {
2324
jasmine.Ajax.install();
2425
});
2526
afterEach(function() {
2627
jasmine.Ajax.uninstall();
2728
});
2829

29-
it('rejects with Error given unparsable Error object', function (done) {
30+
it('rejects with Error given unparsable Error object', function(done) {
3031
StackTrace.fromError({message: 'ERROR_MESSAGE'})
3132
.then(done.fail)['catch'](done);
3233
});
3334

34-
it('parses stacktrace from given Error object', function (done) {
35+
it('parses stacktrace from given Error object', function(done) {
3536
jasmine.Ajax.stubRequest('http://path/to/file.js').andError();
3637

3738
StackTrace.fromError(Errors.IE_11)
@@ -44,7 +45,7 @@ describe('StackTrace', function () {
4445
}
4546
});
4647

47-
it('filters returned stack', function (done) {
48+
it('filters returned stack', function(done) {
4849
function onlyFoos(stackFrame) {
4950
return stackFrame.functionName === 'foo';
5051
}
@@ -62,7 +63,7 @@ describe('StackTrace', function () {
6263
}
6364
});
6465

65-
it('uses source maps to enhance stack frames', function (done) {
66+
it('uses source maps to enhance stack frames', function(done) {
6667
var sourceCache = {
6768
'http://path/to/file.js': 'function increment(){\nsomeVariable+=2;\nnull.x()\n}\nvar someVariable=2;increment();',
6869
'http://path/to/file.min.js': 'function increment(){someVariable+=2;null.x()}var someVariable=2;increment();\n//# sourceMappingURL=file.min.js.map',
@@ -81,9 +82,9 @@ describe('StackTrace', function () {
8182
});
8283
});
8384

84-
describe('#generateArtificially', function () {
85-
it('gets stacktrace from current location', function (done) {
86-
var stackFrameFilter = function (stackFrame) {
85+
describe('#generateArtificially', function() {
86+
it('gets stacktrace from current location', function(done) {
87+
var stackFrameFilter = function(stackFrame) {
8788
return stackFrame.getFunctionName() &&
8889
stackFrame.getFunctionName().indexOf('testGenerateArtificially') > -1;
8990
};
@@ -100,14 +101,19 @@ describe('StackTrace', function () {
100101
});
101102
});
102103

103-
describe('#instrument', function () {
104+
describe('#instrument', function() {
104105
it('throws Error given non-function input', function() {
105-
expect(function() { StackTrace.instrument('BOGUS'); })
106+
expect(function() {
107+
StackTrace.instrument('BOGUS');
108+
})
106109
.toThrow(new Error('Cannot instrument non-function object'));
107110
});
108111

109112
it('wraps given function and calls given callback when called', function(done) {
110-
function interestingFn() { return 'something'; }
113+
function interestingFn() {
114+
return 'something';
115+
}
116+
111117
var wrapped = StackTrace.instrument(interestingFn, callback, done.fail);
112118
expect(wrapped()).toBe('something');
113119

@@ -120,11 +126,16 @@ describe('StackTrace', function () {
120126
});
121127

122128
it('calls callback with stack trace when wrapped function throws an Error', function(done) {
123-
function interestingFn() { throw new Error('BOOM'); }
129+
function interestingFn() {
130+
throw new Error('BOOM');
131+
}
132+
124133
var wrapped = StackTrace.instrument(interestingFn, callback, done.fail);
125134

126135
// Exception should be re-thrown from instrument
127-
expect(function() { wrapped(); }).toThrow(new Error('BOOM'));
136+
expect(function() {
137+
wrapped();
138+
}).toThrow(new Error('BOOM'));
128139

129140
function callback(stackFrames) {
130141
if (stackFrames[0].fileName) { // Work around IE9-
@@ -135,26 +146,35 @@ describe('StackTrace', function () {
135146
});
136147

137148
it('does not re-instrument already instrumented function', function() {
138-
function interestingFn() { return 'something'; }
149+
function interestingFn() {
150+
return 'something';
151+
}
152+
139153
var wrapped = StackTrace.instrument(interestingFn);
140154
expect(StackTrace.instrument(wrapped)).toEqual(wrapped);
141155
});
142156
});
143157

144-
describe('#deinstrument', function () {
145-
it('throws Error given non-function input', function () {
146-
expect(function () {
158+
describe('#deinstrument', function() {
159+
it('throws Error given non-function input', function() {
160+
expect(function() {
147161
StackTrace.deinstrument('BOGUS');
148162
}).toThrow(new Error('Cannot de-instrument non-function object'));
149163
});
150164

151165
it('given unwrapped input, returns input', function() {
152-
function interestingFn() { return 'something'; }
166+
function interestingFn() {
167+
return 'something';
168+
}
169+
153170
expect(StackTrace.deinstrument(interestingFn)).toEqual(interestingFn);
154171
});
155172

156173
it('de-instruments instrumented function', function() {
157-
function interestingFn() { return 'something'; }
174+
function interestingFn() {
175+
return 'something';
176+
}
177+
158178
var wrapped = StackTrace.instrument(interestingFn);
159179
expect(wrapped.__stacktraceOriginalFn).toEqual(interestingFn);
160180

@@ -164,15 +184,15 @@ describe('StackTrace', function () {
164184
});
165185
});
166186

167-
describe('#report', function () {
187+
describe('#report', function() {
168188
beforeEach(function() {
169189
jasmine.Ajax.install();
170190
});
171191
afterEach(function() {
172192
jasmine.Ajax.uninstall();
173193
});
174194

175-
it('sends POST request to given URL', function (done) {
195+
it('sends POST request to given URL', function(done) {
176196
var url = 'http://domain.ext/endpoint';
177197
var stackframes = [new StackFrame('fn', undefined, 'file.js', 32, 1)];
178198

@@ -189,7 +209,7 @@ describe('StackTrace', function () {
189209
}
190210
});
191211

192-
it('rejects if POST request fails', function (done) {
212+
it('rejects if POST request fails', function(done) {
193213
var url = 'http://domain.ext/endpoint';
194214
var stackframes = [new StackFrame('fn', undefined, 'file.js', 32, 1)];
195215

0 commit comments

Comments
 (0)