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

Commit 36831ec

Browse files
committed
refactor(jshint): reduce duplication & test all JS files
1 parent 7d4f0d7 commit 36831ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+369
-440
lines changed

.jshintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/**
2+
lib/htmlparser/**

.jshintrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": ".jshintrc-base",
3+
"node": true,
4+
"globals": {}
5+
}

.jshintrc-base

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"bitwise": true,
3+
"immed": true,
4+
"newcap": true,
5+
"noarg": true,
6+
"noempty": true,
7+
"nonew": true,
8+
"trailing": true,
9+
"maxlen": 200,
10+
"boss": true,
11+
"eqnull": true,
12+
"expr": true,
13+
"globalstrict": true,
14+
"laxbreak": true,
15+
"loopfunc": true,
16+
"sub": true,
17+
"undef": true,
18+
"indent": 2
19+
}

Gruntfile.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var files = require('./angularFiles').files;
24
var util = require('./lib/grunt/utils.js');
35
var versionInfo = require('./lib/versions/version-info');
@@ -107,6 +109,9 @@ module.exports = function(grunt) {
107109
options: {
108110
jshintrc: true,
109111
},
112+
node: {
113+
files: { src: ['*.js', 'lib/**/*.js'] },
114+
},
110115
tests: {
111116
files: { src: 'test/**/*.js' },
112117
},
@@ -260,7 +265,11 @@ module.exports = function(grunt) {
260265
compress: {
261266
build: {
262267
options: {archive: 'build/' + dist +'.zip', mode: 'zip'},
263-
src: ['**'], cwd: 'build', expand: true, dot: true, dest: dist + '/'
268+
src: ['**'],
269+
cwd: 'build',
270+
expand: true,
271+
dot: true,
272+
dest: dist + '/'
264273
}
265274
},
266275

angularFiles.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
angularFiles = {
1+
'use strict';
2+
3+
var angularFiles = {
24
'angularSrc': [
35
'src/minErr.js',
46
'src/Angular.js',

changelog.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// TODO(vojta): pre-commit hook for validating messages
44
// TODO(vojta): report errors, currently Q silence everything which really sucks
55

6+
'use strict';
7+
68
var child = require('child_process');
79
var fs = require('fs');
810
var util = require('util');
@@ -164,15 +166,15 @@ var writeChangelog = function(stream, commits, version) {
164166
hash: commit.hash,
165167
closes: []
166168
});
167-
};
169+
}
168170
});
169171

170172
stream.write(util.format(HEADER_TPL, version, version, currentDate()));
171173
printSection(stream, 'Bug Fixes', sections.fix);
172174
printSection(stream, 'Features', sections.feat);
173175
printSection(stream, 'Performance Improvements', sections.perf);
174176
printSection(stream, 'Breaking Changes', sections.breaks, false);
175-
}
177+
};
176178

177179

178180
var getPreviousTag = function() {

changelog.spec.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/* global describe: false, it: false, expect: false */
2+
3+
'use strict';
4+
15
describe('changelog.js', function() {
26
var ch = require('./changelog');
37

@@ -13,7 +17,7 @@ describe('changelog.js', function() {
1317
expect(msg.hash).toBe('9b1aff905b638aa274a5fc8f88662df446d374bd');
1418
expect(msg.subject).toBe('broadcast $destroy event on scope destruction');
1519
expect(msg.body).toBe('perf testing shows that in chrome this change adds 5-15% overhead\n' +
16-
'when destroying 10k nested scopes where each scope has a $destroy listener\n')
20+
'when destroying 10k nested scopes where each scope has a $destroy listener\n');
1721
expect(msg.component).toBe('scope');
1822
});
1923

compare-master-to-stable.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env node
22

3+
'use strict';
4+
35
var util = require('util');
46
var cp = require('child_process');
57

@@ -146,7 +148,7 @@ then(allInSeries(function (branch) {
146148
return sha + (msg.toLowerCase().indexOf('fix') === -1 ? ' ' : ' * ') + msg;
147149
});
148150
branch.log = log.map(function (line) {
149-
return line.substr(41)
151+
return line.substr(41);
150152
});
151153
return branch;
152154
});

gdocs.js

+79-74
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env node
22

3+
'use strict';
4+
35
var http = require('http');
46
var https = require('https');
57
var fs = require('fs');
@@ -41,63 +43,63 @@ function help() {
4143
console.log('gdocs.js --login <username>');
4244
console.log('gdocs.js --fetch [<docs collection>]');
4345
process.exit(-1);
44-
};
46+
}
4547

4648

4749
function fetch(collection, url){
4850
console.log('fetching a list of docs in collection ' + collection + '...');
4951
request('GET', url, {
50-
headers: {
51-
'Gdata-Version': '3.0',
52-
'Authorization': 'GoogleLogin auth=' + getAuthToken()
53-
}
54-
},
55-
function(chunk){
56-
var entries = chunk.split('<entry');
57-
entries.shift();
58-
entries.forEach(function(entry){
59-
var title = entry.match(/<title>(.*?)<\/title>/)[1];
60-
if (title.match(/\.ngdoc$/)) {
61-
var exportUrl = entry.match(/<content type='text\/html' src='(.*?)'\/>/)[1];
62-
download(collection, title, exportUrl);
63-
};
64-
});
52+
headers: {
53+
'Gdata-Version': '3.0',
54+
'Authorization': 'GoogleLogin auth=' + getAuthToken()
6555
}
66-
);
56+
},
57+
function(chunk){
58+
var entries = chunk.split('<entry');
59+
entries.shift();
60+
entries.forEach(function(entry){
61+
var title = entry.match(/<title>(.*?)<\/title>/)[1];
62+
if (title.match(/\.ngdoc$/)) {
63+
var exportUrl = entry.match(/<content type='text\/html' src='(.*?)'\/>/)[1];
64+
download(collection, title, exportUrl);
65+
}
66+
});
67+
}
68+
);
6769
}
6870

6971
function download(collection, name, url) {
7072
console.log('Downloading:', name, '...');
7173
request('GET', url + '&exportFormat=txt',
72-
{
73-
headers: {
74-
'Gdata-Version': '3.0',
75-
'Authorization': 'GoogleLogin auth=' + getAuthToken()
76-
}
77-
},
78-
function(data){
79-
data = data.replace('\ufeff', '');
80-
data = data.replace(/\r\n/mg, '\n');
74+
{
75+
headers: {
76+
'Gdata-Version': '3.0',
77+
'Authorization': 'GoogleLogin auth=' + getAuthToken()
78+
}
79+
},
80+
function(data){
81+
data = data.replace('\ufeff', '');
82+
data = data.replace(/\r\n/mg, '\n');
8183

82-
// strip out all text annotations
83-
data = data.replace(/\[[a-zA-Z]{1,2}\]/mg, '');
84+
// strip out all text annotations
85+
data = data.replace(/\[[a-zA-Z]{1,2}\]/mg, '');
8486

85-
// strip out all docos comments
86-
data = data.replace(/^[^\s_]+:\n\S+[\S\s]*$/m, '');
87+
// strip out all docos comments
88+
data = data.replace(/^[^\s_]+:\n\S+[\S\s]*$/m, '');
8789

88-
// fix smart-quotes
89-
data = data.replace(/[]/g, '"');
90-
data = data.replace(/[]/g, "'");
90+
// fix smart-quotes
91+
data = data.replace(/[]/g, '"');
92+
data = data.replace(/[]/g, "'");
9193

9294

93-
data = data + '\n';
95+
data = data + '\n';
9496

95-
//this should be a bug in Google Doc API, hence need to remove this once the bug is fixed
96-
data = data.replace(/\n\n/g, '\n');
97+
//this should be a bug in Google Doc API, hence need to remove this once the bug is fixed
98+
data = data.replace(/\n\n/g, '\n');
9799

98-
fs.writeFileSync('docs/content/' + collection + '/' + name, reflow(data, 100));
99-
}
100-
);
100+
fs.writeFileSync('docs/content/' + collection + '/' + name, reflow(data, 100));
101+
}
102+
);
101103
}
102104

103105
/**
@@ -111,34 +113,34 @@ function download(collection, name, url) {
111113
*/
112114
function login(username, password){
113115
request('POST', 'https://www.google.com/accounts/ClientLogin',
114-
{
115-
data: {
116-
Email: username,
117-
Passwd: password,
118-
accountType: 'GOOGLE',
119-
service: 'writely',
120-
'Gdata-version': '3.0'
121-
},
122-
headers: {
123-
'Content-type': 'application/x-www-form-urlencoded'
124-
}
116+
{
117+
data: {
118+
Email: username,
119+
Passwd: password,
120+
accountType: 'GOOGLE',
121+
service: 'writely',
122+
'Gdata-version': '3.0'
125123
},
126-
function(chunk){
127-
var token;
128-
chunk.split('\n').forEach(function(line){
129-
var parts = line.split('=');
130-
if (parts[0] == 'Auth') {
131-
token = parts[1];
132-
}
133-
});
134-
if (token) {
135-
fs.writeFileSync('tmp/gdocs.auth', token);
136-
console.log("logged in, token saved in 'tmp/gdocs.auth'");
137-
} else {
138-
console.log('failed to log in');
124+
headers: {
125+
'Content-type': 'application/x-www-form-urlencoded'
126+
}
127+
},
128+
function(chunk){
129+
var token;
130+
chunk.split('\n').forEach(function(line){
131+
var parts = line.split('=');
132+
if (parts[0] == 'Auth') {
133+
token = parts[1];
139134
}
135+
});
136+
if (token) {
137+
fs.writeFileSync('tmp/gdocs.auth', token);
138+
console.log("logged in, token saved in 'tmp/gdocs.auth'");
139+
} else {
140+
console.log('failed to log in');
140141
}
141-
);
142+
}
143+
);
142144
}
143145

144146
function getAuthToken() {
@@ -152,17 +154,18 @@ function getAuthToken() {
152154
}
153155

154156
function request(method, url, options, response) {
155-
var url = url.match(/http(s?):\/\/(.+?)(\/.*)/);
157+
url = url.match(/http(s?):\/\/(.+?)(\/.*)/);
156158
var isHttps = url[1];
157-
var request = (isHttps ? https : http).request({
159+
var req = (isHttps ? https : http).request({
158160
host: url[2],
159161
port: (url[1] ? 443 : 80),
160162
path: url[3],
161163
method: method
162164
}, function(res){
165+
var data;
163166
switch (res.statusCode) {
164167
case 200:
165-
var data = [];
168+
data = [];
166169
res.setEncoding('utf8');
167170
res.on('end', function () { response(data.join('')); });
168171
res.on('close', function () { response(data.join('')); }); // https
@@ -173,7 +176,7 @@ function request(method, url, options, response) {
173176
console.log('Eror: Login credentials expired! Please login.');
174177
break;
175178
default:
176-
var data = [];
179+
data = [];
177180
console.log('ERROR: ', res.statusCode);
178181
console.log('REQUEST URL: ', url[0]);
179182
console.log('REQUEST POST: ', options.data);
@@ -186,14 +189,14 @@ function request(method, url, options, response) {
186189
}
187190
});
188191
for(var header in options.headers) {
189-
request.setHeader(header, options.headers[header]);
192+
req.setHeader(header, options.headers[header]);
190193
}
191194
if (options.data)
192-
request.write(encodeData(options.data));
193-
request.on('end', function() {
195+
req.write(encodeData(options.data));
196+
req.on('end', function() {
194197
console.log('end');
195198
});
196-
request.end();
199+
req.end();
197200
}
198201

199202
function encodeData(obj) {
@@ -215,7 +218,9 @@ function askPassword(callback) {
215218
stdin.on("data", function(c) {
216219
c = c + "";
217220
switch (c) {
218-
case "\n": case "\r": case "\u0004":
221+
case "\n":
222+
case "\r":
223+
case "\u0004":
219224
stdio.setRawMode(false);
220225
stdin.pause();
221226
callback(password);
@@ -227,7 +232,7 @@ function askPassword(callback) {
227232
password += c;
228233
break;
229234
}
230-
})
235+
});
231236

232237
}
233238

karma-docs.conf.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var sharedConfig = require('./karma-shared.conf');
24

35
module.exports = function(config) {

karma-jqlite.conf.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var angularFiles = require('./angularFiles');
24
var sharedConfig = require('./karma-shared.conf');
35

karma-jquery.conf.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var angularFiles = require('./angularFiles');
24
var sharedConfig = require('./karma-shared.conf');
35

karma-modules.conf.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var angularFiles = require('./angularFiles');
24
var sharedConfig = require('./karma-shared.conf');
35

0 commit comments

Comments
 (0)