Skip to content

Commit

Permalink
chore: add a few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Apr 25, 2024
1 parent cc46acf commit b356bc9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/config-generator.js
Expand Up @@ -171,24 +171,24 @@ const compat = new FlatCompat({baseDirectory: __dirname, recommendedConfig: plug
exportContent += " pluginReactConfig,\n";
}
if (this.answers.config) {
const styleguide = this.answers.config;
const config = this.answers.config;

this.result.devDependencies.push(styleguide.packageName);
this.result.devDependencies.push(config.packageName);

// install peer dependencies - it's needed for most eslintrc-style shared configs.
const peers = fetchPeerDependencies(styleguide.packageName);
const peers = fetchPeerDependencies(config.packageName);

if (peers !== null) {
this.result.devDependencies.push(...peers);
}

if (styleguide.type === "flat" || styleguide.type === void 0) {
importContent += `import styleGuide from "${styleguide.packageName}";\n`;
exportContent += " ...[].concat(styleGuide),\n";
} else if (styleguide.type === "eslintrc") {
if (config.type === "flat" || config.type === void 0) {
importContent += `import config from "${config.packageName}";\n`;
exportContent += " ...[].concat(config),\n";
} else if (config.type === "eslintrc") {
needCompatHelper = true;

const shorthandName = getShorthandName(styleguide.packageName, "eslint-config");
const shorthandName = getShorthandName(config.packageName, "eslint-config");

exportContent += ` ...compat.extends("${shorthandName}"),\n`;
}
Expand Down
16 changes: 16 additions & 0 deletions tests/__snapshots__/config@eslint-config-standard-flat
@@ -0,0 +1,16 @@
{
"configContent": "import config from "eslint-config-standard";


export default [
...[].concat(config),
];",
"configFilename": "eslint.config.mjs",
"devDependencies": [
"eslint-config-standard",
"eslint@^8.0.1",
"eslint-plugin-import@^2.25.2",
"eslint-plugin-n@^15.0.0 || ^16.0.0 ",
"eslint-plugin-promise@^6.0.0",
],
}
16 changes: 16 additions & 0 deletions tests/__snapshots__/config@eslint-config-standard-flat2
@@ -0,0 +1,16 @@
{
"configContent": "import config from "eslint-config-standard";


export default [
...[].concat(config),
];",
"configFilename": "eslint.config.mjs",
"devDependencies": [
"eslint-config-standard",
"eslint@^8.0.1",
"eslint-plugin-import@^2.25.2",
"eslint-plugin-n@^15.0.0 || ^16.0.0 ",
"eslint-plugin-promise@^6.0.0",
],
}
10 changes: 10 additions & 0 deletions tests/config-snapshots.spec.js
Expand Up @@ -92,6 +92,16 @@ describe("generate config for cjs projects", () => {
answers: {
config: { packageName: "eslint-config-standard", type: "eslintrc" }
}
}, {
name: "config@eslint-config-standard-flat",
answers: {
config: { packageName: "eslint-config-standard", type: "flat" }
}
}, {
name: "config@eslint-config-standard-flat2",
answers: {
config: "eslint-config-standard"
}
}];

inputs.forEach(item => {
Expand Down

0 comments on commit b356bc9

Please sign in to comment.