From 6009239042cb651bc7ca6b8c81bbe44c40327430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E5=AE=9A=E8=B0=94=E7=9A=84=E7=8C=AB?= Date: Sat, 4 Aug 2018 06:04:48 +0800 Subject: [PATCH] Chore: rename utils for consistency (#10727) * Chore: rename test files for consistency (refs #10559) * Chore: rename util => utils for consistency --- lib/cli-engine.js | 6 +- lib/config/config-initializer.js | 12 ++-- lib/ignored-paths.js | 6 +- lib/util/glob-utils.js | 4 +- lib/util/naming.js | 4 +- lib/util/source-code-utils.js | 4 +- tests/lib/config/autoconfig.js | 14 ++-- tests/lib/config/config-initializer.js | 8 +-- tests/lib/{ => util}/ast-utils.js | 6 +- .../lib/util/{glob-util.js => glob-utils.js} | 66 +++++++++---------- tests/lib/util/{npm-util.js => npm-utils.js} | 40 +++++------ .../lib/util/{path-util.js => path-utils.js} | 18 ++--- ...urce-code-util.js => source-code-utils.js} | 4 +- 13 files changed, 96 insertions(+), 96 deletions(-) rename tests/lib/{ => util}/ast-utils.js (99%) rename tests/lib/util/{glob-util.js => glob-utils.js} (86%) rename tests/lib/util/{npm-util.js => npm-utils.js} (82%) rename tests/lib/util/{path-util.js => path-utils.js} (81%) rename tests/lib/util/{source-code-util.js => source-code-utils.js} (98%) diff --git a/lib/cli-engine.js b/lib/cli-engine.js index 5f64a7a6d10..9d7246d1e0d 100644 --- a/lib/cli-engine.js +++ b/lib/cli-engine.js @@ -22,7 +22,7 @@ const fs = require("fs"), IgnoredPaths = require("./ignored-paths"), Config = require("./config"), LintResultCache = require("./util/lint-result-cache"), - globUtil = require("./util/glob-utils"), + globUtils = require("./util/glob-utils"), validator = require("./config/config-validator"), hash = require("./util/hash"), ModuleResolver = require("./util/module-resolver"), @@ -492,7 +492,7 @@ class CLIEngine { * @returns {string[]} The equivalent glob patterns. */ resolveFileGlobPatterns(patterns) { - return globUtil.resolveFileGlobPatterns(patterns.filter(Boolean), this.options); + return globUtils.resolveFileGlobPatterns(patterns.filter(Boolean), this.options); } /** @@ -511,7 +511,7 @@ class CLIEngine { } const startTime = Date.now(); - const fileList = globUtil.listFilesToProcess(patterns, options); + const fileList = globUtils.listFilesToProcess(patterns, options); const results = fileList.map(fileInfo => { if (fileInfo.ignored) { return createIgnoreResult(fileInfo.filename, options.cwd); diff --git a/lib/config/config-initializer.js b/lib/config/config-initializer.js index a80506a5556..a6791ba8530 100644 --- a/lib/config/config-initializer.js +++ b/lib/config/config-initializer.js @@ -18,7 +18,7 @@ const util = require("util"), ConfigOps = require("./config-ops"), getSourceCodeOfFiles = require("../util/source-code-utils").getSourceCodeOfFiles, ModuleResolver = require("../util/module-resolver"), - npmUtil = require("../util/npm-utils"), + npmUtils = require("../util/npm-utils"), recConfig = require("../../conf/eslint-recommended"), log = require("../util/logging"); @@ -61,7 +61,7 @@ function writeFile(config, format) { /** * Get the peer dependencies of the given module. * This adds the gotten value to cache at the first time, then reuses it. - * In a process, this function is called twice, but `npmUtil.fetchPeerDependencies` needs to access network which is relatively slow. + * In a process, this function is called twice, but `npmUtils.fetchPeerDependencies` needs to access network which is relatively slow. * @param {string} moduleName The module name to get. * @returns {Object} The peer dependencies of the given module. * This object is the object of `peerDependencies` field of `package.json`. @@ -73,7 +73,7 @@ function getPeerDependencies(moduleName) { if (!result) { log.info(`Checking peerDependencies of ${moduleName}`); - result = npmUtil.fetchPeerDependencies(moduleName); + result = npmUtils.fetchPeerDependencies(moduleName); getPeerDependencies.cache.set(moduleName, result); } @@ -109,7 +109,7 @@ function getModulesList(config, installESLint) { if (installESLint === false) { delete modules.eslint; } else { - const installStatus = npmUtil.checkDevDeps(["eslint"]); + const installStatus = npmUtils.checkDevDeps(["eslint"]); // Mark to show messages if it's new installation of eslint. if (installStatus.eslint === false) { @@ -373,7 +373,7 @@ function hasESLintVersionConflict(answers) { */ function installModules(modules) { log.info(`Installing ${modules.join(", ")}`); - npmUtil.installSyncSaveDev(modules); + npmUtils.installSyncSaveDev(modules); } /* istanbul ignore next: no need to test inquirer */ @@ -438,7 +438,7 @@ function promptUser() { { name: "Google (https://github.com/google/eslint-config-google)", value: "google" } ], when(answers) { - answers.packageJsonExists = npmUtil.checkPackageJson(); + answers.packageJsonExists = npmUtils.checkPackageJson(); return answers.source === "guide" && answers.packageJsonExists; } }, diff --git a/lib/ignored-paths.js b/lib/ignored-paths.js index 634bfbc0ce8..8520090af52 100644 --- a/lib/ignored-paths.js +++ b/lib/ignored-paths.js @@ -12,7 +12,7 @@ const fs = require("fs"), path = require("path"), ignore = require("ignore"), - pathUtil = require("./util/path-utils"); + pathUtils = require("./util/path-utils"); const debug = require("debug")("eslint:ignored-paths"); @@ -328,7 +328,7 @@ class IgnoredPaths { let result = false; const absolutePath = path.resolve(this.options.cwd, filepath); - const relativePath = pathUtil.getRelativePath(absolutePath, this.getBaseDir()); + const relativePath = pathUtils.getRelativePath(absolutePath, this.getBaseDir()); if (typeof category === "undefined") { result = (this.ig.default.filter([relativePath]).length === 0) || @@ -367,7 +367,7 @@ class IgnoredPaths { const filter = ig.createFilter(); return function(absolutePath) { - const relative = pathUtil.getRelativePath(absolutePath, baseDir); + const relative = pathUtils.getRelativePath(absolutePath, baseDir); if (!relative) { return false; diff --git a/lib/util/glob-utils.js b/lib/util/glob-utils.js index 5bb3baa9120..a2be0f0425c 100644 --- a/lib/util/glob-utils.js +++ b/lib/util/glob-utils.js @@ -13,7 +13,7 @@ const lodash = require("lodash"), path = require("path"), GlobSync = require("./glob"), - pathUtil = require("./path-utils"), + pathUtils = require("./path-utils"), IgnoredPaths = require("../ignored-paths"); const debug = require("debug")("eslint:glob-utils"); @@ -77,7 +77,7 @@ function processPath(options) { newPath = pathname.replace(/[/\\]$/, "") + suffix; } - return pathUtil.convertPathToPosix(newPath); + return pathUtils.convertPathToPosix(newPath); }; } diff --git a/lib/util/naming.js b/lib/util/naming.js index d9172296181..aaf00237820 100644 --- a/lib/util/naming.js +++ b/lib/util/naming.js @@ -7,7 +7,7 @@ // Requirements //------------------------------------------------------------------------------ -const pathUtil = require("../util/path-utils"); +const pathUtils = require("../util/path-utils"); //------------------------------------------------------------------------------ // Private @@ -31,7 +31,7 @@ function normalizePackageName(name, prefix) { * https://github.com/eslint/eslint/issues/5644 */ if (normalizedName.indexOf("\\") > -1) { - normalizedName = pathUtil.convertPathToPosix(normalizedName); + normalizedName = pathUtils.convertPathToPosix(normalizedName); } if (normalizedName.charAt(0) === "@") { diff --git a/lib/util/source-code-utils.js b/lib/util/source-code-utils.js index 2baa34899a3..cac13d37067 100644 --- a/lib/util/source-code-utils.js +++ b/lib/util/source-code-utils.js @@ -10,7 +10,7 @@ //------------------------------------------------------------------------------ const CLIEngine = require("../cli-engine"), - globUtil = require("./glob-utils"), + globUtils = require("./glob-utils"), baseDefaultOptions = require("../../conf/default-cli-options"); const debug = require("debug")("eslint:source-code-utils"); @@ -79,7 +79,7 @@ function getSourceCodeOfFiles(patterns, providedOptions, providedCallback) { } debug("constructed options:", options); - const filenames = globUtil.listFilesToProcess(globPatternsList, options) + const filenames = globUtils.listFilesToProcess(globPatternsList, options) .filter(fileInfo => !fileInfo.ignored) .reduce((files, fileInfo) => files.concat(fileInfo.filename), []); diff --git a/tests/lib/config/autoconfig.js b/tests/lib/config/autoconfig.js index dd059f5d159..7d304eeb4d0 100644 --- a/tests/lib/config/autoconfig.js +++ b/tests/lib/config/autoconfig.js @@ -11,7 +11,7 @@ const assert = require("chai").assert, autoconfig = require("../../../lib/config/autoconfig"), - sourceCodeUtil = require("../../../lib/util/source-code-utils"), + sourceCodeUtils = require("../../../lib/util/source-code-utils"), baseDefaultOptions = require("../../../conf/default-cli-options"); const defaultOptions = Object.assign({}, baseDefaultOptions, { cwd: process.cwd() }); @@ -174,7 +174,7 @@ describe("autoconfig", () => { beforeEach(() => { const config = { ignore: false }; - const sourceCode = sourceCodeUtil.getSourceCodeOfFiles(SOURCE_CODE_FIXTURE_FILENAME, config); + const sourceCode = sourceCodeUtils.getSourceCodeOfFiles(SOURCE_CODE_FIXTURE_FILENAME, config); registry = new autoconfig.Registry(rulesConfig); registry = registry.lintSourceCode(sourceCode, defaultOptions); @@ -201,7 +201,7 @@ describe("autoconfig", () => { it("should respect inline eslint config comments (and not crash when they make linting errors)", () => { const config = { ignore: false }; - const sourceCode = sourceCodeUtil.getSourceCodeOfFiles(CONFIG_COMMENTS_FILENAME, config); + const sourceCode = sourceCodeUtils.getSourceCodeOfFiles(CONFIG_COMMENTS_FILENAME, config); const expectedRegistry = [ { config: 2, specificity: 1, errorCount: 3 }, { config: [2, "always"], specificity: 2, errorCount: 3 }, @@ -220,7 +220,7 @@ describe("autoconfig", () => { beforeEach(() => { const config = { ignore: false }; - const sourceCode = sourceCodeUtil.getSourceCodeOfFiles(SOURCE_CODE_FIXTURE_FILENAME, config); + const sourceCode = sourceCodeUtils.getSourceCodeOfFiles(SOURCE_CODE_FIXTURE_FILENAME, config); registry = new autoconfig.Registry(rulesConfig); registry = registry.lintSourceCode(sourceCode, defaultOptions); @@ -248,7 +248,7 @@ describe("autoconfig", () => { beforeEach(() => { const config = { ignore: false }; - const sourceCode = sourceCodeUtil.getSourceCodeOfFiles(SOURCE_CODE_FIXTURE_FILENAME, config); + const sourceCode = sourceCodeUtils.getSourceCodeOfFiles(SOURCE_CODE_FIXTURE_FILENAME, config); let registry = new autoconfig.Registry(errorRulesConfig); registry = registry.lintSourceCode(sourceCode, defaultOptions); @@ -269,7 +269,7 @@ describe("autoconfig", () => { beforeEach(() => { const config = { ignore: false }; - const sourceCode = sourceCodeUtil.getSourceCodeOfFiles(SOURCE_CODE_FIXTURE_FILENAME, config); + const sourceCode = sourceCodeUtils.getSourceCodeOfFiles(SOURCE_CODE_FIXTURE_FILENAME, config); let registry = new autoconfig.Registry(rulesConfig); registry = registry.lintSourceCode(sourceCode, defaultOptions); @@ -293,7 +293,7 @@ describe("autoconfig", () => { it("should not care how many errors the config has", () => { const config = { ignore: false }; - const sourceCode = sourceCodeUtil.getSourceCodeOfFiles(SOURCE_CODE_FIXTURE_FILENAME, config); + const sourceCode = sourceCodeUtils.getSourceCodeOfFiles(SOURCE_CODE_FIXTURE_FILENAME, config); let registry = new autoconfig.Registry(errorRulesConfig); registry = registry.lintSourceCode(sourceCode, defaultOptions); diff --git a/tests/lib/config/config-initializer.js b/tests/lib/config/config-initializer.js index de70ac1565f..3767fe376f3 100644 --- a/tests/lib/config/config-initializer.js +++ b/tests/lib/config/config-initializer.js @@ -16,7 +16,7 @@ const assert = require("chai").assert, sinon = require("sinon"), sh = require("shelljs"), autoconfig = require("../../../lib/config/autoconfig"), - npmUtil = require("../../../lib/util/npm-utils"); + npmUtils = require("../../../lib/util/npm-utils"); const originalDir = process.cwd(); const proxyquire = require("proxyquire").noPreserveCache(); @@ -83,13 +83,13 @@ describe("configInitializer", () => { }); beforeEach(() => { - npmInstallStub = sinon.stub(npmUtil, "installSyncSaveDev"); - npmCheckStub = sinon.stub(npmUtil, "checkDevDeps").callsFake(packages => packages.reduce((status, pkg) => { + npmInstallStub = sinon.stub(npmUtils, "installSyncSaveDev"); + npmCheckStub = sinon.stub(npmUtils, "checkDevDeps").callsFake(packages => packages.reduce((status, pkg) => { status[pkg] = false; return status; }, {})); npmFetchPeerDependenciesStub = sinon - .stub(npmUtil, "fetchPeerDependencies") + .stub(npmUtils, "fetchPeerDependencies") .returns({ eslint: "^3.19.0", "eslint-plugin-jsx-a11y": "^5.0.1", diff --git a/tests/lib/ast-utils.js b/tests/lib/util/ast-utils.js similarity index 99% rename from tests/lib/ast-utils.js rename to tests/lib/util/ast-utils.js index 972882a1219..b2ff37010ed 100644 --- a/tests/lib/ast-utils.js +++ b/tests/lib/util/ast-utils.js @@ -11,9 +11,9 @@ const assert = require("chai").assert, espree = require("espree"), - astUtils = require("../../lib/util/ast-utils"), - Linter = require("../../lib/linter"), - SourceCode = require("../../lib/util/source-code"); + astUtils = require("../../../lib/util/ast-utils"), + Linter = require("../../../lib/linter"), + SourceCode = require("../../../lib/util/source-code"); //------------------------------------------------------------------------------ // Tests diff --git a/tests/lib/util/glob-util.js b/tests/lib/util/glob-utils.js similarity index 86% rename from tests/lib/util/glob-util.js rename to tests/lib/util/glob-utils.js index cbe60b5676b..58bf8883fc6 100644 --- a/tests/lib/util/glob-util.js +++ b/tests/lib/util/glob-utils.js @@ -12,7 +12,7 @@ const assert = require("chai").assert, path = require("path"), os = require("os"), sh = require("shelljs"), - globUtil = require("../../../lib/util/glob-utils"), + globUtils = require("../../../lib/util/glob-utils"), fs = require("fs"); //------------------------------------------------------------------------------ @@ -34,7 +34,7 @@ function getFixturePath(...args) { // Tests //------------------------------------------------------------------------------ -describe("globUtil", () => { +describe("globUtils", () => { before(() => { fixtureDir = `${os.tmpdir()}/eslint/tests/fixtures/`; @@ -53,7 +53,7 @@ describe("globUtil", () => { const opts = { cwd: getFixturePath("glob-util") }; - const result = globUtil.resolveFileGlobPatterns(patterns, opts); + const result = globUtils.resolveFileGlobPatterns(patterns, opts); assert.deepStrictEqual(result, ["one-js-file/**/*.js"]); }); @@ -64,7 +64,7 @@ describe("globUtil", () => { cwd: getFixturePath("glob-util"), globInputPaths: false }; - const result = globUtil.resolveFileGlobPatterns(patterns, opts); + const result = globUtils.resolveFileGlobPatterns(patterns, opts); assert.deepStrictEqual(result, ["one-js-file"]); }); @@ -74,7 +74,7 @@ describe("globUtil", () => { const opts = { cwd: getFixturePath("glob-util") }; - const result = globUtil.resolveFileGlobPatterns(patterns, opts); + const result = globUtils.resolveFileGlobPatterns(patterns, opts); const expected = [`${getFixturePath("glob-util", "one-js-file").replace(/\\/g, "/")}/**/*.js`]; assert.deepStrictEqual(result, expected); @@ -86,7 +86,7 @@ describe("globUtil", () => { cwd: getFixturePath("glob-util"), extensions: [".jsx"] }; - const result = globUtil.resolveFileGlobPatterns(patterns, opts); + const result = globUtils.resolveFileGlobPatterns(patterns, opts); assert.deepStrictEqual(result, ["one-js-file/**/*.jsx"]); }); @@ -97,7 +97,7 @@ describe("globUtil", () => { cwd: getFixturePath("glob-util"), extensions: [".jsx", ".js"] }; - const result = globUtil.resolveFileGlobPatterns(patterns, opts); + const result = globUtils.resolveFileGlobPatterns(patterns, opts); assert.deepStrictEqual(result, ["one-js-file/**/*.{jsx,js}"]); }); @@ -107,7 +107,7 @@ describe("globUtil", () => { const opts = { cwd: getFixturePath("glob-util") }; - const result = globUtil.resolveFileGlobPatterns(patterns, opts); + const result = globUtils.resolveFileGlobPatterns(patterns, opts); assert.deepStrictEqual(result, ["one-js-file/**/*.js", "two-js-files/**/*.js"]); }); @@ -117,7 +117,7 @@ describe("globUtil", () => { const opts = { cwd: getFixturePath("glob-util") }; - const result = globUtil.resolveFileGlobPatterns(patterns, opts); + const result = globUtils.resolveFileGlobPatterns(patterns, opts); assert.deepStrictEqual(result, ["one-js-file/**/*.js"]); }); @@ -127,7 +127,7 @@ describe("globUtil", () => { const opts = { cwd: getFixturePath("glob-util") }; - const result = globUtil.resolveFileGlobPatterns(patterns, opts); + const result = globUtils.resolveFileGlobPatterns(patterns, opts); assert.deepStrictEqual(result, ["one-js-file/**/*.js"]); }); @@ -137,7 +137,7 @@ describe("globUtil", () => { const opts = { cwd: getFixturePath("glob-util") }; - const result = globUtil.resolveFileGlobPatterns(patterns, opts); + const result = globUtils.resolveFileGlobPatterns(patterns, opts); assert.deepStrictEqual(result, ["some-file.js"]); }); @@ -147,7 +147,7 @@ describe("globUtil", () => { const opts = { cwd: getFixturePath() }; - const result = globUtil.resolveFileGlobPatterns(patterns, opts); + const result = globUtils.resolveFileGlobPatterns(patterns, opts); assert.deepStrictEqual(result, ["one-js-file/example.js"]); }); @@ -157,7 +157,7 @@ describe("globUtil", () => { it("should return an array with a resolved (absolute) filename", () => { const patterns = [getFixturePath("glob-util", "one-js-file", "**/*.js")]; - const result = globUtil.listFilesToProcess(patterns, { + const result = globUtils.listFilesToProcess(patterns, { cwd: getFixturePath() }); @@ -169,7 +169,7 @@ describe("globUtil", () => { it("should return an array with a unmodified filename", () => { const patterns = [getFixturePath("glob-util", "one-js-file", "**/*.js")]; - const result = globUtil.listFilesToProcess(patterns, { + const result = globUtils.listFilesToProcess(patterns, { cwd: getFixturePath(), globInputPaths: false }); @@ -182,7 +182,7 @@ describe("globUtil", () => { it("should return all files matching a glob pattern", () => { const patterns = [getFixturePath("glob-util", "two-js-files", "**/*.js")]; - const result = globUtil.listFilesToProcess(patterns, { + const result = globUtils.listFilesToProcess(patterns, { cwd: getFixturePath() }); @@ -201,7 +201,7 @@ describe("globUtil", () => { getFixturePath("glob-util", "two-js-files", "**/*.js"), getFixturePath("glob-util", "one-js-file", "**/*.js") ]; - const result = globUtil.listFilesToProcess(patterns, { + const result = globUtils.listFilesToProcess(patterns, { cwd: getFixturePath() }); @@ -221,7 +221,7 @@ describe("globUtil", () => { const patterns = [getFixturePath("glob-util", "hidden", "**/*.js")]; assert.throws(() => { - globUtil.listFilesToProcess(patterns, { + globUtils.listFilesToProcess(patterns, { cwd: getFixturePath() }); }, `All files matched by '${patterns[0]}' are ignored.`); @@ -229,7 +229,7 @@ describe("globUtil", () => { it("should return hidden files if included in glob pattern", () => { const patterns = [getFixturePath("glob-util", "hidden", "**/.*.js")]; - const result = globUtil.listFilesToProcess(patterns, { + const result = globUtils.listFilesToProcess(patterns, { cwd: getFixturePath() }); @@ -246,7 +246,7 @@ describe("globUtil", () => { const patterns = [directory]; assert.throws(() => { - globUtil.listFilesToProcess(patterns, { + globUtils.listFilesToProcess(patterns, { cwd: getFixturePath() }); }, `All files matched by '${directory}' are ignored.`); @@ -255,7 +255,7 @@ describe("globUtil", () => { it("should ignore and warn for default ignored files when passed explicitly", () => { const filename = getFixturePath("glob-util", "hidden", ".foo.js"); const patterns = [filename]; - const result = globUtil.listFilesToProcess(patterns, { + const result = globUtils.listFilesToProcess(patterns, { cwd: getFixturePath() }); @@ -268,7 +268,7 @@ describe("globUtil", () => { const patterns = [directory]; assert.throws(() => { - globUtil.listFilesToProcess(patterns, { + globUtils.listFilesToProcess(patterns, { cwd: getFixturePath(), ignore: false }); @@ -278,7 +278,7 @@ describe("globUtil", () => { it("should not ignore default ignored files when passed explicitly if ignore is false", () => { const filename = getFixturePath("glob-util", "hidden", ".foo.js"); const patterns = [filename]; - const result = globUtil.listFilesToProcess(patterns, { + const result = globUtils.listFilesToProcess(patterns, { cwd: getFixturePath(), ignore: false }); @@ -292,7 +292,7 @@ describe("globUtil", () => { const patterns = [filename]; assert.throws(() => { - globUtil.listFilesToProcess(patterns, { + globUtils.listFilesToProcess(patterns, { cwd: getFixturePath(), allowMissingGlobs: true }); @@ -304,7 +304,7 @@ describe("globUtil", () => { const patterns = [filename]; assert.throws(() => { - globUtil.listFilesToProcess(patterns, { + globUtils.listFilesToProcess(patterns, { cwd: getFixturePath() }); }, `No files matching '${filename}' were found.`); @@ -315,7 +315,7 @@ describe("globUtil", () => { const options = { ignore: true, ignorePath: getFixturePath("glob-util", "ignored", ".eslintignore") }; assert.throws(() => { - globUtil.listFilesToProcess([pattern], options); + globUtils.listFilesToProcess([pattern], options); }, `All files matched by '${pattern}' are ignored.`); }); @@ -325,14 +325,14 @@ describe("globUtil", () => { const patterns = ["tests/fixtures/glob-util/ignored/**/*.js"]; assert.throws(() => { - globUtil.listFilesToProcess(patterns); + globUtils.listFilesToProcess(patterns); }, `No files matching '${patterns[0]}' were found.`); }); it("should return an ignored file, if ignore option is turned off", () => { const options = { ignore: false }; const patterns = [getFixturePath("glob-util", "ignored", "**/*.js")]; - const result = globUtil.listFilesToProcess(patterns, options); + const result = globUtils.listFilesToProcess(patterns, options); assert.strictEqual(result.length, 1); }); @@ -342,7 +342,7 @@ describe("globUtil", () => { const patterns = [getFixturePath("glob-util", "ignored", "**/*.js")]; assert.throws(() => { - globUtil.listFilesToProcess(patterns, options); + globUtils.listFilesToProcess(patterns, options); }, `All files matched by '${patterns[0]}' are ignored.`); }); @@ -351,7 +351,7 @@ describe("globUtil", () => { const patterns = [getFixturePath("glob-util", "ignored", "**/*.js")]; assert.throws(() => { - globUtil.listFilesToProcess(patterns, options); + globUtils.listFilesToProcess(patterns, options); }, `All files matched by '${patterns[0]}' are ignored.`); }); @@ -360,7 +360,7 @@ describe("globUtil", () => { getFixturePath("glob-util", "one-js-file", "**/*.js"), getFixturePath("glob-util", "one-js-file", "baz.js") ]; - const result = globUtil.listFilesToProcess(patterns, { + const result = globUtils.listFilesToProcess(patterns, { cwd: path.join(fixtureDir, "..") }); @@ -376,7 +376,7 @@ describe("globUtil", () => { const options = { ignore: true, ignorePattern: "foo.js", cwd: getFixturePath() }; const filename = getFixturePath("glob-util", "ignored", "foo.js"); const patterns = [filename]; - const result = globUtil.listFilesToProcess(patterns, options); + const result = globUtils.listFilesToProcess(patterns, options); assert.strictEqual(result.length, 1); assert.deepStrictEqual(result, [ @@ -388,7 +388,7 @@ describe("globUtil", () => { const options = { cwd: getFixturePath("glob-util") }; const glob = getFixturePath("glob-util", "**/*.js"); const patterns = [glob]; - const result = globUtil.listFilesToProcess(patterns, options); + const result = globUtils.listFilesToProcess(patterns, options); const resultFilenames = result.map(resultObj => resultObj.filename); assert.notInclude(resultFilenames, getFixturePath("glob-util", "node_modules", "dependency.js")); @@ -398,7 +398,7 @@ describe("globUtil", () => { const options = { ignorePattern: "!/node_modules/dependency.js", cwd: getFixturePath("glob-util") }; const glob = getFixturePath("glob-util", "**/*.js"); const patterns = [glob]; - const result = globUtil.listFilesToProcess(patterns, options); + const result = globUtils.listFilesToProcess(patterns, options); const unignoredFilename = getFixturePath("glob-util", "node_modules", "dependency.js"); assert.includeDeepMembers(result, [{ filename: unignoredFilename, ignored: false }]); diff --git a/tests/lib/util/npm-util.js b/tests/lib/util/npm-utils.js similarity index 82% rename from tests/lib/util/npm-util.js rename to tests/lib/util/npm-utils.js index 01dc1f02581..1b07f37153f 100644 --- a/tests/lib/util/npm-util.js +++ b/tests/lib/util/npm-utils.js @@ -11,7 +11,7 @@ const assert = require("chai").assert, spawn = require("cross-spawn"), sinon = require("sinon"), - npmUtil = require("../../../lib/util/npm-utils"), + npmUtils = require("../../../lib/util/npm-utils"), log = require("../../../lib/util/logging"), mockFs = require("mock-fs"); @@ -19,7 +19,7 @@ const assert = require("chai").assert, // Tests //------------------------------------------------------------------------------ -describe("npmUtil", () => { +describe("npmUtils", () => { let sandbox; @@ -36,7 +36,7 @@ describe("npmUtil", () => { let installStatus; before(() => { - installStatus = npmUtil.checkDevDeps(["debug", "mocha", "notarealpackage", "jshint"]); + installStatus = npmUtils.checkDevDeps(["debug", "mocha", "notarealpackage", "jshint"]); }); it("should not find a direct dependency of the project", () => { @@ -56,7 +56,7 @@ describe("npmUtil", () => { }); it("should return false for a single, non-existent package", () => { - installStatus = npmUtil.checkDevDeps(["notarealpackage"]); + installStatus = npmUtils.checkDevDeps(["notarealpackage"]); assert.isFalse(installStatus.notarealpackage); }); @@ -66,7 +66,7 @@ describe("npmUtil", () => { }); // Should not throw. - npmUtil.checkDevDeps(["some-package"]); + npmUtils.checkDevDeps(["some-package"]); }); it("should throw with message when parsing invalid package.json", () => { @@ -76,7 +76,7 @@ describe("npmUtil", () => { assert.throws(() => { try { - npmUtil.checkDevDeps(["some-package"]); + npmUtils.checkDevDeps(["some-package"]); } catch (error) { assert.strictEqual(error.messageTemplate, "failed-to-read-json"); throw error; @@ -89,7 +89,7 @@ describe("npmUtil", () => { let installStatus; before(() => { - installStatus = npmUtil.checkDeps(["debug", "mocha", "notarealpackage", "jshint"]); + installStatus = npmUtils.checkDeps(["debug", "mocha", "notarealpackage", "jshint"]); }); afterEach(() => { @@ -113,13 +113,13 @@ describe("npmUtil", () => { }); it("should return false for a single, non-existent package", () => { - installStatus = npmUtil.checkDeps(["notarealpackage"]); + installStatus = npmUtils.checkDeps(["notarealpackage"]); assert.isFalse(installStatus.notarealpackage); }); it("should throw if no package.json can be found", () => { assert.throws(() => { - installStatus = npmUtil.checkDeps(["notarealpackage"], "/fakepath"); + installStatus = npmUtils.checkDeps(["notarealpackage"], "/fakepath"); }, "Could not find a package.json file"); }); @@ -129,7 +129,7 @@ describe("npmUtil", () => { }); // Should not throw. - npmUtil.checkDeps(["some-package"]); + npmUtils.checkDeps(["some-package"]); }); it("should throw with message when parsing invalid package.json", () => { @@ -139,7 +139,7 @@ describe("npmUtil", () => { assert.throws(() => { try { - npmUtil.checkDeps(["some-package"]); + npmUtils.checkDeps(["some-package"]); } catch (error) { assert.strictEqual(error.messageTemplate, "failed-to-read-json"); throw error; @@ -158,12 +158,12 @@ describe("npmUtil", () => { "package.json": "{ \"file\": \"contents\" }" }); - assert.strictEqual(npmUtil.checkPackageJson(), true); + assert.strictEqual(npmUtils.checkPackageJson(), true); }); it("should return false if package.json does not exist", () => { mockFs({}); - assert.strictEqual(npmUtil.checkPackageJson(), false); + assert.strictEqual(npmUtils.checkPackageJson(), false); }); }); @@ -171,7 +171,7 @@ describe("npmUtil", () => { it("should invoke npm to install a single desired package", () => { const stub = sandbox.stub(spawn, "sync").returns({ stdout: "" }); - npmUtil.installSyncSaveDev("desired-package"); + npmUtils.installSyncSaveDev("desired-package"); assert(stub.calledOnce); assert.strictEqual(stub.firstCall.args[0], "npm"); assert.deepStrictEqual(stub.firstCall.args[1], ["i", "--save-dev", "desired-package"]); @@ -181,7 +181,7 @@ describe("npmUtil", () => { it("should accept an array of packages to install", () => { const stub = sandbox.stub(spawn, "sync").returns({ stdout: "" }); - npmUtil.installSyncSaveDev(["first-package", "second-package"]); + npmUtils.installSyncSaveDev(["first-package", "second-package"]); assert(stub.calledOnce); assert.strictEqual(stub.firstCall.args[0], "npm"); assert.deepStrictEqual(stub.firstCall.args[1], ["i", "--save-dev", "first-package", "second-package"]); @@ -190,14 +190,14 @@ describe("npmUtil", () => { it("should log an error message if npm throws ENOENT error", () => { const logErrorStub = sandbox.stub(log, "error"); - const npmUtilStub = sandbox.stub(spawn, "sync").returns({ error: { code: "ENOENT" } }); + const npmUtilsStub = sandbox.stub(spawn, "sync").returns({ error: { code: "ENOENT" } }); - npmUtil.installSyncSaveDev("some-package"); + npmUtils.installSyncSaveDev("some-package"); assert(logErrorStub.calledOnce); logErrorStub.restore(); - npmUtilStub.restore(); + npmUtilsStub.restore(); }); }); @@ -205,7 +205,7 @@ describe("npmUtil", () => { it("should execute 'npm show --json peerDependencies' command", () => { const stub = sandbox.stub(spawn, "sync").returns({ stdout: "" }); - npmUtil.fetchPeerDependencies("desired-package"); + npmUtils.fetchPeerDependencies("desired-package"); assert(stub.calledOnce); assert.strictEqual(stub.firstCall.args[0], "npm"); assert.deepStrictEqual(stub.firstCall.args[1], ["show", "--json", "desired-package", "peerDependencies"]); @@ -215,7 +215,7 @@ describe("npmUtil", () => { it("should return null if npm throws ENOENT error", () => { const stub = sandbox.stub(spawn, "sync").returns({ error: { code: "ENOENT" } }); - const peerDependencies = npmUtil.fetchPeerDependencies("desired-package"); + const peerDependencies = npmUtils.fetchPeerDependencies("desired-package"); assert.isNull(peerDependencies); diff --git a/tests/lib/util/path-util.js b/tests/lib/util/path-utils.js similarity index 81% rename from tests/lib/util/path-util.js rename to tests/lib/util/path-utils.js index c5022cd2079..f0e1061f518 100644 --- a/tests/lib/util/path-util.js +++ b/tests/lib/util/path-utils.js @@ -11,7 +11,7 @@ const path = require("path"), assert = require("chai").assert, sinon = require("sinon"), - pathUtil = require("../../../lib/util/path-utils"); + pathUtils = require("../../../lib/util/path-utils"); //------------------------------------------------------------------------------ // Tests @@ -23,28 +23,28 @@ describe("pathUtil", () => { it("should remove a leading './'", () => { const input = "./relative/file/path.js"; - const result = pathUtil.convertPathToPosix(input); + const result = pathUtils.convertPathToPosix(input); assert.strictEqual(result, "relative/file/path.js"); }); it("should remove interior '../'", () => { const input = "./relative/file/../path.js"; - const result = pathUtil.convertPathToPosix(input); + const result = pathUtils.convertPathToPosix(input); assert.strictEqual(result, "relative/path.js"); }); it("should not remove a leading '../'", () => { const input = "../parent/file/path.js"; - const result = pathUtil.convertPathToPosix(input); + const result = pathUtils.convertPathToPosix(input); assert.strictEqual(result, "../parent/file/path.js"); }); it("should convert windows path seperators into posix style path seperators", () => { const input = "windows\\style\\path.js"; - const result = pathUtil.convertPathToPosix(input); + const result = pathUtils.convertPathToPosix(input); assert.strictEqual(result, "windows/style/path.js"); }); @@ -56,7 +56,7 @@ describe("pathUtil", () => { it("should return a path relative to the provided base path", () => { const filePath = "/absolute/file/path.js"; const basePath = "/absolute/"; - const result = pathUtil.getRelativePath(filePath, basePath); + const result = pathUtils.getRelativePath(filePath, basePath); assert.strictEqual(result, path.normalize("file/path.js")); }); @@ -66,7 +66,7 @@ describe("pathUtil", () => { const basePath = "somewhere/"; assert.throws(() => { - pathUtil.getRelativePath(filePath, basePath); + pathUtils.getRelativePath(filePath, basePath); }); }); @@ -75,7 +75,7 @@ describe("pathUtil", () => { const basePath = "/absolute/file"; sinon.stub(process, "cwd").returns("/absolute/"); - const result = pathUtil.getRelativePath(filePath, basePath); + const result = pathUtils.getRelativePath(filePath, basePath); assert.strictEqual(result, "path.js"); @@ -84,7 +84,7 @@ describe("pathUtil", () => { it("should strip a leading '/' if no baseDir is provided", () => { const filePath = "/absolute/file/path.js"; - const result = pathUtil.getRelativePath(filePath); + const result = pathUtils.getRelativePath(filePath); assert.strictEqual(result, "absolute/file/path.js"); }); diff --git a/tests/lib/util/source-code-util.js b/tests/lib/util/source-code-utils.js similarity index 98% rename from tests/lib/util/source-code-util.js rename to tests/lib/util/source-code-utils.js index 6b9ca7d1893..7d3350a0d04 100644 --- a/tests/lib/util/source-code-util.js +++ b/tests/lib/util/source-code-utils.js @@ -15,7 +15,7 @@ const path = require("path"), assert = require("chai").assert, sinon = require("sinon"), sh = require("shelljs"), - globUtil = require("../../../lib/util/glob-utils"), + globUtils = require("../../../lib/util/glob-utils"), SourceCode = require("../../../lib/util/source-code"); const proxyquire = require("proxyquire").noCallThru().noPreserveCache(); @@ -139,7 +139,7 @@ describe("SourceCodeUtil", () => { it("should use default options if none are provided", () => { const filename = getFixturePath("foo.js"); - const spy = sinon.spy(globUtil, "resolveFileGlobPatterns"); + const spy = sinon.spy(globUtils, "resolveFileGlobPatterns"); getSourceCodeOfFiles(filename); assert(spy.called);