Răsfoiți Sursa

updated eslint rules

Diana Arreola 4 ani în urmă
părinte
comite
1d9b92795f

+ 0 - 124
ext-plugin/plugin.ts

@@ -1,124 +0,0 @@
-"use strict";
-import * as cp from "child_process";
-
-const HOWDOI_PREFIX = 'howdoi';
-
-interface HowdoiResult {
-    question: string;
-    answer: string[];
-    link: string[];   
-}
-main('# howdoi print python');
-function main(arg:string): void {
-  const userCommand:string = arg;
-  const userCommandWithoutComment:string[]|null = modifyCommentedText(userCommand);
-    
-  if (userCommandWithoutComment != null) {
-    const textToBeSearched:string = userCommandWithoutComment[0];
-    const frontCommentChar:string  = userCommandWithoutComment[1];
-    const endCommentChar:string = userCommandWithoutComment[2];
-
-    spawnChild(textToBeSearched, function(howdoiOutput:string) {
-      howdoi(howdoiOutput, userCommand, frontCommentChar, endCommentChar);
-    });
-  }   
-}
-
-async function spawnChild(command:string, callback:any) {
-  const commandWithoutPrefix = removeHowdoiPrefix(command);
-  const process = await cp.spawn("howdoi", [commandWithoutPrefix, '-n 3']);
-  let howdoiCommandOutput = '';
-  process.stdout.on("data", (data:Buffer) => {
-    howdoiCommandOutput += String(data);
-  });
-
-  process.stderr.on("data", (data:Buffer) => {
-    console.log(`stderr: ${data}`);
-  });
-    
-  process.on("error", (error:any) => {
-    console.log(`error: ${error.message}`);
-  });
-    
-  process.on("close", (code:number) => {
-    console.log('onnn', (typeof code));
-    console.log(`child process exited with code ${code}`);
-    return callback(howdoiCommandOutput);
-  });
-}
-
-function removeHowdoiPrefix(command:string): string {
-  if (!command.trim().startsWith(HOWDOI_PREFIX)) {
-    return command;
-  }
-  return command.replace(HOWDOI_PREFIX, '');
-}
-
-function modifyCommentedText(userCommand:string): string[]|null {
-  /* This function finds the comment regex, removes it from the string and returns an array 
-  with the modified string, the beginning comment regex, ending comment regex */
-  const frontCommentRegex =  /^[!@#<>/\$%\^\&*\)\(+=._-]+/;
-  const endCommentRegex = /[!@#<>/\$%\^\&*\)\(+=._-]+$/;
-  let frontCommentChar:string;
-  let endCommentChar:string;	
-  let userCommandWithoutComment:string[];
-  const initialMatchRegex:RegExpMatchArray | null = userCommand.match(frontCommentRegex);
-  const endMatchRegex:RegExpMatchArray | null = userCommand.match(frontCommentRegex);
-        
-  if (initialMatchRegex && endMatchRegex){
-    frontCommentChar = initialMatchRegex.join();
-    endCommentChar = endMatchRegex.join();
-    userCommand = userCommand.replace(frontCommentRegex, '');
-    userCommand = userCommand.replace(endCommentRegex, '');
-    userCommandWithoutComment = [userCommand, frontCommentChar, endCommentChar];
-    return userCommandWithoutComment;
-  }
-  else if(endMatchRegex){
-    endCommentChar = endMatchRegex.join();
-    userCommand = userCommand.replace(endCommentRegex, '');
-    userCommandWithoutComment = [userCommand,'',endCommentChar];
-    return userCommandWithoutComment;
-  }
-  else if(initialMatchRegex){
-    frontCommentChar = initialMatchRegex.join();
-    userCommand= userCommand.replace(frontCommentRegex, '');
-    userCommandWithoutComment = [userCommand, frontCommentChar, ''];
-    return userCommandWithoutComment;
-  }
-  else {
-    return null;
-  }
-}
-
-function organizeHowdoiOutput(howdoiOutput:string, frontCommentChar:string, endCommentChar:string): string[][] {
-  /* Creates an array from the howdoiOutput string in which each element 
-  is one of three answers from the usersCommand */
-  const delim = '\n'+'================================================================================' + '\n' + '\n';
-  const howdoiAnswersArr = howdoiOutput.split(delim);
-  /* Creates a 2D array from howdoiAnswersArr in which each element is an array which denotes
-  one of three answers from the usersCommand, and the elements in that array are link and answer */
-  const newHowdoiAnswersArr:string[][] = howdoiAnswersArr.map((elem) => elem.split(' ★'));
-  //  The comment Regex is added to the link string
-  for (let i = 0; i < newHowdoiAnswersArr.length; i++) {
-    newHowdoiAnswersArr[i][0] = frontCommentChar + newHowdoiAnswersArr[i][0] + endCommentChar;
-  }
-
-  return newHowdoiAnswersArr;
-}
-
-function createHowdoiResult(howdoiResultArr:string[][], userCommand:string): HowdoiResult {
-  const howdoiResultObj:HowdoiResult = {question: userCommand, answer: [], link: []};
-
-  for (let i = 0; i < howdoiResultArr.length; i++) {
-    howdoiResultObj.link.push(howdoiResultArr[i][0]);
-    howdoiResultObj.answer.push(howdoiResultArr[i][1]);
-  }
-
-  return howdoiResultObj;
-}
-
-function howdoi(howdoiOutput:string, userCommand:string, frontCommentChar:string, endCommentChar:string): HowdoiResult {
-  const organizedHowdoiArr:string[][] = organizeHowdoiOutput(howdoiOutput, frontCommentChar, endCommentChar);
-  const howdoiResultObj:HowdoiResult = createHowdoiResult(organizedHowdoiArr, userCommand);
-  return howdoiResultObj;
-}

+ 0 - 0
ext-plugin/.eslintignore → extension/ext-plugin/.eslintignore


+ 9 - 1
ext-plugin/.eslintrc.json → extension/ext-plugin/.eslintrc.json

@@ -24,6 +24,14 @@
         "flatTernaryExpressions": false,
         "ignoreComments": false
       }
-    ]
+    ],
+    "@typescript-eslint/naming-convention": "warn",
+    "@typescript-eslint/semi": ["error", "never"],
+    "comma-spacing": ["error", { "before": false, "after": true }],
+    "curly": "warn",
+    "eqeqeq": "warn",
+    "no-throw-literal": "warn",
+    "quotes": ["error", "single"],
+    "semi": "off"
   }    
 }

+ 0 - 0
ext-plugin/.gitignore → extension/ext-plugin/.gitignore


+ 0 - 0
ext-plugin/package-lock.json → extension/ext-plugin/package-lock.json


+ 0 - 0
ext-plugin/package.json → extension/ext-plugin/package.json


+ 130 - 0
extension/ext-plugin/plugin.ts

@@ -0,0 +1,130 @@
+'use strict'
+import * as cp from 'child_process'
+
+const HOWDOI_PREFIX = 'howdoi'
+
+interface HowdoiResult {
+    question: string
+    answer: string[]
+    link: string[]  
+}
+
+interface CallBack {
+  (howdoiOutput: string): void
+}
+
+function main(arg: string): void {
+  const userCommand: string = arg
+  const userCommandWithoutComment: string[]|null = modifyCommentedText(userCommand)
+    
+  if (userCommandWithoutComment !== null) {
+    const textToBeSearched: string = userCommandWithoutComment[0]
+    const frontCommentChar: string  = userCommandWithoutComment[1]
+    const endCommentChar: string = userCommandWithoutComment[2]
+
+    
+    const callbackFunc: CallBack = function(howdoiOutput: string): void {
+      howdoi(howdoiOutput, userCommand, frontCommentChar, endCommentChar)
+    }
+
+    spawnChild(textToBeSearched, callbackFunc)
+  }   
+}
+
+async function spawnChild(command: string, callbackFunc: CallBack): Promise<void> {
+  const commandWithoutPrefix = removeHowdoiPrefix(command)
+  const process = await cp.spawn('howdoi', [commandWithoutPrefix, '-n 3'])
+  let howdoiCommandOutput = ''
+  process.stdout.on('data', (data: Buffer) => {
+    howdoiCommandOutput += String(data)
+  })
+
+  process.stderr.on('data', (data: Buffer) => {
+    console.log(`stderr: ${data}`)
+  })
+    
+  process.on('error', (error: Error) => {
+    console.log(`error: ${error.message}`)
+  })
+    
+  process.on('close', (code:number) => {
+    console.log(`child process exited with code ${code}`)
+    return callbackFunc(howdoiCommandOutput)
+  })
+}
+
+function removeHowdoiPrefix(command: string): string {
+  if (!command.trim().startsWith(HOWDOI_PREFIX)) {
+    return command
+  }
+  return command.replace(HOWDOI_PREFIX, '')
+}
+
+function modifyCommentedText(userCommand: string): string[]|null {
+  /* This function finds the comment regex, removes it from the string and returns an array 
+  with the modified string, the beginning comment regex, ending comment regex */
+  const frontCommentRegex =  /^[!@#<>/%*(+=._-]+/
+  const endCommentRegex = /[!@#<>/%*+=._-]+$/
+  let frontCommentChar: string
+  let endCommentChar: string
+  let userCommandWithoutComment: string[]
+  const initialMatchRegex: RegExpMatchArray | null = userCommand.match(frontCommentRegex)
+  const endMatchRegex: RegExpMatchArray | null = userCommand.match(frontCommentRegex)
+        
+  if (initialMatchRegex && endMatchRegex){
+    frontCommentChar = initialMatchRegex.join()
+    endCommentChar = endMatchRegex.join()
+    userCommand = userCommand.replace(frontCommentRegex, '')
+    userCommand = userCommand.replace(endCommentRegex, '')
+    userCommandWithoutComment = [userCommand, frontCommentChar, endCommentChar]
+    return userCommandWithoutComment
+  }
+  else if(endMatchRegex){
+    endCommentChar = endMatchRegex.join()
+    userCommand = userCommand.replace(endCommentRegex, '')
+    userCommandWithoutComment = [userCommand, '', endCommentChar]
+    return userCommandWithoutComment
+  }
+  else if(initialMatchRegex){
+    frontCommentChar = initialMatchRegex.join()
+    userCommand= userCommand.replace(frontCommentRegex, '')
+    userCommandWithoutComment = [userCommand, frontCommentChar, '']
+    return userCommandWithoutComment
+  }
+  else {
+    return null
+  }
+}
+
+function organizeHowdoiOutput(howdoiOutput: string, frontCommentChar: string, endCommentChar: string): string[][] {
+  /* Creates an array from the howdoiOutput string in which each element 
+  is one of three answers from the usersCommand */
+  const delim = '\n'+'================================================================================' + '\n' + '\n'
+  const howdoiAnswersArr = howdoiOutput.split(delim)
+  /* Creates a 2D array from howdoiAnswersArr in which each element is an array which denotes
+  one of three answers from the usersCommand, and the elements in that array are link and answer */
+  const newHowdoiAnswersArr: string[][] = howdoiAnswersArr.map((elem) => elem.split(' ★'))
+  //  The comment Regex is added to the link string
+  for (let i = 0; i < newHowdoiAnswersArr.length; i++) {
+    newHowdoiAnswersArr[i][0] = frontCommentChar + newHowdoiAnswersArr[i][0] + endCommentChar
+  }
+
+  return newHowdoiAnswersArr
+}
+
+function createHowdoiResult(howdoiResultArr: string[][], userCommand: string): HowdoiResult {
+  const howdoiResultObj: HowdoiResult = {question: userCommand, answer: [], link: []}
+
+  for (let i = 0; i < howdoiResultArr.length; i++) {
+    howdoiResultObj.link.push(howdoiResultArr[i][0])
+    howdoiResultObj.answer.push(howdoiResultArr[i][1])
+  }
+
+  return howdoiResultObj
+}
+
+function howdoi(howdoiOutput: string, userCommand: string, frontCommentChar: string, endCommentChar: string): HowdoiResult {
+  const organizedHowdoiArr: string[][] = organizeHowdoiOutput(howdoiOutput, frontCommentChar, endCommentChar)
+  const howdoiResultObj: HowdoiResult = createHowdoiResult(organizedHowdoiArr, userCommand)
+  return howdoiResultObj
+}

+ 0 - 0
ext-plugin/tsconfig.json → extension/ext-plugin/tsconfig.json


+ 0 - 11
extension/howdoi/src/test/suite/extension.test.ts

@@ -1,11 +0,0 @@
-import * as assert from 'assert';
-import * as vscode from 'vscode';
-// import * as myExtension from '../../extension';
-
-suite('Extension Test Suite', () => {
-  vscode.window.showInformationMessage('Start all tests.');
-  test('Sample test', () => {
-    assert.equal(-1, [1, 2, 3].indexOf(5));
-    assert.equal(-1, [1, 2, 3].indexOf(0));
-  });
-});

+ 1 - 1
extension/howdoi/.eslintrc → extension/vscode-howdoi/.eslintrc

@@ -25,7 +25,7 @@
       }
     ],
     "@typescript-eslint/class-name-casing": "warn",
-    "@typescript-eslint/semi": "off",
+    "@typescript-eslint/semi": ["error", "never"],
     "comma-spacing": ["error", { "before": false, "after": true }],
     "curly": "warn",
     "eqeqeq": "warn",

+ 0 - 0
extension/howdoi/.gitignore → extension/vscode-howdoi/.gitignore


+ 0 - 0
extension/howdoi/.vscode/extensions.json → extension/vscode-howdoi/.vscode/extensions.json


+ 0 - 0
extension/howdoi/.vscode/launch.json → extension/vscode-howdoi/.vscode/launch.json


+ 0 - 0
extension/howdoi/.vscode/settings.json → extension/vscode-howdoi/.vscode/settings.json


+ 0 - 0
extension/howdoi/.vscode/tasks.json → extension/vscode-howdoi/.vscode/tasks.json


+ 0 - 0
extension/howdoi/.vscodeignore → extension/vscode-howdoi/.vscodeignore


+ 0 - 0
extension/howdoi/CHANGELOG.md → extension/vscode-howdoi/CHANGELOG.md


+ 0 - 0
extension/howdoi/README.md → extension/vscode-howdoi/README.md


+ 0 - 0
extension/howdoi/package-lock.json → extension/vscode-howdoi/package-lock.json


+ 3 - 3
extension/howdoi/package.json → extension/vscode-howdoi/package.json

@@ -30,13 +30,13 @@
     "test": "node ./out/test/runTest.js"
   },
   "devDependencies": {
-    "@types/vscode": "^1.46.0",
     "@types/glob": "^7.1.1",
     "@types/mocha": "^7.0.2",
     "@types/node": "^13.11.0",
-    "eslint": "^6.8.0",
+    "@types/vscode": "^1.46.0",
+    "@typescript-eslint/eslint-plugin": "^2.34.0",
     "@typescript-eslint/parser": "^2.30.0",
-    "@typescript-eslint/eslint-plugin": "^2.30.0",
+    "eslint": "^6.8.0",
     "glob": "^7.1.6",
     "mocha": "^7.1.2",
     "typescript": "^3.8.3",

+ 17 - 11
extension/howdoi/src/extension.ts → extension/vscode-howdoi/src/extension.ts

@@ -9,26 +9,30 @@ interface HowdoiResult {
     link: string[]
 }
 
-async function spawnChild(command: string, callback: any) {
+interface CallBack {
+  (howdoiOutput: string): void
+}
+
+async function spawnChild(command: string, callbackFunc: CallBack): Promise<void> {
   const commandWithoutPrefix = removeHowdoiPrefix(command)
   const process = await cp.spawn('howdoi', [commandWithoutPrefix, '-n 3'])
   let howdoiCommandOutput: string = ''
 
-  process.stdout.on('data', (data: any) => {
+  process.stdout.on('data', (data: Buffer) => {
     howdoiCommandOutput += String(data)
   })
 
-  process.stderr.on('data', (data: any) => {
+  process.stderr.on('data', (data: Buffer) => {
     console.log(`stderr: ${data}`)
   })
 
-  process.on('error', (error: any) => {
+  process.on('error', (error: Error) => {
     console.log(`error: ${error.message}`)
   })
 
-  process.on('close', (code: any) => {
+  process.on('close', (code: number) => {
     console.log(`child process exited with code ${code}`)
-    return callback(howdoiCommandOutput)
+    return callbackFunc(howdoiCommandOutput)
   })
 }
 
@@ -42,8 +46,8 @@ function removeHowdoiPrefix(command: string): string {
 function modifyCommentedText(userCommand: string): string[]|null {
   /* This function finds the comment regex, removes it from the string and returns an array
   with the modified string, the beginning comment regex, ending comment regex */
-  const frontCommentRegex = /^[!@#<>/\$%\^\&*\)\(+=._-]+/
-  const endCommentRegex = /[!@#<>/\$%\^\&*\)\(+=._-]+$/
+  const frontCommentRegex = /^[!@#<>/%*(+=._-]+/
+  const endCommentRegex = /[!@#<>/%*+=._-]+$/
   let frontCommentChar: string
   let endCommentChar: string
   let userCommandWithoutComment: string[]
@@ -78,7 +82,7 @@ function modifyCommentedText(userCommand: string): string[]|null {
 function organizeHowdoiOutput(howdoiOutput: string, frontCommentChar: string, endCommentChar: string): string[][] {
   /* Creates an array from the howdoiOutput string in which each element
   is one of three answers from the usersCommand */
-  const delim: string = '\n'+'================================================================================'+'\n'+'\n'
+  const delim = '\n'+'================================================================================'+'\n'+'\n'
   const howdoiAnswersArr: string[] = howdoiOutput.split(delim)
   /* Creates a 2D array from howdoiAnswersArr in which each element is an array which denotes
   one of three answers from the usersCommand, and the elements in that array are the link and answer */
@@ -143,10 +147,12 @@ export function activate(context: vscode.ExtensionContext) {
       const frontCommentChar: string  = userCommandWithoutComment[1]
       const endCommentChar: string = userCommandWithoutComment[2]
 
-      spawnChild(textToBeSearched, function(howdoiOutput: string) {
+      const callbackFunc: CallBack = function(howdoiOutput: string): void {
         let howdoiResultObj = howdoi(howdoiOutput, userCommand, frontCommentChar, endCommentChar)
         quickPicker(editor, howdoiResultObj, userCommand)
-      })
+      }
+
+      spawnChild(textToBeSearched, callbackFunc)
     }
     else {
       vscode.window.showErrorMessage('please use single line comment for howdoi.')

+ 8 - 8
extension/howdoi/src/test/runTest.ts → extension/vscode-howdoi/src/test/runTest.ts

@@ -1,23 +1,23 @@
-import * as path from 'path';
+import * as path from 'path'
 
-import { runTests } from 'vscode-test';
+import { runTests } from 'vscode-test'
 
 async function main() {
   try {
     // The folder containing the Extension Manifest package.json
     // Passed to `--extensionDevelopmentPath`
-    const extensionDevelopmentPath = path.resolve(__dirname, '../../');
+    const extensionDevelopmentPath = path.resolve(__dirname, '../../')
 
     // The path to test runner
     // Passed to --extensionTestsPath
-    const extensionTestsPath = path.resolve(__dirname, './suite/index');
+    const extensionTestsPath = path.resolve(__dirname, './suite/index')
 
     // Download VS Code, unzip it and run the integration test
-    await runTests({ extensionDevelopmentPath, extensionTestsPath });
+    await runTests({ extensionDevelopmentPath, extensionTestsPath })
   } catch (err) {
-    console.error('Failed to run tests');
-    process.exit(1);
+    console.error('Failed to run tests')
+    process.exit(1)
   }
 }
 
-main();
+main()

+ 11 - 0
extension/vscode-howdoi/src/test/suite/extension.test.ts

@@ -0,0 +1,11 @@
+import * as assert from 'assert'
+import * as vscode from 'vscode'
+// import * as myExtension from '../../extension';
+
+suite('Extension Test Suite', () => {
+  vscode.window.showInformationMessage('Start all tests.')
+  test('Sample test', () => {
+    assert.equal(-1, [1, 2, 3].indexOf(5))
+    assert.equal(-1, [1, 2, 3].indexOf(0))
+  })
+})

+ 14 - 14
extension/howdoi/src/test/suite/index.ts → extension/vscode-howdoi/src/test/suite/index.ts

@@ -1,38 +1,38 @@
-import * as path from 'path';
-import * as Mocha from 'mocha';
-import * as glob from 'glob';
+import * as path from 'path'
+import * as Mocha from 'mocha'
+import * as glob from 'glob'
 
 export function run(): Promise<void> {
   // Create the mocha test
   const mocha = new Mocha({
     ui: 'tdd',
     color: true
-  });
+  })
 
-  const testsRoot = path.resolve(__dirname, '..');
+  const testsRoot = path.resolve(__dirname, '..')
 
   return new Promise((c, e) => {
     glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
       if (err) {
-        return e(err);
+        return e(err)
       }
 
       // Add files to the test suite
-      files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
+      files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)))
 
       try {
         // Run the mocha test
         mocha.run(failures => {
           if (failures > 0) {
-            e(new Error(`${failures} tests failed.`));
+            e(new Error(`${failures} tests failed.`))
           } else {
-            c();
+            c()
           }
-        });
+        })
       } catch (err) {
-        console.error(err);
-        e(err);
+        console.error(err)
+        e(err)
       }
-    });
-  });
+    })
+  })
 }

+ 0 - 0
extension/howdoi/tsconfig.json → extension/vscode-howdoi/tsconfig.json