Skip to content

Commit

Permalink
fix: add xo-typescript tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Jul 25, 2022
1 parent e261c3f commit b65f0ba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
31 changes: 19 additions & 12 deletions lib/init/config-initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,30 @@ function getModulesList(config, installESLint) {
modules[moduleName] = "latest";
}
}
if (config.extends) {
const extendList = Array.isArray(config.extends) ? config.extends : [config.extends];

for (const extend of extendList) {
if (extend.startsWith("eslint:") || extend.startsWith("plugin:")) {
continue;
}
const moduleName = naming.normalizePackageName(extend, "eslint-config");
const extendList = typeof config.extends === "string" ? [config.extends] : [...config.extends];

modules[moduleName] = "latest";
Object.assign(
modules,
getPeerDependencies(`${moduleName}@latest`)
);
for (const item of config.overrides) {
if (typeof item.extends === "string") {
extendList.push(item.extends);
} else {
extendList.push(...item.extends);
}
}

for (const extend of extendList) {
if (extend.startsWith("eslint:") || extend.startsWith("plugin:")) {
continue;
}
const moduleName = naming.normalizePackageName(extend, "eslint-config");

modules[moduleName] = "latest";
Object.assign(
modules,
getPeerDependencies(`${moduleName}@latest`)
);
}

const parser = config.parser || (config.parserOptions && config.parserOptions.parser);

if (parser) {
Expand Down
11 changes: 11 additions & 0 deletions tests/init/config-initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,17 @@ describe("configInitializer", () => {
assert.include(modules, "eslint-config-xo@latest");
});

it("should support the xo-typescript style guide", () => {
const config = { extends: "xo", overrides: [{ files: ["*.ts"], extends: ["xo-typescript"] }] };
const modules = init.getModulesList(config);

assert.deepStrictEqual(config.extends, "xo");
assert.deepStrictEqual(config.overrides[0].extends[0], "xo-typescript");
assert.strictEqual(config.installedESLint, true);
assert.include(modules, "eslint-config-xo@latest");
assert.include(modules, "eslint-config-xo-typescript@latest");
});

it("should install required sharable config", () => {
const config = { extends: "google" };

Expand Down

0 comments on commit b65f0ba

Please sign in to comment.