Skip to content

Commit

Permalink
Add option to add prettier as eslint plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
badsyntax committed Dec 9, 2019
1 parent e990244 commit 2b04f2f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 deletions.
18 changes: 18 additions & 0 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,21 @@ module.exports = class extends Generator {
});
},

askForPrettier: () => {
if (generator.extensionConfig.type !== 'ext-command-ts') {
return Promise.resolve();
}

return generator.prompt({
type: 'confirm',
name: 'prettierInit',
message: 'Include prettier with eslint?',
default: true
}).then(prettierAnswer => {
generator.extensionConfig.prettierInit = prettierAnswer.prettierInit;
});
},

askForThemeName: () => {
if (generator.extensionConfig.type !== 'ext-colortheme') {
return Promise.resolve();
Expand Down Expand Up @@ -670,6 +685,9 @@ module.exports = class extends Generator {
if (this.extensionConfig.gitInit) {
this.fs.copy(this.sourceRoot() + '/gitignore', context.name + '/.gitignore');
}
if (this.extensionConfig.prettierInit) {
this.fs.copy(this.sourceRoot() + '/.prettierrc.json', context.name + '/.prettierrc.json');
}
this.fs.copyTpl(this.sourceRoot() + '/README.md', context.name + '/README.md', context);
this.fs.copyTpl(this.sourceRoot() + '/CHANGELOG.md', context.name + '/CHANGELOG.md', context);
this.fs.copyTpl(this.sourceRoot() + '/vsc-extension-quickstart.md', context.name + '/vsc-extension-quickstart.md', context);
Expand Down
4 changes: 3 additions & 1 deletion generators/app/templates/ext-command-ts/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
},
"parser": "@typescript-eslint/parser",
"extends": [
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended"<% if (prettierInit) { %>,
"prettier/@typescript-eslint",
"plugin:prettier/recommended"<% } %>
],
"parserOptions": {
"ecmaVersion": 2018,
Expand Down
5 changes: 5 additions & 0 deletions generators/app/templates/ext-command-ts/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"tabWidth": 2,
"printWidth": 80
}
7 changes: 5 additions & 2 deletions generators/app/templates/ext-command-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
"@types/vscode": <%- JSON.stringify(vsCodeEngine) %>,
"@typescript-eslint/eslint-plugin": "^2.10.0",
"@typescript-eslint/parser": "^2.10.0",
"eslint": "^6.7.2",
"eslint": "^6.7.2",<% if (prettierInit) { %>
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-prettier": "^3.1.1",<% } %>
"glob": "^7.1.5",
"mocha": "^6.2.2",
"mocha": "^6.2.2",<% if (prettierInit) { %>
"prettier": "^1.19.1",<% } %>
"typescript": "^3.6.4",
"vscode-test": "^1.2.2"
}
Expand Down
1 change: 1 addition & 0 deletions generators/app/templates/ext-command-ts/vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ src/**
vsc-extension-quickstart.md
**/tsconfig.json
**/.eslintrc.json
**/.prettierrc.json
**/*.map
**/*.ts
9 changes: 8 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ describe('test code generator', function () {
displayName: 'Test Com',
description: 'My TestCom',
gitInit: true,
prettierInit: true,
pkgManager: 'npm'
}) // Mock the prompt answers
.toPromise().then(function () {
Expand All @@ -688,8 +689,11 @@ describe('test code generator', function () {
"@typescript-eslint/eslint-plugin": "^2.10.0",
"@typescript-eslint/parser": "^2.10.0",
"eslint": "^6.7.2",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-prettier": "^3.1.1",
"glob": "^7.1.5",
"mocha": "^6.2.2",
"prettier": "^1.19.1",
"typescript": "^3.6.4",
"vscode-test": "^1.2.2"
},
Expand All @@ -714,7 +718,7 @@ describe('test code generator', function () {
try {


assert.file(['package.json', 'README.md', 'CHANGELOG.md', '.vscodeignore', 'src/extension.ts', 'src/test/suite/extension.test.ts', 'src/test/suite/index.ts', 'tsconfig.json']);
assert.file(['package.json', 'README.md', 'CHANGELOG.md', '.vscodeignore', 'src/extension.ts', 'src/test/suite/extension.test.ts', 'src/test/suite/index.ts', 'tsconfig.json', '.eslintrc.json', '.prettierrc.json']);

var packageJSONBody = fs.readFileSync('package.json', 'utf8')
var actualPackageJSON = JSON.parse(packageJSONBody);
Expand All @@ -737,6 +741,7 @@ describe('test code generator', function () {
displayName: 'Test Com',
description: 'My TestCom',
gitInit: false,
prettierInit: false,
pkgManager: 'yarn'
}) // Mock the prompt answers
.toPromise().then(function () {
Expand Down Expand Up @@ -829,6 +834,7 @@ describe('test code generator', function () {
description: 'My TestCom',
checkJavaScript: false,
gitInit: false,
prettierInit: false,
pkgManager: 'npm'
}) // Mock the prompt answers
.toPromise().then(function () {
Expand Down Expand Up @@ -896,6 +902,7 @@ describe('test code generator', function () {
description: 'My TestCom',
checkJavaScript: true,
gitInit: false,
prettierInit: false,
pkgManager: 'yarn'
}) // Mock the prompt answers
.toPromise().then(function () {
Expand Down

0 comments on commit 2b04f2f

Please sign in to comment.