Skip to content

Commit aef0df8

Browse files
committed
Merge pull request #450 from getsentry/eslint
Use eslint
2 parents cedc88f + 9bc6462 commit aef0df8

File tree

8 files changed

+103
-43
lines changed

8 files changed

+103
-43
lines changed

.eslintrc

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"env": {
3+
"jasmine": true,
4+
"node": true,
5+
"mocha": true,
6+
"browser": true,
7+
"builtin": true
8+
},
9+
"globals": {
10+
"require": false
11+
},
12+
"rules": {
13+
"block-scoped-var": 2,
14+
"dot-notation": [
15+
2,
16+
{
17+
"allowKeywords": true
18+
}
19+
],
20+
"eqeqeq": [
21+
2,
22+
"allow-null"
23+
],
24+
"guard-for-in": 2,
25+
"new-cap": 2,
26+
"no-caller": 2,
27+
"no-cond-assign": [
28+
2,
29+
"except-parens"
30+
],
31+
"no-debugger": 2,
32+
"no-empty": 2,
33+
"no-eval": 2,
34+
"no-extend-native": 2,
35+
"no-extra-parens": 2,
36+
"no-irregular-whitespace": 2,
37+
"no-iterator": 2,
38+
"no-loop-func": 2,
39+
"no-multi-str": 2,
40+
"no-new": 2,
41+
"no-proto": 2,
42+
"no-script-url": 2,
43+
"no-sequences": 2,
44+
"no-shadow": 2,
45+
"no-undef": 2,
46+
"no-unused-vars": [
47+
2,
48+
{"args": "none"}
49+
],
50+
"no-with": 2,
51+
"quotes": [
52+
2,
53+
"single",
54+
"avoid-escape"
55+
],
56+
"semi": [
57+
0,
58+
"never"
59+
],
60+
"strict": [
61+
2,
62+
"global"
63+
],
64+
"valid-typeof": 2,
65+
"wrap-iife": [
66+
2,
67+
"inside"
68+
]
69+
}
70+
}

.jshintrc

Lines changed: 0 additions & 11 deletions
This file was deleted.

Gruntfile.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
module.exports = function(grunt) {
2-
"use strict";
1+
'use strict';
32

3+
module.exports = function(grunt) {
44
var _ = require('lodash');
55
var path = require('path');
66
var through = require('through2');
@@ -14,12 +14,12 @@ module.exports = function(grunt) {
1414
var plugins = grunt.option('plugins');
1515
// Create plugin paths and verify they exist
1616
plugins = _.map(plugins ? plugins.split(',') : [], function (plugin) {
17-
var path = 'plugins/' + plugin + '.js';
17+
var p = 'plugins/' + plugin + '.js';
1818

19-
if(!grunt.file.exists(path))
19+
if(!grunt.file.exists(p))
2020
throw new Error("Plugin '" + plugin + "' not found in plugins directory.");
2121

22-
return path;
22+
return p;
2323
});
2424

2525
// custom browserify transformer to re-write plugins to
@@ -136,7 +136,7 @@ module.exports = function(grunt) {
136136
compress: {
137137
dead_code: true,
138138
global_defs: {
139-
"TEST": false
139+
'TEST': false
140140
}
141141
}
142142
},
@@ -151,11 +151,8 @@ module.exports = function(grunt) {
151151
all: ['build/**/*.map']
152152
},
153153

154-
jshint: {
155-
options: {
156-
jshintrc: '.jshintrc'
157-
},
158-
all: ['Gruntfile.js', 'src/**/*.js', 'plugins/**/*.js']
154+
eslint: {
155+
target: ['Gruntfile.js', 'src/**/*.js', 'plugins/**/*.js']
159156
},
160157

161158
mocha: {
@@ -270,8 +267,7 @@ module.exports = function(grunt) {
270267

271268
grunt.registerMultiTask('fixSourceMaps', function () {
272269
this.files.forEach(function (f) {
273-
var result;
274-
var sources = f.src.filter(function (filepath) {
270+
f.src.filter(function (filepath) {
275271
if (!grunt.file.exists(filepath)) {
276272
grunt.log.warn('Source file "' + filepath + '" not found.');
277273
return false;
@@ -294,7 +290,6 @@ module.exports = function(grunt) {
294290
// Grunt contrib tasks
295291
grunt.loadNpmTasks('grunt-contrib-uglify');
296292
grunt.loadNpmTasks('grunt-contrib-clean');
297-
grunt.loadNpmTasks('grunt-contrib-jshint');
298293
grunt.loadNpmTasks('grunt-contrib-connect');
299294
grunt.loadNpmTasks('grunt-contrib-copy');
300295

@@ -305,6 +300,7 @@ module.exports = function(grunt) {
305300
grunt.loadNpmTasks('grunt-s3');
306301
grunt.loadNpmTasks('grunt-gitinfo');
307302
grunt.loadNpmTasks('grunt-sri');
303+
grunt.loadNpmTasks('grunt-eslint');
308304

309305
// Build tasks
310306
grunt.registerTask('_prep', ['clean', 'gitinfo', 'version']);
@@ -317,7 +313,7 @@ module.exports = function(grunt) {
317313
grunt.registerTask('dist', ['build.core', 'copy:dist']);
318314

319315
// Test task
320-
grunt.registerTask('test', ['jshint', 'browserify.core', 'browserify:test', 'mocha']);
316+
grunt.registerTask('test', ['eslint', 'browserify.core', 'browserify:test', 'mocha']);
321317

322318
// Webserver tasks
323319
grunt.registerTask('run:test', ['connect:test']);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"grunt-contrib-copy": "^0.8.2",
2525
"grunt-contrib-jshint": "^0.11.3",
2626
"grunt-contrib-uglify": "^0.11.0",
27+
"grunt-eslint": "^17.3.1",
2728
"grunt-gitinfo": "^0.1.7",
2829
"grunt-mocha": "^0.4.15",
2930
"grunt-release": "^0.13.0",

plugins/angular.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ function angularPlugin(Raven, angular) {
2525
['Raven', '$delegate', exceptionHandler]);
2626
}
2727

28-
function exceptionHandler(Raven, $delegate) {
28+
function exceptionHandler(R, $delegate) {
2929
return function (ex, cause) {
30-
Raven.captureException(ex, {
30+
R.captureException(ex, {
3131
extra: { cause: cause }
3232
});
3333
$delegate(ex, cause);

plugins/console.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function consolePlugin(Raven, console) {
1313
logLevels = ['debug', 'info', 'warn', 'error'],
1414
level = logLevels.pop();
1515

16-
var logForGivenLevel = function(level) {
17-
var originalConsoleLevel = console[level];
16+
var logForGivenLevel = function(l) {
17+
var originalConsoleLevel = console[l];
1818

1919
// warning level is the only level that doesn't map up
2020
// correctly with what Sentry expects.

src/raven.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function Raven() {
5656
this._plugins = [];
5757
this._startTime = now();
5858

59-
for (var method in this._originalConsole) {
59+
for (var method in this._originalConsole) { // eslint-disable-line guard-for-in
6060
this._originalConsoleMethods[method] = this._originalConsole[method];
6161
}
6262
}
@@ -98,7 +98,7 @@ Raven.prototype = {
9898
if (options) {
9999
each(options, function(key, value){
100100
// tags and extra are special and need to be put into context
101-
if (key == 'tags' || key == 'extra') {
101+
if (key === 'tags' || key === 'extra') {
102102
self._globalContext[key] = value;
103103
} else {
104104
self._globalOptions[key] = value;
@@ -535,7 +535,9 @@ Raven.prototype = {
535535
// IE9 if quirks
536536
try {
537537
document.fireEvent('on' + evt.eventType.toLowerCase(), evt);
538-
} catch(e) {}
538+
} catch(e) {
539+
// Do nothing
540+
}
539541
}
540542
},
541543

@@ -555,7 +557,7 @@ Raven.prototype = {
555557
// Make a copy of the arguments
556558
var args = [].slice.call(arguments);
557559
var originalCallback = args[0];
558-
if (typeof (originalCallback) === 'function') {
560+
if (typeof originalCallback === 'function') {
559561
args[0] = self.wrap(originalCallback);
560562
}
561563

@@ -591,7 +593,9 @@ Raven.prototype = {
591593
if (fn && fn.handleEvent) {
592594
fn.handleEvent = self.wrap(fn.handleEvent);
593595
}
594-
} catch (err) {} // can sometimes get 'Permission denied to access property "handle Event'
596+
} catch (err) {
597+
// can sometimes get 'Permission denied to access property "handle Event'
598+
}
595599
return orig.call(this, evt, self.wrap(fn), capture, secure);
596600
};
597601
});
@@ -658,7 +662,7 @@ Raven.prototype = {
658662
return dsn;
659663
},
660664

661-
_handleOnErrorStackInfo: function(stackInfo, options) {
665+
_handleOnErrorStackInfo: function() {
662666
// if we are intentionally ignoring errors via onerror, bail out
663667
if (!this._ignoreOnError) {
664668
this._handleStackInfo.apply(this, arguments);
@@ -712,9 +716,9 @@ Raven.prototype = {
712716

713717
normalized.in_app = !( // determine if an exception came from outside of our app
714718
// first we check the global includePaths list.
715-
(!!this._globalOptions.includePaths.test && !this._globalOptions.includePaths.test(normalized.filename)) ||
719+
!!this._globalOptions.includePaths.test && !this._globalOptions.includePaths.test(normalized.filename) ||
716720
// Now we check for fun, if the function name is Raven or TraceKit
717-
/(Raven|TraceKit)\./.test(normalized['function']) ||
721+
/(Raven|TraceKit)\./.test(normalized.function) ||
718722
// finally, we do a last ditch effort and check for raven.min.js
719723
/raven\.(min\.)?js$/.test(normalized.filename)
720724
);
@@ -762,7 +766,7 @@ Raven.prototype = {
762766
},
763767

764768
_processException: function(type, message, fileurl, lineno, frames, options) {
765-
var stacktrace, i, fullMessage;
769+
var stacktrace, fullMessage;
766770

767771
if (!!this._globalOptions.ignoreErrors.test && this._globalOptions.ignoreErrors.test(message)) return;
768772

src/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function isObject(what) {
1919
}
2020

2121
function isEmptyObject(what) {
22-
for (var k in what) return false;
22+
for (var _ in what) return false; // eslint-disable-line guard-for-in, no-unused-vars
2323
return true;
2424
}
2525

@@ -87,7 +87,7 @@ function joinRegExp(patterns) {
8787
if (isString(pattern)) {
8888
// If it's a string, we need to escape it
8989
// Taken from: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
90-
sources.push(pattern.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"));
90+
sources.push(pattern.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1'));
9191
} else if (pattern && pattern.source) {
9292
// If it's a regexp already, we want to extract the source
9393
sources.push(pattern.source);
@@ -126,13 +126,13 @@ function uuid4() {
126126
return v;
127127
};
128128

129-
return (pad(arr[0]) + pad(arr[1]) + pad(arr[2]) + pad(arr[3]) + pad(arr[4]) +
129+
return pad(arr[0]) + pad(arr[1] + pad(arr[2]) + pad(arr[3]) + pad(arr[4]) +
130130
pad(arr[5]) + pad(arr[6]) + pad(arr[7]));
131131
} else {
132132
// http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523
133133
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
134134
var r = Math.random()*16|0,
135-
v = c == 'x' ? r : (r&0x3|0x8);
135+
v = c === 'x' ? r : r&0x3|0x8;
136136
return v.toString(16);
137137
});
138138
}

0 commit comments

Comments
 (0)