Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 17cc35d

Browse files
committed
chore: use ES6+ linting in test/, gulp/, and config/
- start running ESLint on files in test/ - fix some lint issues - clang-format files in test/
1 parent 45bab33 commit 17cc35d

File tree

8 files changed

+204
-194
lines changed

8 files changed

+204
-194
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ bower-material/
88
code.material.angularjs.org/
99

1010
# Ignore certain project files
11-
# TODO Remove test/ at some point when the files there are fit for linting
12-
test/
1311
src/core/services/compiler/compiler.spec.js
1412
docs/config/template/*.js
1513
docs/app/js/highlight.pack.js

.eslintrc.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "eslint:recommended",
33
"parserOptions": {
4-
"ecmaVersion": 8
4+
"ecmaVersion": 2021
55
},
66
"rules": {
77
"accessor-pairs": "error",
@@ -289,10 +289,12 @@
289289
},
290290
{
291291
"files": [
292-
"**/*.spec.js"
292+
"**/*.spec.js",
293+
"test/*.js"
293294
],
294295
"env": {
295-
"jasmine": true
296+
"jasmine": true,
297+
"browser": true
296298
},
297299
"rules": {
298300
"no-native-reassign": "off",

config/.jshintrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"sub": true,
3+
"multistr": true,
4+
"-W018": true,
5+
"expr": true,
6+
"boss": true,
7+
"laxbreak": true,
8+
"esversion": 9,
9+
"predef": ["angular"]
10+
}

gulp/.jshintrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"sub": true,
3+
"multistr": true,
4+
"-W018": true,
5+
"expr": true,
6+
"boss": true,
7+
"laxbreak": true,
8+
"esversion": 9,
9+
"predef": ["angular"]
10+
}

gulp/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ function filterNonCodeFiles() {
249249
// builds the theming related css and provides it as a JS const for angular
250250
function themeBuildStream() {
251251
// Make a copy so that we don't modify the actual config that is used by other functions
252-
var paths = config.themeBaseFiles.slice(0);
252+
const paths = config.themeBaseFiles.slice(0);
253253
config.componentPaths.forEach(component => paths.push(path.join(component, '*-theme.scss')));
254254
paths.push(config.themeCore);
255255

test/.jshintrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"sub": true,
3+
"multistr": true,
4+
"-W018": true,
5+
"expr": true,
6+
"boss": true,
7+
"laxbreak": true,
8+
"esversion": 9,
9+
"predef": ["angular"]
10+
}

test/angular-material-mocks.js

Lines changed: 115 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/**
2-
*
32
* AngularJS-Material-Mocks
43
*
54
* Developers interested in running their own custom unit tests WITH angular-material.js loaded...
@@ -10,103 +9,105 @@
109
* - Forces $mdAria.expectWithText() to be synchronous
1110
* - Mocks $$rAF.throttle()
1211
* - Captures flush exceptions from $$rAF
13-
*
1412
*/
13+
// eslint-disable-next-line no-shadow-restricted-names
1514
(function(window, angular, undefined) {
1615

17-
'use strict';
16+
'use strict';
1817

1918
// Allow our code to know when they are running inside of a test so they can expose extra services
2019
// that should NOT be exposed to the public but that should be tested.
2120
//
2221
// As an example, see input.js which exposes some animation-related methods.
2322
window._mdMocksIncluded = true;
2423

25-
/**
26-
* @ngdoc module
27-
* @name ngMaterial-mock
28-
* @packageName angular-material-mocks
29-
*
30-
* @description
31-
*
32-
* The `ngMaterial-mock` module provides support
33-
*
34-
*/
35-
angular.module('ngMaterial-mock', [
36-
'ngMock',
37-
'ngAnimateMock',
38-
'material.core'
39-
])
40-
.config(['$provide', function($provide) {
41-
42-
$provide.factory('$material', ['$animate', '$timeout', function($animate, $timeout) {
43-
return {
44-
flushOutstandingAnimations: function() {
45-
// this code is placed in a try-catch statement
46-
// since 1.3 and 1.4 handle their animations differently
47-
// and there may be situations where follow-up animations
48-
// are run in one version and not the other
49-
try { $animate.flush(); } catch(e) {}
50-
},
51-
flushInterimElement: function() {
52-
this.flushOutstandingAnimations();
53-
$timeout.flush();
54-
this.flushOutstandingAnimations();
55-
$timeout.flush();
56-
this.flushOutstandingAnimations();
57-
$timeout.flush();
24+
/**
25+
* @ngdoc module
26+
* @name ngMaterial-mock
27+
* @packageName angular-material-mocks
28+
*
29+
* @description
30+
* The `ngMaterial-mock` module provides support
31+
*/
32+
angular.module('ngMaterial-mock', ['ngMock', 'ngAnimateMock', 'material.core']).config([
33+
'$provide',
34+
function($provide) {
35+
$provide.factory('$material', [
36+
'$animate', '$timeout',
37+
function($animate, $timeout) {
38+
return {
39+
flushOutstandingAnimations: function() {
40+
// this code is placed in a try-catch statement
41+
// since 1.3 and 1.4 handle their animations differently
42+
// and there may be situations where follow-up animations
43+
// are run in one version and not the other
44+
try {
45+
$animate.flush();
46+
// eslint-disable-next-line no-empty
47+
} catch (e) {}
48+
},
49+
flushInterimElement: function() {
50+
this.flushOutstandingAnimations();
51+
$timeout.flush();
52+
this.flushOutstandingAnimations();
53+
$timeout.flush();
54+
this.flushOutstandingAnimations();
55+
$timeout.flush();
56+
}
57+
};
5858
}
59-
};
60-
}]);
61-
62-
/**
63-
* AngularJS Material dynamically generates Style tags
64-
* based on themes and palettes; for each ng-app.
65-
*
66-
* For testing, we want to disable generation and
67-
* <style> DOM injections. So we clear the huge THEME
68-
* styles while testing...
69-
*/
70-
$provide.constant('$MD_THEME_CSS', '/**/');
71-
72-
/**
73-
* Add throttle() and wrap .flush() to catch `no callbacks present`
74-
* errors
75-
*/
76-
$provide.decorator('$$rAF', function throttleInjector($delegate){
77-
78-
$delegate.throttle = function(cb) {
79-
return function() {
80-
cb.apply(this, arguments);
59+
]);
60+
61+
/**
62+
* AngularJS Material dynamically generates Style tags
63+
* based on themes and palettes; for each ng-app.
64+
*
65+
* For testing, we want to disable generation and
66+
* <style> DOM injections. So we clear the huge THEME
67+
* styles while testing...
68+
*/
69+
$provide.constant('$MD_THEME_CSS', '/**/');
70+
71+
/**
72+
* Add throttle() and wrap .flush() to catch `no callbacks present`
73+
* errors
74+
*/
75+
$provide.decorator('$$rAF', function throttleInjector($delegate) {
76+
$delegate.throttle = function(cb) {
77+
return function() {
78+
cb.apply(this, arguments);
79+
};
8180
};
82-
};
83-
84-
var ngFlush = $delegate.flush;
85-
$delegate.flush = function() {
86-
try { ngFlush(); }
87-
catch(e) { ; }
88-
};
8981

90-
return $delegate;
91-
});
92-
93-
/**
94-
* Capture $timeout.flush() errors: "No deferred tasks to be flushed"
95-
* errors
96-
*/
97-
$provide.decorator('$timeout', function throttleInjector($delegate){
98-
99-
var ngFlush = $delegate.flush;
100-
$delegate.flush = function() {
101-
var args = Array.prototype.slice.call(arguments);
102-
try { ngFlush.apply($delegate, args); }
103-
catch(e) { }
104-
};
82+
const ngFlush = $delegate.flush;
83+
$delegate.flush = function() {
84+
try {
85+
ngFlush();
86+
// eslint-disable-next-line no-empty
87+
} catch (e) {}
88+
};
10589

106-
return $delegate;
107-
});
90+
return $delegate;
91+
});
92+
93+
/**
94+
* Capture $timeout.flush() errors: "No deferred tasks to be flushed"
95+
* errors
96+
*/
97+
$provide.decorator('$timeout', function throttleInjector($delegate) {
98+
const ngFlush = $delegate.flush;
99+
$delegate.flush = function() {
100+
const args = Array.prototype.slice.call(arguments);
101+
try {
102+
ngFlush.apply($delegate, args);
103+
// eslint-disable-next-line no-empty
104+
} catch (e) {}
105+
};
108106

109-
}]);
107+
return $delegate;
108+
});
109+
}
110+
]);
110111

111112
/**
112113
* Stylesheet Mocks used by `animateCss.spec.js`
@@ -115,24 +116,23 @@ angular.module('ngMaterial-mock', [
115116
doc = doc ? doc[0] : window.document;
116117
wind = wind || window;
117118

118-
var node = doc.createElement('style');
119-
var head = doc.getElementsByTagName('head')[0];
119+
const node = doc.createElement('style');
120+
const head = doc.getElementsByTagName('head')[0];
120121
head.appendChild(node);
121122

122-
var ss = doc.styleSheets[doc.styleSheets.length - 1];
123+
const ss = doc.styleSheets[doc.styleSheets.length - 1];
123124

124125
return {
125126
addRule: function(selector, styles) {
126127
styles = addVendorPrefix(styles);
127128

128129
try {
129130
ss.insertRule(selector + '{ ' + styles + '}', 0);
130-
}
131-
catch (e) {
131+
} catch (e) {
132132
try {
133133
ss.addRule(selector, styles);
134-
}
135-
catch (e2) {}
134+
// eslint-disable-next-line no-empty
135+
} catch (e2) {}
136136
}
137137
},
138138

@@ -150,37 +150,33 @@ angular.module('ngMaterial-mock', [
150150
* '-webkit-transition:0.5s linear all; transition:0.5s linear all; font-size:100px;'
151151
*/
152152
function addVendorPrefix(styles) {
153-
var cache = { };
153+
const cache = {};
154154

155155
// Decompose into cache registry
156-
styles
157-
.match(/([\-A-Za-z]*)\w\:\w*([A-Za-z0-9\.\-\s]*)/gi)
158-
.forEach(function(style){
159-
var pair = style.split(":");
160-
var key = pair[0];
161-
162-
switch(key) {
163-
case 'transition':
164-
case 'transform':
165-
case 'animation':
166-
case 'transition-duration':
167-
case 'animation-duration':
168-
cache[key] = cache['-webkit-' + key] = pair[1];
169-
break;
170-
default:
171-
cache[key] = pair[1];
172-
}
173-
});
174-
175-
// Recompose full style object (as string)
176-
styles = "";
177-
angular.forEach(cache, function(value, key) {
178-
styles = styles + key + ":" + value + "; ";
179-
});
180-
181-
return styles;
182-
}
156+
styles.match(/([-A-Za-z]*)\w:\w*([A-Za-z0-9.\-\s]*)/gi).forEach(function(style) {
157+
const pair = style.split(':');
158+
const key = pair[0];
159+
160+
switch (key) {
161+
case 'transition':
162+
case 'transform':
163+
case 'animation':
164+
case 'transition-duration':
165+
case 'animation-duration':
166+
cache[key] = cache['-webkit-' + key] = pair[1];
167+
break;
168+
default:
169+
cache[key] = pair[1];
170+
}
171+
});
183172

184-
};
173+
// Recompose full style object (as string)
174+
styles = '';
175+
angular.forEach(cache, function(value, key) {
176+
styles = styles + key + ':' + value + '; ';
177+
});
185178

179+
return styles;
180+
}
181+
};
186182
})(window, window.angular);

0 commit comments

Comments
 (0)