Skip to content

Commit 07c31d0

Browse files
committed
chore: add eslint
- This adds eslint and integrates it to the build chain - Removes jshint Closes angular-ui#4758 Closes angular-ui#4840
1 parent 742132a commit 07c31d0

File tree

25 files changed

+242
-158
lines changed

25 files changed

+242
-158
lines changed

Diff for: .eslintrc

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"rules": {
3+
"comma-dangle": 2,
4+
"no-cond-assign": 2,
5+
"no-control-regex": 2,
6+
"no-debugger": 2,
7+
"no-dupe-args": 2,
8+
"no-dupe-keys": 2,
9+
"no-duplicate-case": 2,
10+
"no-empty-character-class": 2,
11+
"no-empty": 2,
12+
"no-ex-assign": 2,
13+
"no-extra-boolean-cast": 2,
14+
"no-extra-parens": 2,
15+
"no-extra-semi": 2,
16+
"no-func-assign": 2,
17+
"no-inner-declarations": 2,
18+
"no-invalid-regexp": 2,
19+
"no-negated-in-lhs": 2,
20+
"no-regex-spaces": 2,
21+
"no-sparse-arrays": 2,
22+
"no-unexpected-multiline": 2,
23+
"no-unreachable": 2,
24+
"valid-typeof": 2,
25+
"accessor-pairs": 2,
26+
"block-scoped-var": 2,
27+
"complexity": 2,
28+
"curly": 2,
29+
"dot-notation": 2,
30+
"eqeqeq": 2,
31+
"guard-for-in": 2,
32+
"no-alert": 2,
33+
"no-caller": 2,
34+
"no-case-declarations": 2,
35+
"no-div-regex": 2,
36+
"no-else-return": 2,
37+
"no-empty-label": 2,
38+
"no-empty-pattern": 2,
39+
"no-eq-null": 2,
40+
"no-eval": 2,
41+
"no-extend-native": 2,
42+
"no-extra-bind": 2,
43+
"no-floating-decimal": 2,
44+
"no-implied-eval": 2,
45+
"no-invalid-this": 2,
46+
"no-iterator": 2,
47+
"no-lone-blocks": 2,
48+
"no-loop-func": 2,
49+
"no-multi-spaces": 2,
50+
"no-native-reassign": 2,
51+
"no-new-func": 2,
52+
"no-new-wrappers": 2,
53+
"no-new": 2,
54+
"no-octal-escape": 2,
55+
"no-octal": 2,
56+
"no-proto": 2,
57+
"no-redeclare": 2,
58+
"no-script-url": 2,
59+
"no-self-compare": 2,
60+
"no-sequences": 2,
61+
"no-throw-literal": 2,
62+
"no-unused-expressions": 2,
63+
"no-useless-call": 2,
64+
"no-useless-concat": 2,
65+
"no-void": 2,
66+
"no-with": 2,
67+
"radix": 2,
68+
"wrap-iife": 2,
69+
"yoda": 2
70+
}
71+
}

Diff for: Gruntfile.js

+4-19
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
1-
/* jshint node: true */
21
var markdown = require('node-markdown').Markdown;
32
var fs = require('fs');
43

54
module.exports = function(grunt) {
6-
7-
grunt.loadNpmTasks('grunt-contrib-watch');
8-
grunt.loadNpmTasks('grunt-contrib-concat');
9-
grunt.loadNpmTasks('grunt-contrib-copy');
10-
grunt.loadNpmTasks('grunt-contrib-jshint');
11-
grunt.loadNpmTasks('grunt-contrib-uglify');
12-
grunt.loadNpmTasks('grunt-html2js');
13-
grunt.loadNpmTasks('grunt-karma');
14-
grunt.loadNpmTasks('grunt-conventional-changelog');
15-
grunt.loadNpmTasks('grunt-ddescribe-iit');
5+
require('load-grunt-tasks')(grunt);
166

177
// Project configuration.
188
grunt.util.linefeed = '\n';
@@ -50,7 +40,6 @@ module.exports = function(grunt) {
5040
},
5141
js: {
5242
files: ['src/**/*.js'],
53-
//we don't need to jshint here, it slows down everything else
5443
tasks: ['karma:watch:run']
5544
}
5645
},
@@ -124,11 +113,8 @@ module.exports = function(grunt) {
124113
}]
125114
}
126115
},
127-
jshint: {
128-
files: ['Gruntfile.js','src/**/*.js'],
129-
options: {
130-
jshintrc: '.jshintrc'
131-
}
116+
eslint: {
117+
files: ['Gruntfile.js','src/**/*.js']
132118
},
133119
karma: {
134120
options: {
@@ -197,7 +183,7 @@ module.exports = function(grunt) {
197183

198184
//register before and after test tasks so we've don't have to change cli
199185
//options on the google's CI server
200-
grunt.registerTask('before-test', ['enforce', 'ddescribe-iit', 'jshint', 'html2js']);
186+
grunt.registerTask('before-test', ['enforce', 'ddescribe-iit', 'eslint', 'html2js']);
201187
grunt.registerTask('after-test', ['build', 'copy']);
202188

203189
//Rename our watch task to 'delta', then make actual 'watch'
@@ -427,7 +413,6 @@ module.exports = function(grunt) {
427413
* https://github.com/angular/angular.js/blob/36831eccd1da37c089f2141a2c073a6db69f3e1d/lib/grunt/utils.js#L121-L145
428414
*/
429415
function processCSS(state, minify, file) {
430-
/* jshint quotmark: false */
431416
var css = fs.readFileSync(file).toString(),
432417
js;
433418
state.css.push(css);

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
"grunt": "^0.4.5",
1919
"grunt-contrib-concat": "^0.5.1",
2020
"grunt-contrib-copy": "^0.8.0",
21-
"grunt-contrib-jshint": "^0.11.1",
2221
"grunt-contrib-uglify": "^0.10.0",
2322
"grunt-contrib-watch": "^0.6.1",
2423
"grunt-conventional-changelog": "^5.0.0",
2524
"grunt-ddescribe-iit": "0.0.6",
25+
"grunt-eslint": "^17.3.1",
2626
"grunt-html2js": "^0.3.0",
2727
"grunt-karma": "^0.12.0",
2828
"jasmine-core": "^2.2.0",
@@ -31,6 +31,7 @@
3131
"karma-coverage": "^0.5.0",
3232
"karma-firefox-launcher": "^0.1.4",
3333
"karma-jasmine": "^0.3.5",
34+
"load-grunt-tasks": "^3.3.0",
3435
"node-markdown": "0.1.1",
3536
"semver": "^5.0.1",
3637
"shelljs": "^0.5.1"

Diff for: src/carousel/carousel.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,8 @@ angular.module('ui.bootstrap.carousel', [])
242242
};
243243
})
244244

245-
.animation('.item', [
246-
'$animate', '$animateCss',
247-
function($animate, $animateCss) {
245+
.animation('.item', ['$animate', '$animateCss',
246+
function($animate, $animateCss) {
248247
var SLIDE_DIRECTION = 'uib-slideDirection';
249248

250249
function removeClass(element, className, callback) {
@@ -257,10 +256,10 @@ function($animate, $animateCss) {
257256
return {
258257
beforeAddClass: function(element, className, done) {
259258
// Due to transclusion, noTransition property is on parent's scope
260-
if (className == 'active' && !$animate.enabled(element)) {
259+
if (className === 'active' && !$animate.enabled(element)) {
261260
var stopped = false;
262261
var direction = element.data(SLIDE_DIRECTION);
263-
var directionClass = direction == 'next' ? 'left' : 'right';
262+
var directionClass = direction === 'next' ? 'left' : 'right';
264263
var removeClassFn = removeClass.bind(this, element,
265264
directionClass + ' ' + direction, done);
266265
element.addClass(direction);
@@ -280,7 +279,7 @@ function($animate, $animateCss) {
280279
if (className === 'active' && !$animate.enabled(element)) {
281280
var stopped = false;
282281
var direction = element.data(SLIDE_DIRECTION);
283-
var directionClass = direction == 'next' ? 'left' : 'right';
282+
var directionClass = direction === 'next' ? 'left' : 'right';
284283
var removeClassFn = removeClass.bind(this, element, directionClass, done);
285284

286285
$animateCss(element, {addClass: directionClass})

Diff for: src/carousel/test/carousel.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('carousel', function() {
4646

4747
function testSlideActive(slideIndex) {
4848
for (var i = 0; i < scope.slides.length; i++) {
49-
if (i == slideIndex) {
49+
if (i === slideIndex) {
5050
expect(scope.slides[i].active).toBe(true);
5151
} else {
5252
expect(scope.slides[i].active).not.toBe(true);

Diff for: src/dateparser/dateparser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ angular.module('ui.bootstrap.dateparser', [])
317317
}
318318

319319
if (month === 1 && date > 28) {
320-
return date === 29 && ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0);
320+
return date === 29 && (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0);
321321
}
322322

323323
if (month === 3 || month === 5 || month === 8 || month === 10) {

Diff for: src/datepicker/datepicker.js

+40-20
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
3030
// Configuration attributes
3131
angular.forEach(['formatDay', 'formatMonth', 'formatYear', 'formatDayHeader', 'formatDayTitle', 'formatMonthTitle',
3232
'showWeeks', 'startingDay', 'yearRange', 'shortcutPropagation'], function(key, index) {
33-
self[key] = angular.isDefined($attrs[key]) ? (index < 6 ? $interpolate($attrs[key])($scope.$parent) : $scope.$parent.$eval($attrs[key])) : datepickerConfig[key];
33+
self[key] = angular.isDefined($attrs[key]) ?
34+
index < 6 ? $interpolate($attrs[key])($scope.$parent) :
35+
$scope.$parent.$eval($attrs[key]) :
36+
datepickerConfig[key];
3437
});
3538

3639
// Watchable date attributes
@@ -50,7 +53,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
5053
$scope.$parent.$watch($parse($attrs[key]), function(value) {
5154
self[key] = angular.isDefined(value) ? value : $attrs[key];
5255
$scope[key] = self[key];
53-
if ((key == 'minMode' && self.modes.indexOf($scope.datepickerMode) < self.modes.indexOf(self[key])) || (key == 'maxMode' && self.modes.indexOf($scope.datepickerMode) > self.modes.indexOf(self[key]))) {
56+
if (key === 'minMode' && self.modes.indexOf($scope.datepickerMode) < self.modes.indexOf(self[key]) ||
57+
key === 'maxMode' && self.modes.indexOf($scope.datepickerMode) > self.modes.indexOf(self[key])) {
5458
$scope.datepickerMode = self[key];
5559
}
5660
});
@@ -118,7 +122,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
118122
this._refreshView();
119123

120124
var date = ngModelCtrl.$viewValue ? new Date(ngModelCtrl.$viewValue) : null;
121-
ngModelCtrl.$setValidity('dateDisabled', !date || (this.element && !this.isDisabled(date)));
125+
ngModelCtrl.$setValidity('dateDisabled', !date ||
126+
this.element && !this.isDisabled(date));
122127
}
123128
};
124129

@@ -135,7 +140,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
135140
};
136141

137142
this.isDisabled = function(date) {
138-
return $scope.disabled || ((this.minDate && this.compare(date, this.minDate) < 0) || (this.maxDate && this.compare(date, this.maxDate) > 0) || ($attrs.dateDisabled && $scope.dateDisabled({date: date, mode: $scope.datepickerMode})));
143+
return $scope.disabled ||
144+
this.minDate && this.compare(date, this.minDate) < 0 ||
145+
this.maxDate && this.compare(date, this.maxDate) > 0 ||
146+
$attrs.dateDisabled && $scope.dateDisabled({date: date, mode: $scope.datepickerMode});
139147
};
140148

141149
this.customClass = function(date) {
@@ -173,7 +181,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
173181
$scope.toggleMode = function(direction) {
174182
direction = direction || 1;
175183

176-
if (($scope.datepickerMode === self.maxMode && direction === 1) || ($scope.datepickerMode === self.minMode && direction === -1)) {
184+
if ($scope.datepickerMode === self.maxMode && direction === 1 ||
185+
$scope.datepickerMode === self.minMode && direction === -1) {
177186
return;
178187
}
179188

@@ -222,7 +231,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
222231
this.step = { months: 1 };
223232
this.element = $element;
224233
function getDaysInMonth(year, month) {
225-
return ((month === 1) && (year % 4 === 0) && ((year % 100 !== 0) || (year % 400 === 0))) ? 29 : DAYS_IN_MONTH[month];
234+
return month === 1 && year % 4 === 0 &&
235+
(year % 100 !== 0 || year % 400 === 0) ? 29 : DAYS_IN_MONTH[month];
226236
}
227237

228238
this.init = function(ctrl) {
@@ -249,7 +259,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
249259
firstDayOfMonth.setFullYear(year, month, 1);
250260

251261
var difference = this.startingDay - firstDayOfMonth.getDay(),
252-
numDisplayedFromPreviousMonth = (difference > 0) ? 7 - difference : - difference,
262+
numDisplayedFromPreviousMonth = difference > 0 ?
263+
7 - difference : - difference,
253264
firstDate = new Date(firstDayOfMonth);
254265

255266
if (numDisplayedFromPreviousMonth > 0) {
@@ -704,12 +715,12 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
704715
date = new Date();
705716
}
706717

707-
return ((scope.watchData.minDate && scope.compare(date, cache.minDate) < 0) ||
708-
(scope.watchData.maxDate && scope.compare(date, cache.maxDate) > 0));
718+
return scope.watchData.minDate && scope.compare(date, cache.minDate) < 0 ||
719+
scope.watchData.maxDate && scope.compare(date, cache.maxDate) > 0;
709720
};
710721

711722
scope.compare = function(date1, date2) {
712-
return (new Date(date1.getFullYear(), date1.getMonth(), date1.getDate()) - new Date(date2.getFullYear(), date2.getMonth(), date2.getDate()));
723+
return new Date(date1.getFullYear(), date1.getMonth(), date1.getDate()) - new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
713724
};
714725

715726
// Inner change
@@ -791,18 +802,22 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
791802

792803
if (!viewValue) {
793804
return null;
794-
} else if (angular.isDate(viewValue) && !isNaN(viewValue)) {
805+
}
806+
807+
if (angular.isDate(viewValue) && !isNaN(viewValue)) {
795808
return viewValue;
796-
} else if (angular.isString(viewValue)) {
809+
}
810+
811+
if (angular.isString(viewValue)) {
797812
var date = dateParser.parse(viewValue, dateFormat, scope.date);
798813
if (isNaN(date)) {
799814
return undefined;
800-
} else {
801-
return date;
802815
}
803-
} else {
804-
return undefined;
816+
817+
return date;
805818
}
819+
820+
return undefined;
806821
}
807822

808823
function validator(modelValue, viewValue) {
@@ -815,16 +830,21 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
815830
if (angular.isNumber(value)) {
816831
value = new Date(value);
817832
}
833+
818834
if (!value) {
819835
return true;
820-
} else if (angular.isDate(value) && !isNaN(value)) {
836+
}
837+
838+
if (angular.isDate(value) && !isNaN(value)) {
821839
return true;
822-
} else if (angular.isString(value)) {
840+
}
841+
842+
if (angular.isString(value)) {
823843
var date = dateParser.parse(value, dateFormat);
824844
return !isNaN(date);
825-
} else {
826-
return false;
827845
}
846+
847+
return false;
828848
}
829849

830850
function documentClickBind(event) {

Diff for: src/datepicker/docs/demo.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($
44
};
55
$scope.today();
66

7-
$scope.clear = function () {
7+
$scope.clear = function() {
88
$scope.dt = null;
99
};
1010

1111
// Disable weekend selection
1212
$scope.disabled = function(date, mode) {
13-
return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
13+
return mode === 'day' && (date.getDay() === 0 || date.getDay() === 6);
1414
};
1515

1616
$scope.toggleMin = function() {
1717
$scope.minDate = $scope.minDate ? null : new Date();
1818
};
19+
1920
$scope.toggleMin();
2021
$scope.maxDate = new Date(2020, 5, 22);
2122

@@ -59,7 +60,7 @@ angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($
5960
if (mode === 'day') {
6061
var dayToCheck = new Date(date).setHours(0,0,0,0);
6162

62-
for (var i=0;i<$scope.events.length;i++){
63+
for (var i = 0; i < $scope.events.length; i++) {
6364
var currentDay = new Date($scope.events[i].date).setHours(0,0,0,0);
6465

6566
if (dayToCheck === currentDay) {

0 commit comments

Comments
 (0)