Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: generated vue-ts config #64

Merged
merged 3 commits into from Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 24 additions & 14 deletions lib/init/config-initializer.js
Expand Up @@ -156,6 +156,7 @@ function processAnswers(answers) {
env: {},
parserOptions: {},
extends: [],
plugins: [],
overrides: []
};

Expand All @@ -174,24 +175,18 @@ function processAnswers(answers) {
config.env[env] = true;
});

// add in library information
if (answers.framework === "react") {
config.plugins = ["react"];
config.extends.push("plugin:react/recommended");
} else if (answers.framework === "vue") {
config.plugins = ["vue"];
config.extends.push("plugin:vue/vue3-essential");
}

// if answers.source == "guide", the ts supports should be in the shared config.
if (answers.typescript && answers.source !== "guide") {
config.parser = "@typescript-eslint/parser";

if (Array.isArray(config.plugins)) {
config.plugins.push("@typescript-eslint");
// .vue files should be parsed by vue-eslint-parser.
// https://eslint.vuejs.org/user-guide/#how-to-use-a-custom-parser
if (answers.framework === "vue") {
config.parserOptions.parser = "@typescript-eslint/parser";
} else {
config.plugins = ["@typescript-eslint"];
config.parser = "@typescript-eslint/parser";
}

config.plugins.push("@typescript-eslint");
}

// set config.extends based the selected guide
Expand All @@ -209,7 +204,6 @@ function processAnswers(answers) {
}
}


// setup rules based on problems/style enforcement preferences
if (answers.purpose === "problems") {
config.extends.unshift("eslint:recommended");
Expand All @@ -226,12 +220,28 @@ function processAnswers(answers) {
config.extends.push("plugin:@typescript-eslint/recommended");
}

// add in library information
// The configuration of the framework plugins should be placed at the end of extends.
if (answers.framework === "react" && answers.styleguide !== "airbnb") {
config.plugins.push("react");
config.extends.push("plugin:react/recommended");
} else if (answers.framework === "vue") {
config.plugins.push("vue");
config.extends.push("plugin:vue/vue3-essential");
}

// normalize extends
if (config.extends.length === 0) {
delete config.extends;
} else if (config.extends.length === 1) {
config.extends = config.extends[0];
}
if (config.overrides.length === 0) {
delete config.overrides;
}
if (config.plugins.length === 0) {
delete config.plugins;
}

ConfigOps.normalizeToStrings(config);
return config;
Expand Down
5 changes: 3 additions & 2 deletions tests/init/config-initializer.js
Expand Up @@ -207,8 +207,9 @@ describe("configInitializer", () => {
answers.typescript = true;
const config = init.processAnswers(answers);

assert.deepStrictEqual(config.extends, ["eslint:recommended", "plugin:vue/vue3-essential", "plugin:@typescript-eslint/recommended"]);
assert.deepStrictEqual(config.plugins, ["vue", "@typescript-eslint"]);
assert.include(config.parserOptions, { parser: "@typescript-eslint/parser" });
assert.deepStrictEqual(config.extends, ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:vue/vue3-essential"]);
assert.deepStrictEqual(config.plugins, ["@typescript-eslint", "vue"]);
});

it("should extend eslint:recommended", () => {
Expand Down