Skip to content

Commit

Permalink
fix: ts supports
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Jul 5, 2022
1 parent c21f4c2 commit 4b2e121
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
12 changes: 3 additions & 9 deletions lib/init/config-initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,16 @@ function processAnswers(answers) {

// add in library information
if (answers.framework === "react") {
config.parserOptions.ecmaFeatures = {
jsx: true
};
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.typescript) {
if (answers.framework === "vue") {
config.parserOptions.parser = "@typescript-eslint/parser";
} else {
config.parser = "@typescript-eslint/parser";
}
// if answers.source == "guide", the ts supports should be in the shared config.
if (answers.typescript && answers.source === "prompt") {
config.parser = "@typescript-eslint/parser";

if (Array.isArray(config.plugins)) {
config.plugins.push("@typescript-eslint");
Expand Down
3 changes: 1 addition & 2 deletions tests/init/config-initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ describe("configInitializer", () => {
answers.framework = "react";
const config = init.processAnswers(answers);

assert.strictEqual(config.parserOptions.ecmaFeatures.jsx, true);
assert.strictEqual(config.parserOptions.ecmaVersion, "latest");
assert.deepStrictEqual(config.plugins, ["react"]);
assert.include(config.extends, "plugin:react/recommended");
});

it("should enable vue plugin", () => {
Expand All @@ -208,7 +208,6 @@ describe("configInitializer", () => {
const config = init.processAnswers(answers);

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

Expand Down

0 comments on commit 4b2e121

Please sign in to comment.