8000 refactor(jshint): don't assume browser-only globals · angular/angular.js@29b65d6 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 29b65d6

Browse files
committed
refactor(jshint): don't assume browser-only globals
Fixes #13442
1 parent fad6c7c commit 29b65d6

36 files changed

+2116
-3985
lines changed

.jshintrc-base

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
{
22
"bitwise": true,
3+
"esversion": 6,
34
"immed": true,
45
"newcap": true,
56
"noarg": true,
67
"noempty": true,
78
"nonew": true,
8-
"trailing": true,
99
"maxlen": 200,
1010
"boss": true,
1111
"eqnull": true,
1212
"expr": true,
13-
"globalstrict": true,
1413
"laxbreak": true,
1514
"loopfunc": true,
15+
"strict": "global",
1616
"sub": true,
1717
"undef": true,
18-
"indent": 2
18+
"indent": 2,
19+
20+
"globals": {
21+
"ArrayBuffer": false,
22+
"Uint8Array": false
23+
}
1924
}

docs/app/e2e/.jshintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
"dump": false,
2020

2121
/* e2e */
22+
"protractor": false,
2223
"browser": false,
2324
"element": false,
2425
"by": false,
26+
"$": false,
27+
"$$": false,
2528

2629
/* testabilityPatch / matchers */
2730
"inject": false,
@@ -39,4 +42,4 @@
3942
"browserTrigger": false,
4043
"jqLiteCacheSize": false
4144
}
42-
}
45+
}

docs/gulpfile.js

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"use strict";
22

3+
var fs = require('fs');
4+
var _ = require('lodash');
5+
var stripJsonComments = require('strip-json-comments');
6+
37
var gulp = require('gulp');
48
var log = require('gulp-util').log;
59
var concat = require('gulp-concat');
@@ -25,6 +29,23 @@ var ignoredFiles = '!src/angular.bind.js';
2529
var assets = 'app/assets/**/*';
2630

2731

32+
var getJshintConfig = function(filepath) {
33+
return JSON.parse(stripJsonComments(fs.readFileSync(filepath, {encoding: 'utf-8'})));
34+
};
35+
36+
var getMergedJshintConfig = function(filepath) {
37+
// "extends" doesn't work in configuration passed by an object, we need to do the extending ourselves.
38+
var config = getJshintConfig(filepath);
39+
var baseConfig = getJshintConfig('../.jshintrc-base');
40+
_.merge(config, baseConfig);
41+
delete config.extends;
42+
43+
// Examples don't run in strict mode; accept that for now.
44+
config.strict = false;
45+
46+
return config;
47+
};
48+
2849
var copyComponent = function(component, pattern, sourceFolder, packageFile) {
2950
pattern = pattern || '/**/*';
3051
sourceFolder = sourceFolder || bowerFolder;
@@ -88,7 +109,7 @@ gulp.task('assets', ['bower'], function() {
88109
});
89110

90111

91-
gulp.task('doc-gen', ['bower'], function() {
112+
gulp.task('doc-gen', ['bower'], function(cb) {
92113
var dgeni = new Dgeni([require('./config')]);
93114
return dgeni.generate().catch(function(error) {
94115
process.exit(1);
@@ -97,10 +118,28 @@ gulp.task('doc-gen', ['bower'], function() {
97118

98119
// JSHint the example and protractor test files
99120
gulp.task('jshint', ['doc-gen'], function() {
100-
gulp.src([outputFolder + '/ptore2e/**/*.js', outputFolder + '/examples/**/*.js'])
101-
.pipe(jshint())
102-
.pipe(jshint.reporter('jshint-stylish'))
103-
.pipe(jshint.reporter('fail'));
121+
var examplesConfig = getMergedJshintConfig('../docs/app/test/.jshintrc');
122+
// Some tests use `alert` which is not assumed to be available even with `"browser": true`.
123+
examplesConfig.globals.alert = false;
124+
125+
var protractorConfig = getMergedJshintConfig('../docs/app/e2e/.jshintrc');
126+
127+
return merge(
128+
gulp.src([
129+
outputFolder + '/examples/**/*.js',
130+
'!' + outputFolder + '/examples/**/protractor.js',
131+
])
132+
.pipe(jshint(examplesConfig))
133+
.pipe(jshint.reporter('jshint-stylish'))
134+
.pipe(jshint.reporter('fail')),
135+
gulp.src([
136+
outputFolder + '/ptore2e/**/*.js',
137+
outputFolder + '/examples/**/protractor.js',
138+
])
139+
.pipe(jshint(protractorConfig))
140+
.pipe(jshint.reporter('jshint-stylish'))
141+
.pipe(jshint.reporter('fail'))
142+
);
104143
});
105144

106145

0 commit comments

Comments
 (0)
0