Skip to content

Commit

Permalink
chore: Remove unused code (#36)
Browse files Browse the repository at this point in the history
* chore: Remove unused unIndent test helper

* chore: Remove unused createCustomTeardown test helper

This also allows us to remove the `fs-teardown` dependency.

* chore: Remove re-export test helper

With the other two unused helpers removed, `index.js` now just
re-exports a single import. This commit removes it and updates the two
imports to point to the underlying file.

* chore: Remove unused error.messageTemplate

ESLint's CLI uses `.messageTemplate` to pretty-print errors, but no such
functionality exists in `@eslint/create-config`.
  • Loading branch information
btmills committed Aug 24, 2022
1 parent 24a7337 commit 368a1a3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 91 deletions.
14 changes: 1 addition & 13 deletions lib/init/npm-utils.js
Expand Up @@ -101,24 +101,12 @@ function fetchPeerDependencies(packageName) {
function check(packages, opt) {
const deps = new Set();
const pkgJson = (opt) ? findPackageJson(opt.startDir) : findPackageJson();
let fileJson;

if (!pkgJson) {
throw new Error("Could not find a package.json file. Run 'npm init' to create one.");
}

try {
fileJson = JSON.parse(fs.readFileSync(pkgJson, "utf8"));
} catch (e) {
const error = new Error(e);

error.messageTemplate = "failed-to-read-json";
error.messageData = {
path: pkgJson,
message: e.message
};
throw error;
}
const fileJson = JSON.parse(fs.readFileSync(pkgJson, "utf8"));

["dependencies", "devDependencies"].forEach(key => {
if (opt[key] && typeof fileJson[key] === "object") {
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -62,7 +62,6 @@
"eslint-release": "^3.2.0",
"esmock": "^1.8.8",
"espree": "^9.0.0",
"fs-teardown": "^0.3.0",
"lint-staged": "^12.1.2",
"memfs": "^3.4.0",
"mocha": "^9.1.3",
Expand Down
61 changes: 0 additions & 61 deletions tests/_utils/index.js

This file was deleted.

2 changes: 1 addition & 1 deletion tests/init/config-initializer.js
Expand Up @@ -16,7 +16,7 @@ import sh from "shelljs";
import esmock from "esmock";
import { fileURLToPath } from "url";
import * as npmUtils from "../../lib/init/npm-utils.js";
import { defineInMemoryFs } from "../_utils/index.js";
import { defineInMemoryFs } from "../_utils/in-memory-fs.js";

const originalDir = process.cwd();
const { assert } = chai;
Expand Down
20 changes: 5 additions & 15 deletions tests/init/npm-utils.js
Expand Up @@ -17,7 +17,7 @@ import {
checkDeps,
checkDevDeps
} from "../../lib/init/npm-utils.js";
import { defineInMemoryFs } from "../_utils/index.js";
import { defineInMemoryFs } from "../_utils/in-memory-fs.js";
import esmock from "esmock";

const { assert } = chai;
Expand Down Expand Up @@ -89,13 +89,8 @@ describe("npmUtils", () => {
});

assert.throws(() => {
try {
stubcheckDevDeps(["some-package"]);
} catch (error) {
assert.strictEqual(error.messageTemplate, "failed-to-read-json");
throw error;
}
}, "SyntaxError: Unexpected token v");
stubcheckDevDeps(["some-package"]);
}, /Unexpected token v/u);
});
});

Expand Down Expand Up @@ -148,13 +143,8 @@ describe("npmUtils", () => {
});

assert.throws(() => {
try {
stubbedcheckDeps(["some-package"]);
} catch (error) {
assert.strictEqual(error.messageTemplate, "failed-to-read-json");
throw error;
}
}, "SyntaxError: Unexpected token v");
stubbedcheckDeps(["some-package"]);
}, /Unexpected token v/u);
});
});

Expand Down

0 comments on commit 368a1a3

Please sign in to comment.