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 9583e59
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
32 changes: 20 additions & 12 deletions lib/init/config-initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,29 @@ 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 = [];
const overrides = config.overrides || [];

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 if (Array.isArray(item.extends)) {
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);
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 9583e59

Please sign in to comment.