Skip to content

Commit 2e87f14

Browse files
nfischerariporad
authored andcommitted
chore: update jshint and move it to an npm script (shelljs#454)
1 parent 36cc243 commit 2e87f14

File tree

15 files changed

+88
-87
lines changed

15 files changed

+88
-87
lines changed

.jshintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test/resources/
2+
node_modules/

.jshintrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@
33
"sub": true,
44
"undef": true,
55
"unused": true,
6+
"futurehostile": true,
7+
"latedef": "nofunc",
8+
"nocomma": true,
9+
"nonbsp": true,
10+
"notypeof": true,
611
"node": true
7-
}
12+
}

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ tmp/
44
.documentup.json
55
.gitignore
66
.jshintrc
7+
.jshintignore
78
.lgtm
89
.travis.yml
910
.gitattributes

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
"homepage": "http://github.com/shelljs/shelljs",
2525
"main": "./shell.js",
2626
"scripts": {
27+
"posttest": "npm run lint",
2728
"test": "node scripts/run-tests",
2829
"gendocs": "node scripts/generate-docs",
30+
"lint": "jshint .",
2931
"changelog": "bash scripts/changelog.sh"
3032
},
3133
"bin": {
@@ -38,7 +40,7 @@
3840
},
3941
"devDependencies": {
4042
"coffee-script": "^1.10.0",
41-
"jshint": "~2.1.11"
43+
"jshint": "^2.9.2"
4244
},
4345
"optionalDependencies": {},
4446
"engines": {

scripts/run-tests.js

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,9 @@
11
#!/usr/bin/env node
2-
/* globals cd, echo, exec, exit, ls, pwd, test */
2+
/* globals cd, echo, exec, exit, ls */
33
require('../global');
4-
var common = require('../src/common');
54

65
var failed = false;
76

8-
//
9-
// Lint
10-
//
11-
var JSHINT_BIN = 'node_modules/jshint/bin/jshint';
12-
cd(__dirname + '/..');
13-
14-
if (!test('-f', JSHINT_BIN)) {
15-
echo('JSHint not found. Run `npm install` in the root dir first.');
16-
exit(1);
17-
}
18-
19-
var jsfiles = common.expand([pwd() + '/*.js',
20-
pwd() + '/scripts/*.js',
21-
pwd() + '/src/*.js',
22-
pwd() + '/test/*.js'
23-
]).join(' ');
24-
// Perform linting on all javascript files
25-
if (exec(JSON.stringify(process.execPath)+' '+pwd()+'/'+JSHINT_BIN+' '+jsfiles).code !== 0) {
26-
failed = true;
27-
echo('*** JSHINT FAILED! (return code != 0)');
28-
} else {
29-
echo('All JSHint tests passed');
30-
}
31-
echo();
32-
337
//
348
// Unit tests
359
//

src/common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ exports.error = error;
8787
//@
8888
//@ Turns a regular string into a string-like object similar to what each
8989
//@ command returns. This has special methods, like `.to()` and `.toEnd()`
90-
var ShellString = function (stdout, stderr, code) {
90+
function ShellString(stdout, stderr, code) {
9191
var that;
9292
if (stdout instanceof Array) {
9393
that = stdout;
@@ -106,7 +106,7 @@ var ShellString = function (stdout, stderr, code) {
106106
that[cmd] = function() {return shell[cmd].apply(that.stdout, arguments);};
107107
});
108108
return that;
109-
};
109+
}
110110

111111
exports.ShellString = ShellString;
112112

test/common.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,35 @@ assert.throws(function () {
2626
// Valids
2727
//
2828

29+
var result;
30+
2931
// single file, array syntax
30-
var result = common.expand(['resources/file1.txt']);
32+
result = common.expand(['resources/file1.txt']);
3133
assert.equal(shell.error(), null);
3234
assert.deepEqual(result, ['resources/file1.txt']);
3335

3436
// multiple file, glob syntax, * for file name
35-
var result = common.expand(['resources/file*.txt']);
37+
result = common.expand(['resources/file*.txt']);
3638
assert.equal(shell.error(), null);
3739
assert.deepEqual(result.sort(), ['resources/file1.txt', 'resources/file2.txt'].sort());
3840

3941
// multiple file, glob syntax, * for directory name
40-
var result = common.expand(['*/file*.txt']);
42+
result = common.expand(['*/file*.txt']);
4143
assert.equal(shell.error(), null);
4244
assert.deepEqual(result.sort(), ['resources/file1.txt', 'resources/file2.txt'].sort());
4345

4446
// multiple file, glob syntax, ** for directory name
45-
var result = common.expand(['**/file*.js']);
47+
result = common.expand(['**/file*.js']);
4648
assert.equal(shell.error(), null);
4749
assert.deepEqual(result.sort(), ["resources/file1.js","resources/file2.js","resources/ls/file1.js","resources/ls/file2.js"].sort());
4850

4951
// broken links still expand
50-
var result = common.expand(['resources/b*dlink']);
52+
result = common.expand(['resources/b*dlink']);
5153
assert.equal(shell.error(), null);
5254
assert.deepEqual(result, ['resources/badlink']);
5355

5456
// common.parseOptions (normal case)
55-
var result = common.parseOptions('-Rf', {
57+
result = common.parseOptions('-Rf', {
5658
'R': 'recursive',
5759
'f': 'force',
5860
'r': 'reverse'
@@ -62,7 +64,7 @@ assert.ok(result.force === true);
6264
assert.ok(result.reverse === false);
6365

6466
// common.parseOptions (with mutually-negating options)
65-
var result = common.parseOptions('-f', {
67+
result = common.parseOptions('-f', {
6668
'n': 'no_force',
6769
'f': '!no_force',
6870
'R': 'recursive'
@@ -72,7 +74,7 @@ assert.ok(result.no_force === false);
7274
assert.ok(result.force === undefined); // this key shouldn't exist
7375

7476
// common.parseOptions (the last of the conflicting options should hold)
75-
var result = common.parseOptions('-fn', {
77+
result = common.parseOptions('-fn', {
7678
'n': 'no_force',
7779
'f': '!no_force',
7880
'R': 'recursive'
@@ -82,7 +84,7 @@ assert.ok(result.no_force === true);
8284
assert.ok(result.force === undefined); // this key shouldn't exist
8385

8486
// common.parseOptions using an object to hold options
85-
var result = common.parseOptions({'-v': 'some text here'}, {
87+
result = common.parseOptions({'-v': 'some text here'}, {
8688
'v': 'value',
8789
'f': 'force',
8890
'r': 'reverse'

test/grep.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ shell.mkdir('tmp');
1212
// Invalids
1313
//
1414

15-
var result = shell.grep();
15+
var result;
16+
17+
result = shell.grep();
1618
assert.ok(shell.error());
1719
assert.equal(result.code, 2);
1820

@@ -39,60 +41,60 @@ assert.equal(result.code, 2);
3941
// Valids
4042
//
4143

42-
var result = shell.grep('line', 'resources/a.txt');
44+
result = shell.grep('line', 'resources/a.txt');
4345
assert.equal(shell.error(), null);
4446
assert.equal(result.split('\n').length - 1, 4);
4547

46-
var result = shell.grep('-v', 'line', 'resources/a.txt');
48+
result = shell.grep('-v', 'line', 'resources/a.txt');
4749
assert.equal(shell.error(), null);
4850
assert.equal(result.split('\n').length - 1, 8);
4951

50-
var result = shell.grep('line one', 'resources/a.txt');
52+
result = shell.grep('line one', 'resources/a.txt');
5153
assert.equal(shell.error(), null);
5254
assert.equal(result, 'This is line one\n');
5355

5456
// multiple files
55-
var result = shell.grep(/test/, 'resources/file1.txt', 'resources/file2.txt');
57+
result = shell.grep(/test/, 'resources/file1.txt', 'resources/file2.txt');
5658
assert.equal(shell.error(), null);
5759
assert.equal(result, 'test1\ntest2\n');
5860

5961
// multiple files, array syntax
60-
var result = shell.grep(/test/, ['resources/file1.txt', 'resources/file2.txt']);
62+
result = shell.grep(/test/, ['resources/file1.txt', 'resources/file2.txt']);
6163
assert.equal(shell.error(), null);
6264
assert.equal(result, 'test1\ntest2\n');
6365

6466
// multiple files, glob syntax, * for file name
65-
var result = shell.grep(/test/, 'resources/file*.txt');
67+
result = shell.grep(/test/, 'resources/file*.txt');
6668
assert.equal(shell.error(), null);
6769
assert.ok(result == 'test1\ntest2\n' || result == 'test2\ntest1\n');
6870

6971
// multiple files, glob syntax, * for directory name
70-
var result = shell.grep(/test/, '*/file*.txt');
72+
result = shell.grep(/test/, '*/file*.txt');
7173
assert.equal(shell.error(), null);
7274
assert.ok(result == 'test1\ntest2\n' || result == 'test2\ntest1\n');
7375

7476
// multiple files, glob syntax, ** for directory name
75-
var result = shell.grep(/test/, '**/file*.js');
77+
result = shell.grep(/test/, '**/file*.js');
7678
assert.equal(shell.error(), null);
7779
assert.equal(result, 'test\ntest\ntest\ntest\n');
7880

7981
// one file, * in regex
80-
var result = shell.grep(/alpha*beta/, 'resources/grep/file');
82+
result = shell.grep(/alpha*beta/, 'resources/grep/file');
8183
assert.equal(shell.error(), null);
8284
assert.equal(result, 'alphaaaaaaabeta\nalphbeta\n');
8385

8486
// one file, * in string-regex
85-
var result = shell.grep('alpha*beta', 'resources/grep/file');
87+
result = shell.grep('alpha*beta', 'resources/grep/file');
8688
assert.equal(shell.error(), null);
8789
assert.equal(result, 'alphaaaaaaabeta\nalphbeta\n');
8890

8991
// one file, * in regex, make sure * is not globbed
90-
var result = shell.grep(/l*\.js/, 'resources/grep/file');
92+
result = shell.grep(/l*\.js/, 'resources/grep/file');
9193
assert.equal(shell.error(), null);
9294
assert.equal(result, 'this line ends in.js\nlllllllllllllllll.js\n');
9395

9496
// one file, * in string-regex, make sure * is not globbed
95-
var result = shell.grep('l*\\.js', 'resources/grep/file');
97+
result = shell.grep('l*\\.js', 'resources/grep/file');
9698
assert.equal(shell.error(), null);
9799
assert.equal(result, 'this line ends in.js\nlllllllllllllllll.js\n');
98100

test/pwd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ assert.ok(!_pwd.stderr);
1919
assert.equal(_pwd, path.resolve('.'));
2020

2121
shell.cd('tmp');
22-
var _pwd = shell.pwd();
22+
_pwd = shell.pwd();
2323
assert.equal(_pwd.code, 0);
2424
assert.ok(!_pwd.stderr);
2525
assert.equal(shell.error(), null);

test/rm.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ shell.mkdir('tmp');
1313
// Invalids
1414
//
1515

16-
var result = shell.rm();
16+
var contents;
17+
var result;
18+
19+
result = shell.rm();
1720
assert.ok(shell.error());
1821
assert.equal(result.code, 1);
1922
assert.equal(result.stderr, 'rm: no paths given');
@@ -123,7 +126,7 @@ assert.equal(fs.existsSync('tmp/.hidden'), true);
123126
result = shell.rm('-rf', 'tmp/*');
124127
assert.equal(shell.error(), null);
125128
assert.equal(result.code, 0);
126-
var contents = fs.readdirSync('tmp');
129+
contents = fs.readdirSync('tmp');
127130
assert.equal(contents.length, 1);
128131
assert.equal(contents[0], '.hidden'); // shouldn't remove hiddden if no .* given
129132

@@ -139,7 +142,7 @@ assert.equal(fs.existsSync('tmp/.hidden'), true);
139142
result = shell.rm('-rf', 'tmp/*', 'tmp/.*');
140143
assert.equal(shell.error(), null);
141144
assert.equal(result.code, 0);
142-
var contents = fs.readdirSync('tmp');
145+
contents = fs.readdirSync('tmp');
143146
assert.equal(contents.length, 0);
144147

145148
// recursive dir removal - array-syntax
@@ -154,7 +157,7 @@ assert.equal(fs.existsSync('tmp/.hidden'), true);
154157
result = shell.rm('-rf', ['tmp/*', 'tmp/.*']);
155158
assert.equal(shell.error(), null);
156159
assert.equal(result.code, 0);
157-
var contents = fs.readdirSync('tmp');
160+
contents = fs.readdirSync('tmp');
158161
assert.equal(contents.length, 0);
159162

160163
// removal of a read-only file (unforced)

0 commit comments

Comments
 (0)