Skip to content

Commit 1894ba4

Browse files
committed
[Refactor] use non-hoisted declarations instead of expressions
1 parent e606385 commit 1894ba4

13 files changed

Lines changed: 44 additions & 44 deletions

File tree

eslint.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export default [
2020
'global-require': 'warn',
2121
'id-length': ['error', { min: 1, max: 40 }],
2222
'max-depth': 'off',
23-
'max-lines-per-function': 'warn',
24-
'max-lines': ['error', 360],
23+
'max-lines-per-function': 'off',
24+
'max-lines': 'off',
2525
'max-nested-callbacks': 'off',
2626
'max-params': 'off',
2727
'max-statements-per-line': ['error', { max: 2 }],

lib/async.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ var windowsDriveRegex = /^\w:[/\\]*$/;
1515
var nodeModulesRegex = /[/\\]node_modules[/\\]*$/;
1616

1717
var homedir = getHomedir();
18-
var defaultPaths = function () {
18+
function defaultPaths() {
1919
return [
2020
path.join(homedir, '.node_modules'),
2121
path.join(homedir, '.node_libraries')
2222
];
23-
};
23+
}
2424

2525
var defaultIsFile = function isFile(file, cb) {
2626
fs.stat(file, function (err, stat) {
@@ -49,15 +49,15 @@ var defaultRealpath = function realpath(x, cb) {
4949
});
5050
};
5151

52-
var maybeRealpath = function maybeRealpath(realpath, x, opts, cb) {
52+
function maybeRealpath(realpath, x, opts, cb) {
5353
if (!opts || !opts.preserveSymlinks) {
5454
realpath(x, cb);
5555
} else {
5656
cb(null, x);
5757
}
58-
};
58+
}
5959

60-
var defaultReadPackage = function defaultReadPackage(readFile, pkgfile, cb) {
60+
function defaultReadPackage(readFile, pkgfile, cb) {
6161
readFile(pkgfile, function (readFileErr, body) {
6262
if (readFileErr) cb(readFileErr);
6363
else {
@@ -69,15 +69,15 @@ var defaultReadPackage = function defaultReadPackage(readFile, pkgfile, cb) {
6969
}
7070
}
7171
});
72-
};
72+
}
7373

74-
var getPackageCandidates = function getPackageCandidates(x, start, opts) {
74+
function getPackageCandidates(x, start, opts) {
7575
var dirs = nodeModulesPaths(start, opts, x);
7676
for (var i = 0; i < dirs.length; i++) {
7777
dirs[i] = path.join(dirs[i], x);
7878
}
7979
return dirs;
80-
};
80+
}
8181

8282
module.exports = function resolve(x, options, callback) {
8383
var cb = callback;

lib/node-modules-paths.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var parse = path.parse || require('path-parse'); // eslint-disable-line global-r
44
var driveLetterRegex = /^([A-Za-z]:)/;
55
var uncPathRegex = /^\\\\/;
66

7-
var getNodeModulesDirs = function getNodeModulesDirs(absoluteStart, modules) {
7+
function getNodeModulesDirs(absoluteStart, modules) {
88
var prefix = '/';
99
if (driveLetterRegex.test(absoluteStart)) {
1010
prefix = '';
@@ -24,7 +24,7 @@ var getNodeModulesDirs = function getNodeModulesDirs(absoluteStart, modules) {
2424
return path.resolve(prefix, aPath, moduleDir);
2525
}));
2626
}, []);
27-
};
27+
}
2828

2929
module.exports = function nodeModulesPaths(start, opts, request) {
3030
var modules = opts && opts.moduleDirectory

lib/sync.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ var windowsDriveRegex = /^\w:[/\\]*$/;
1616
var nodeModulesRegex = /[/\\]node_modules[/\\]*$/;
1717

1818
var homedir = getHomedir();
19-
var defaultPaths = function () {
19+
function defaultPaths() {
2020
return [
2121
path.join(homedir, '.node_modules'),
2222
path.join(homedir, '.node_libraries')
2323
];
24-
};
24+
}
2525

2626
var defaultIsFile = function isFile(file) {
2727
try {
@@ -54,24 +54,24 @@ var defaultRealpathSync = function realpathSync(x) {
5454
return x;
5555
};
5656

57-
var maybeRealpathSync = function maybeRealpathSync(realpathSync, x, opts) {
57+
function maybeRealpathSync(realpathSync, x, opts) {
5858
if (!opts || !opts.preserveSymlinks) {
5959
return realpathSync(x);
6060
}
6161
return x;
62-
};
62+
}
6363

64-
var defaultReadPackageSync = function defaultReadPackageSync(readFileSync, pkgfile) {
64+
function defaultReadPackageSync(readFileSync, pkgfile) {
6565
return JSON.parse(readFileSync(pkgfile));
66-
};
66+
}
6767

68-
var getPackageCandidates = function getPackageCandidates(x, start, opts) {
68+
function getPackageCandidates(x, start, opts) {
6969
var dirs = nodeModulesPaths(start, opts, x);
7070
for (var i = 0; i < dirs.length; i++) {
7171
dirs[i] = path.join(dirs[i], x);
7272
}
7373
return dirs;
74-
};
74+
}
7575

7676
module.exports = function resolveSync(x, options) {
7777
if (typeof x !== 'string') {

test/mock.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,14 @@ test('readPackage', function (t) {
281281
});
282282
});
283283

284-
var readPackage = function (readFile, file, cb) {
284+
function readPackage(readFile, file, cb) {
285285
var barPackage = path.join('bar', 'package.json');
286286
if (file.slice(-barPackage.length) === barPackage) {
287287
cb(null, { main: './something-else.js' });
288288
} else {
289289
cb(null, JSON.parse(files[path.resolve(file)]));
290290
}
291-
};
291+
}
292292

293293
t.test('with readPackage', function (st) {
294294
st.plan(3);

test/mock_sync.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,12 @@ test('readPackageSync', function (t) {
180180
);
181181
});
182182

183-
var readPackageSync = function (readFileSync, file) {
183+
function readPackageSync(readFileSync, file) {
184184
if (file.indexOf(path.join('bar', 'package.json')) >= 0) {
185185
return { main: './something-else.js' };
186186
}
187187
return JSON.parse(files[path.resolve(file)]);
188-
};
188+
}
189189

190190
t.test('with readPackage', function (st) {
191191
st.plan(1);

test/node-modules-paths.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var keys = require('object-keys');
55

66
var nodeModulesPaths = require('../lib/node-modules-paths');
77

8-
var verifyDirs = function verifyDirs(t, start, dirs, moduleDirectories, paths) {
8+
function verifyDirs(t, start, dirs, moduleDirectories, paths) {
99
var moduleDirs = [].concat(moduleDirectories || 'node_modules');
1010
if (paths) {
1111
for (var k = 0; k < paths.length; ++k) {
@@ -33,7 +33,7 @@ var verifyDirs = function verifyDirs(t, start, dirs, moduleDirectories, paths) {
3333
counts[foundModuleDirs[j]] = true;
3434
}
3535
t.equal(keys(counts).length, 1, 'all found module directories had the same count');
36-
};
36+
}
3737

3838
test('node-modules-paths', function (t) {
3939
t.test('no options', function (t) {
@@ -65,9 +65,9 @@ test('node-modules-paths', function (t) {
6565
});
6666

6767
t.test('with paths=function option', function (t) {
68-
var paths = function paths(request, absoluteStart, getNodeModulesDirs, opts) {
68+
function paths(request, absoluteStart, getNodeModulesDirs, opts) {
6969
return getNodeModulesDirs().concat(path.join(absoluteStart, 'not node modules', request));
70-
};
70+
}
7171

7272
var start = path.join(__dirname, 'resolver');
7373
var dirs = nodeModulesPaths(start, { paths: paths }, 'pkg');
@@ -78,9 +78,9 @@ test('node-modules-paths', function (t) {
7878
});
7979

8080
t.test('with paths=function skipping node modules resolution', function (t) {
81-
var paths = function paths(request, absoluteStart, getNodeModulesDirs, opts) {
81+
function paths(request, absoluteStart, getNodeModulesDirs, opts) {
8282
return [];
83-
};
83+
}
8484
var start = path.join(__dirname, 'resolver');
8585
var dirs = nodeModulesPaths(start, { paths: paths });
8686
t.deepEqual(dirs, [], 'no node_modules was computed');

test/node_path.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var resolve = require('../');
66
test('$NODE_PATH', function (t) {
77
t.plan(8);
88

9-
var isDir = function (dir, cb) {
9+
function isDir(dir, cb) {
1010
if (dir === '/node_path' || dir === 'node_path/x') {
1111
return cb(null, true);
1212
}
@@ -17,7 +17,7 @@ test('$NODE_PATH', function (t) {
1717
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
1818
return cb(err);
1919
});
20-
};
20+
}
2121

2222
resolve('aaa', {
2323
paths: [

test/pathfilter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ var resolve = require('../');
44

55
var resolverDir = path.join(__dirname, '/pathfilter/deep_ref');
66

7-
var pathFilterFactory = function (t) {
7+
function pathFilterFactory(t) {
88
return function (pkg, x, remainder) {
99
t.equal(pkg.version, '1.2.3');
1010
t.equal(x, path.join(resolverDir, 'node_modules/deep/ref'));
1111
t.equal(remainder, 'ref');
1212
return 'alt';
1313
};
14-
};
14+
}
1515

1616
test('#62: deep module references and the pathFilter', function (t) {
1717
t.test('deep/ref.js', function (st) {

test/pathfilter_sync.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ var resolve = require('../');
55
test('synchronous pathfilter', function (t) {
66
var res;
77
var resolverDir = __dirname + '/pathfilter/deep_ref';
8-
var pathFilter = function (pkg, x, remainder) {
8+
function pathFilter(pkg, x, remainder) {
99
t.equal(pkg.version, '1.2.3');
1010
t.equal(x, path.join(resolverDir, 'node_modules', 'deep', 'ref'));
1111
t.equal(remainder, 'ref');
1212
return 'alt';
13-
};
13+
}
1414

1515
res = resolve.sync('deep/ref', { basedir: resolverDir });
1616
t.equal(res, path.join(resolverDir, 'node_modules', 'deep', 'ref.js'));

0 commit comments

Comments
 (0)