Skip to content

Commit 2ad71d7

Browse files
bz2steren
authored andcommitted
Use eslint for javascript linting (#55)
Switch from jshint to eslint as linting dependency. Add basic config with recommended rules and a few extra syntax enforcements. Use eslint-plugin-mocha for some test specialisation. Remove gulp lint task. Remove old demo.min.js file. Add eslint override comments as needed for now and fix a few issues.
1 parent 8770a9e commit 2ad71d7

9 files changed

Lines changed: 1075 additions & 449 deletions

File tree

.eslintrc.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"env": {
3+
"browser": true
4+
},
5+
"extends": [
6+
"eslint:recommended"
7+
],
8+
"parserOptions": {
9+
"ecmaVersion": 5
10+
},
11+
"globals" : {
12+
"Promise": false
13+
},
14+
"rules": {
15+
"block-scoped-var": "error",
16+
"complexity": ["error", 15],
17+
"curly": "error",
18+
"eqeqeq": ["error", "smart"],
19+
"linebreak-style": ["error", "unix"],
20+
"quote-props": ["error", "as-needed"],
21+
"quotes": ["error", "single"],
22+
"semi": "error",
23+
"unicode-bom": ["error", "never"]
24+
},
25+
"overrides": [{
26+
"files": ["test/*.js"],
27+
"env": {
28+
"mocha": true
29+
},
30+
"globals": {
31+
"chai": false,
32+
"sinon": false,
33+
"StackdriverErrorReporter": false
34+
},
35+
"plugins": [
36+
"mocha"
37+
],
38+
"rules": {
39+
"mocha/handle-done-callback": "error",
40+
"mocha/no-exclusive-tests": "warn",
41+
"mocha/no-nested-tests": "error",
42+
"mocha/no-return-and-callback": "error"
43+
}
44+
}]
45+
}

demo/demo-angular.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
angular.module('demoApp', [])
1+
angular.module('demoApp', []) // eslint-disable-line no-undef
22

33
.factory('$exceptionHandler', ['$log', '$window', function($log, $window) {
44
var StackdriverErrors = new $window.StackdriverErrorReporter();
@@ -18,4 +18,4 @@ angular.module('demoApp', [])
1818
demo.starUser = function() {
1919
demo.user.star();
2020
};
21-
});
21+
});

demo/demo.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
// eslint-disable-next-line no-undef
1617
var StackdriverErrors = new StackdriverErrorReporter();
1718

1819
function updateConfig() {
@@ -39,6 +40,7 @@ function loadFromLocalStorage() {
3940
if(key && projectId) {
4041
updateConfig();
4142
} else {
43+
// eslint-disable-next-line no-console
4244
console.warn('No API key provided, Stackdriver not started.');
4345
}
4446
}
@@ -47,7 +49,7 @@ loadFromLocalStorage();
4749

4850
// Fake application code
4951
var users;
50-
function vanillaCrash() {
52+
function vanillaCrash() { // eslint-disable-line no-unused-vars
5153
starUsers();
5254
}
5355
function starUsers() {
@@ -61,16 +63,16 @@ function displayUserInfo() {
6163
}
6264
}
6365
function addUser(name) {
64-
var user = new User();
66+
var user = new User(name); // eslint-disable-line no-undef
6567
users.push(user);
6668
}
6769

6870

6971
// Buttons logic
70-
function reportErrorMessage() {
72+
function reportErrorMessage() { // eslint-disable-line no-unused-vars
7173
displayUserInfo();
7274
}
73-
function catchCrashAndReport() {
75+
function catchCrashAndReport() { // eslint-disable-line no-unused-vars
7476
try {
7577
addUser('Keyser Söze');
7678
} catch (e) {

demo/demo.min.js

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

gulpfile.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
/* global require */
1617
var gulp = require('gulp');
1718
var rename = require('gulp-rename');
1819
var replace = require('gulp-replace');
1920
var uglify = require('gulp-uglify');
2021
var sourcemaps = require('gulp-sourcemaps');
2122
var mochaPhantomJS = require('gulp-mocha-phantomjs');
22-
var jshint = require('gulp-jshint');
2323
var concat = require('gulp-concat');
2424

2525
var SRC_FILE = 'stackdriver-errors.js';
@@ -29,12 +29,6 @@ var dependencies = [
2929
'./node_modules/stacktrace-js/dist/stacktrace-with-promises-and-json-polyfills.js',
3030
];
3131

32-
gulp.task('lint', function() {
33-
return gulp.src(SRC_FILE)
34-
.pipe(jshint())
35-
.pipe(jshint.reporter('default'));
36-
});
37-
3832
gulp.task('test', function () {
3933
return gulp
4034
.src('test/test.html')
@@ -71,5 +65,5 @@ gulp.task('demo-js', function() {
7165
.pipe(gulp.dest('dist'));
7266
});
7367

74-
gulp.task('default', ['lint', 'test']);
68+
gulp.task('default', ['test']);
7569
gulp.task('demo', ['dist', 'demo-html', 'demo-js']);

0 commit comments

Comments
 (0)