From 1825b71e527ff7ca1b44eafbc0391c7a1af75bfd Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Sun, 8 Dec 2019 11:30:05 +0100 Subject: [PATCH 1/3] Replace tslint with eslint --- generators/app/index.js | 3 +-- .../app/templates/ext-command-ts/.eslintrc.json | 16 ++++++++++++++++ .../app/templates/ext-command-ts/package.json | 4 +++- .../app/templates/ext-command-ts/tslint.json | 15 --------------- .../ext-command-ts/vscode/extensions.json | 4 ++-- .../ext-command-ts/vscode/settings.json | 11 +++++++++-- .../app/templates/ext-command-ts/vscodeignore | 4 ++-- test/test.js | 11 +++++++---- 8 files changed, 40 insertions(+), 28 deletions(-) create mode 100644 generators/app/templates/ext-command-ts/.eslintrc.json delete mode 100644 generators/app/templates/ext-command-ts/tslint.json diff --git a/generators/app/index.js b/generators/app/index.js index c17447b7..42f65dff 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -677,8 +677,7 @@ module.exports = class extends Generator { this.fs.copyTpl(this.sourceRoot() + '/src/extension.ts', context.name + '/src/extension.ts', context); this.fs.copyTpl(this.sourceRoot() + '/package.json', context.name + '/package.json', context); - - this.fs.copy(this.sourceRoot() + '/tslint.json', context.name + '/tslint.json'); + this.fs.copyTpl(this.sourceRoot() + '/.eslintrc.json', context.name + '/.eslintrc.json', context); this.extensionConfig.installDependencies = true; } diff --git a/generators/app/templates/ext-command-ts/.eslintrc.json b/generators/app/templates/ext-command-ts/.eslintrc.json new file mode 100644 index 00000000..4495b0f7 --- /dev/null +++ b/generators/app/templates/ext-command-ts/.eslintrc.json @@ -0,0 +1,16 @@ +{ + "env": { + "browser": false, + "commonjs": true, + "es6": true, + "node": true + }, + "parser": "@typescript-eslint/parser", + "extends": [ + "plugin:@typescript-eslint/recommended" + ], + "parserOptions": { + "ecmaVersion": 2018, + "sourceType": "module" + } +} diff --git a/generators/app/templates/ext-command-ts/package.json b/generators/app/templates/ext-command-ts/package.json index 16d870fd..daad2c72 100644 --- a/generators/app/templates/ext-command-ts/package.json +++ b/generators/app/templates/ext-command-ts/package.json @@ -31,10 +31,12 @@ "@types/mocha": "^5.2.7", "@types/node": "^12.11.7", "@types/vscode": <%- JSON.stringify(vsCodeEngine) %>, + "@typescript-eslint/eslint-plugin": "^2.10.0", + "@typescript-eslint/parser": "^2.10.0", + "eslint": "^6.7.2", "glob": "^7.1.5", "mocha": "^6.2.2", "typescript": "^3.6.4", - "tslint": "^5.20.0", "vscode-test": "^1.2.2" } } diff --git a/generators/app/templates/ext-command-ts/tslint.json b/generators/app/templates/ext-command-ts/tslint.json deleted file mode 100644 index c81ff28f..00000000 --- a/generators/app/templates/ext-command-ts/tslint.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "rules": { - "no-string-throw": true, - "no-unused-expression": true, - "no-duplicate-variable": true, - "curly": true, - "class-name": true, - "semicolon": [ - true, - "always" - ], - "triple-equals": true - }, - "defaultSeverity": "warning" -} diff --git a/generators/app/templates/ext-command-ts/vscode/extensions.json b/generators/app/templates/ext-command-ts/vscode/extensions.json index 0a18b9c4..3ac9aeb6 100644 --- a/generators/app/templates/ext-command-ts/vscode/extensions.json +++ b/generators/app/templates/ext-command-ts/vscode/extensions.json @@ -2,6 +2,6 @@ // See http://go.microsoft.com/fwlink/?LinkId=827846 // for the documentation about the extensions.json format "recommendations": [ - "ms-vscode.vscode-typescript-tslint-plugin" + "dbaeumer.vscode-eslint" ] -} \ No newline at end of file +} diff --git a/generators/app/templates/ext-command-ts/vscode/settings.json b/generators/app/templates/ext-command-ts/vscode/settings.json index 30bf8c2d..bb576274 100644 --- a/generators/app/templates/ext-command-ts/vscode/settings.json +++ b/generators/app/templates/ext-command-ts/vscode/settings.json @@ -7,5 +7,12 @@ "out": true // set this to false to include "out" folder in search results }, // Turn off tsc task auto detection since we have the necessary tasks as npm scripts - "typescript.tsc.autoDetect": "off" -} \ No newline at end of file + "typescript.tsc.autoDetect": "off", + // Enable eslint validation on typescript files + "eslint.validate": [ + { + "language": "typescript", + "autoFix": true + } + ] +} diff --git a/generators/app/templates/ext-command-ts/vscodeignore b/generators/app/templates/ext-command-ts/vscodeignore index ed3f9d37..c06f4a7b 100644 --- a/generators/app/templates/ext-command-ts/vscodeignore +++ b/generators/app/templates/ext-command-ts/vscodeignore @@ -5,6 +5,6 @@ src/** .gitignore vsc-extension-quickstart.md **/tsconfig.json -**/tslint.json +**/.eslintrc.json **/*.map -**/*.ts \ No newline at end of file +**/*.ts diff --git a/test/test.js b/test/test.js index 45f79b79..a0ad4d2f 100644 --- a/test/test.js +++ b/test/test.js @@ -685,10 +685,12 @@ describe('test code generator', function () { "@types/mocha": "^5.2.7", "@types/node": "^12.11.7", "@types/vscode": engineVersion, + "@typescript-eslint/eslint-plugin": "^2.10.0", + "@typescript-eslint/parser": "^2.10.0", + "eslint": "^6.7.2", "glob": "^7.1.5", "mocha": "^6.2.2", "typescript": "^3.6.4", - "tslint": "^5.20.0", "vscode-test": "^1.2.2" }, "main": "./out/extension.js", @@ -734,7 +736,6 @@ describe('test code generator', function () { name: 'testCom', displayName: 'Test Com', description: 'My TestCom', - tslint: true, gitInit: false, pkgManager: 'yarn' }) // Mock the prompt answers @@ -755,10 +756,12 @@ describe('test code generator', function () { "@types/mocha": "^5.2.7", "@types/node": "^12.11.7", "@types/vscode": engineVersion, + "@typescript-eslint/eslint-plugin": "^2.10.0", + "@typescript-eslint/parser": "^2.10.0", + "eslint": "^6.7.2", "glob": "^7.1.5", "mocha": "^6.2.2", "typescript": "^3.6.4", - "tslint": "^5.20.0", "vscode-test": "^1.2.2" }, "main": "./out/extension.js", @@ -797,7 +800,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', 'tslint.json', '.vscode/extensions.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', '.vscode/extensions.json']); var packageJSONBody = fs.readFileSync('package.json', 'utf8') var actualPackageJSON = JSON.parse(packageJSONBody); From e9902445b29988a4b0678e33ab5a3ad760cb3e0a Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Sun, 8 Dec 2019 11:33:22 +0100 Subject: [PATCH 2/3] Fix eslint errors --- generators/app/templates/ext-command-ts/src/extension.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generators/app/templates/ext-command-ts/src/extension.ts b/generators/app/templates/ext-command-ts/src/extension.ts index d4a0765d..b7e57234 100644 --- a/generators/app/templates/ext-command-ts/src/extension.ts +++ b/generators/app/templates/ext-command-ts/src/extension.ts @@ -13,7 +13,7 @@ export function activate(context: vscode.ExtensionContext) { // The command has been defined in the package.json file // Now provide the implementation of the command with registerCommand // The commandId parameter must match the command field in package.json - let disposable = vscode.commands.registerCommand('extension.helloWorld', () => { + const disposable = vscode.commands.registerCommand('extension.helloWorld', () => { // The code you place here will be executed every time your command is executed // Display a message box to the user @@ -24,4 +24,5 @@ export function activate(context: vscode.ExtensionContext) { } // this method is called when your extension is deactivated +// eslint-disable-next-line @typescript-eslint/no-empty-function export function deactivate() {} From 13d0f0151c8de4134cf0ffe6ef77e9962b6c8f78 Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Mon, 9 Dec 2019 18:51:33 +0100 Subject: [PATCH 3/3] Add option to add prettier as eslint plugin --- generators/app/index.js | 18 ++++++++++++++++++ .../templates/ext-command-ts/.eslintrc.json | 4 +++- .../templates/ext-command-ts/.prettierrc.json | 6 ++++++ .../app/templates/ext-command-ts/package.json | 7 +++++-- .../app/templates/ext-command-ts/vscodeignore | 1 + test/test.js | 9 ++++++++- 6 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 generators/app/templates/ext-command-ts/.prettierrc.json diff --git a/generators/app/index.js b/generators/app/index.js index 42f65dff..b3b33344 100644 --- a/generators/app/index.js +++ b/generators/app/index.js @@ -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(); @@ -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); diff --git a/generators/app/templates/ext-command-ts/.eslintrc.json b/generators/app/templates/ext-command-ts/.eslintrc.json index 4495b0f7..e4903b6d 100644 --- a/generators/app/templates/ext-command-ts/.eslintrc.json +++ b/generators/app/templates/ext-command-ts/.eslintrc.json @@ -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, diff --git a/generators/app/templates/ext-command-ts/.prettierrc.json b/generators/app/templates/ext-command-ts/.prettierrc.json new file mode 100644 index 00000000..2bc722b2 --- /dev/null +++ b/generators/app/templates/ext-command-ts/.prettierrc.json @@ -0,0 +1,6 @@ +{ + "singleQuote": true, + "tabWidth": 2, + "printWidth": 80, + "useTabs": true +} diff --git a/generators/app/templates/ext-command-ts/package.json b/generators/app/templates/ext-command-ts/package.json index daad2c72..2d27670e 100644 --- a/generators/app/templates/ext-command-ts/package.json +++ b/generators/app/templates/ext-command-ts/package.json @@ -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" } diff --git a/generators/app/templates/ext-command-ts/vscodeignore b/generators/app/templates/ext-command-ts/vscodeignore index c06f4a7b..90be308e 100644 --- a/generators/app/templates/ext-command-ts/vscodeignore +++ b/generators/app/templates/ext-command-ts/vscodeignore @@ -6,5 +6,6 @@ src/** vsc-extension-quickstart.md **/tsconfig.json **/.eslintrc.json +**/.prettierrc.json **/*.map **/*.ts diff --git a/test/test.js b/test/test.js index a0ad4d2f..9224f504 100644 --- a/test/test.js +++ b/test/test.js @@ -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 () { @@ -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" }, @@ -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); @@ -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 () { @@ -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 () { @@ -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 () {