Skip to content

Commit

Permalink
Switch from TSLint to ESLint for TypeScript samples (#3969)
Browse files Browse the repository at this point in the history
* Switch from TSLint to ESLint for TypeScript samples

* Update ci-javascript-samples.yml

Updating eslint for both file types i.e. .js and .ts

* eslint-plugin-import

* eslint-plugin-n

* Resolving dependencies

* jsonwebtoken
  • Loading branch information
gandiddi authored May 13, 2024
1 parent df21f1a commit 62a768d
Show file tree
Hide file tree
Showing 46 changed files with 340 additions and 324 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ci-javascript-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,5 @@ jobs:

- name: yarn lint
run: |
if ${{ endsWith(matrix.files[0], '.js') }}; then
yarn eslint ${{ join(matrix.files, ' ') }}
else
yarn tslint ${{ join(matrix.files, ' ') }}
fi
yarn eslint ${{ join(matrix.files, ' ') }}
working-directory: ${{ matrix.folder }}
15 changes: 15 additions & 0 deletions samples/typescript_nodejs/00.empty-bot/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
"extends": "standard",
"parser": "@typescript-eslint/parser",
"rules": {
"semi": [2, "always"],
"indent": [2, 4],
"no-return-await": 0,
"space-before-function-paren": [2, {
"named": "never",
"anonymous": "never",
"asyncArrow": "always"
}],
"template-curly-spacing": [2, "always"]
}
};
15 changes: 11 additions & 4 deletions samples/typescript_nodejs/00.empty-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"main": "./lib/index.js",
"scripts": {
"build": "tsc --build",
"lint": "tslint -c tslint.json 'src/**/*.ts'",
"lint": "eslint -c .eslintrc.js --ext .ts src",
"postinstall": "npm run build && node ./deploymentScripts/webConfigPrep.js",
"start": "tsc --build && node ./lib/index.js",
"test": "echo \"Error: no test specified\" && exit 1",
Expand All @@ -24,8 +24,15 @@
},
"devDependencies": {
"@types/restify": "8.4.2",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"eslint": "^8.57.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"nodemon": "~2.0.4",
"tslint": "~6.1.2",
"typescript": "~4.3.2"
"typescript": "~4.9.3"
}
}
}
3 changes: 1 addition & 2 deletions samples/typescript_nodejs/00.empty-bot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as restify from 'restify';
// See https://aka.ms/bot-services to learn more about the different parts of a bot.
import {
CloudAdapter,
ConfigurationServiceClientCredentialFactory,
ConfigurationBotFrameworkAuthentication,
ConfigurationBotFrameworkAuthenticationOptions
} from 'botbuilder';
Expand Down Expand Up @@ -54,5 +53,5 @@ const myBot = new EmptyBot();
// Listen for incoming requests.
server.post('/api/messages', async (req, res) => {
// Route received a request to adapter for processing
await adapter.process(req, res, (context) => myBot.run(context))
await adapter.process(req, res, (context) => myBot.run(context));
});
18 changes: 0 additions & 18 deletions samples/typescript_nodejs/00.empty-bot/tslint.json

This file was deleted.

15 changes: 15 additions & 0 deletions samples/typescript_nodejs/01.console-echo/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
"extends": "standard",
"parser": "@typescript-eslint/parser",
"rules": {
"semi": [2, "always"],
"indent": [2, 4],
"no-return-await": 0,
"space-before-function-paren": [2, {
"named": "never",
"anonymous": "never",
"asyncArrow": "always"
}],
"template-curly-spacing": [2, "always"]
}
};
14 changes: 11 additions & 3 deletions samples/typescript_nodejs/01.console-echo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"main": "index.js",
"scripts": {
"build": "tsc --build",
"lint": "tslint -c tslint.json 'src/**/*.ts'",
"lint": "eslint -c .eslintrc.js --ext .ts src",
"start": "tsc --build && node ./lib/index.js",
"test": "echo \"Error: no test specified\" && exit 1",
"watch": "nodemon --watch ./src -e ts --exec \"npm run start\""
Expand All @@ -17,8 +17,16 @@
"readline": "^1.3.0"
},
"devDependencies": {
"@types/jsonwebtoken": "^9.0.6",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"eslint": "^8.57.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"nodemon": "~1.19.4",
"tslint": "^5.20.0",
"typescript": "~4.3.2"
"typescript": "~4.9.3"
}
}
3 changes: 1 addition & 2 deletions samples/typescript_nodejs/01.console-echo/src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ActivityTypes, TurnContext } from 'botbuilder';
* Simple bot that echoes received messages.
*/
export class ConsoleEchoBot {

/**
* Driver code for the bot. This bot only responds to "Message"-type
* Activities. If the user's message is "quit", the process will exit.
Expand All @@ -26,5 +25,5 @@ export class ConsoleEchoBot {
await turnContext.sendActivity(`You sent '${ turnContext.activity.text }'`);
}
}
}
};
}
49 changes: 25 additions & 24 deletions samples/typescript_nodejs/01.console-echo/src/consoleAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ConsoleAdapter extends BotAdapter {
this.reference = {
bot: { id: 'bot', name: 'Bot' },
channelId: 'console',
conversation: { id: 'convo1', name: '', isGroup: false },
conversation: { id: 'convo1', name: '', isGroup: false },
serviceUrl: '',
user: { id: 'user', name: 'User1' },
...reference
Expand Down Expand Up @@ -123,12 +123,12 @@ export class ConsoleAdapter extends BotAdapter {
* @param logic A function handler that will be called to perform the bots logic after the the adapters middleware has been run.
*/
public continueConversation(reference: ConversationReference, logic: (context: TurnContext) => Promise<void>): Promise<void> {
// Create context and run middleware pipe
const activity: Partial<Activity> = TurnContext.applyConversationReference({}, reference, true);
const context: TurnContext = new TurnContext(this, activity);
// Create context and run middleware pipe
const activity: Partial<Activity> = TurnContext.applyConversationReference({}, reference, true);
const context: TurnContext = new TurnContext(this, activity);

return this.runMiddleware(context, logic)
.catch((err: Error) => { this.printError(err.toString()); });
return this.runMiddleware(context, logic)
.catch((err: Error) => { this.printError(err.toString()); });
}

/**
Expand All @@ -143,25 +143,26 @@ export class ConsoleAdapter extends BotAdapter {
*/
public async sendActivities(context: TurnContext, activities: Array <Partial<Activity>>): Promise<ResourceResponse[]> {
const responses: ResourceResponse[] = [];
for(const activity of activities) {
for (const activity of activities) {
responses.push({} as ResourceResponse);

switch (activity.type) {
case 'delay' as ActivityTypes:
await this.sleep(activity.value);
break;
case ActivityTypes.Message:
if (activity.attachments && activity.attachments.length > 0) {
const append: string = activity.attachments.length === 1
? `(1 attachment)` : `(${activity.attachments.length} attachments)`;
this.print(`${activity.text} ${append}`);
} else {
this.print(activity.text || '');
}
break;
default:
this.print(`[${activity.type}]`);
break;
case 'delay' as ActivityTypes:
await this.sleep(activity.value);
break;
case ActivityTypes.Message:
if (activity.attachments && activity.attachments.length > 0) {
const append: string = activity.attachments.length === 1
? '(1 attachment)'
: `(${ activity.attachments.length } attachments)`;
this.print(`${ activity.text } ${ append }`);
} else {
this.print(activity.text || '');
}
break;
default:
this.print(`[${ activity.type }]`);
break;
}
}
return responses;
Expand All @@ -172,15 +173,15 @@ export class ConsoleAdapter extends BotAdapter {
* will result an error being returned.
*/
public updateActivity(context: TurnContext, activity: Partial<Activity>): Promise<void> {
return Promise.reject(new Error(`ConsoleAdapter.updateActivity(): not supported.`));
return Promise.reject(new Error('ConsoleAdapter.updateActivity(): not supported.'));
}

/**
* Not supported for the ConsoleAdapter. Calling this method or `TurnContext.deleteActivity()`
* will result an error being returned.
*/
public deleteActivity(context: TurnContext, reference: Partial<ConversationReference>): Promise<void> {
return Promise.reject(new Error(`ConsoleAdapter.deleteActivity(): not supported.`));
return Promise.reject(new Error('ConsoleAdapter.deleteActivity(): not supported.'));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions samples/typescript_nodejs/01.console-echo/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import { ConsoleAdapter} from './consoleAdapter';
import { ConsoleAdapter } from './consoleAdapter';

import { ConsoleEchoBot } from './bot';

Expand All @@ -17,7 +17,7 @@ const echoBot: ConsoleEchoBot = new ConsoleEchoBot();
// `adapter.listen` tells the adapter to listen for incoming messages
// and events, known as "Activities."
// Activities are wrapped in TurnContext objects by the handler function.
const closeFn = adapter.listen(async (turnContext: TurnContext) => {
adapter.listen(async (turnContext: TurnContext) => {
await echoBot.onTurn(turnContext);
});

Expand Down
18 changes: 0 additions & 18 deletions samples/typescript_nodejs/01.console-echo/tslint.json

This file was deleted.

15 changes: 15 additions & 0 deletions samples/typescript_nodejs/02.echo-bot/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
"extends": "standard",
"parser": "@typescript-eslint/parser",
"rules": {
"semi": [2, "always"],
"indent": [2, 4],
"no-return-await": 0,
"space-before-function-paren": [2, {
"named": "never",
"anonymous": "never",
"asyncArrow": "always"
}],
"template-curly-spacing": [2, "always"]
}
};
13 changes: 10 additions & 3 deletions samples/typescript_nodejs/02.echo-bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"main": "./lib/index.js",
"scripts": {
"build": "tsc --build",
"lint": "tslint -c tslint.json 'src/**/*.ts'",
"lint": "eslint -c .eslintrc.js --ext .ts src",
"postinstall": "npm run build && node ./deploymentScripts/webConfigPrep.js",
"start": "tsc --build && node ./lib/index.js",
"test": "echo \"Error: no test specified\" && exit 1",
Expand All @@ -27,8 +27,15 @@
"@types/dotenv": "6.1.1",
"@types/node": "^16.11.6",
"@types/restify": "8.4.2",
"@typescript-eslint/eslint-plugin": "^7.8.0",
"@typescript-eslint/parser": "^7.8.0",
"eslint": "^8.57.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"nodemon": "~2.0.4",
"tslint": "~6.1.2",
"typescript": "~4.3.2"
"typescript": "~4.9.3"
}
}
11 changes: 5 additions & 6 deletions samples/typescript_nodejs/02.echo-bot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

import * as path from 'path';

import { config } from 'dotenv';
const ENV_FILE = path.join(__dirname, '..', '.env');
config({ path: ENV_FILE });

import * as restify from 'restify';

import { INodeSocket } from 'botframework-streaming';
Expand All @@ -15,19 +11,22 @@ import { INodeSocket } from 'botframework-streaming';
// See https://aka.ms/bot-services to learn more about the different parts of a bot.
import {
CloudAdapter,
ConfigurationServiceClientCredentialFactory,
ConfigurationBotFrameworkAuthentication,
ConfigurationBotFrameworkAuthenticationOptions
} from 'botbuilder';

// This bot's main dialog.
import { EchoBot } from './bot';

import { config } from 'dotenv';
const ENV_FILE = path.join(__dirname, '..', '.env');
config({ path: ENV_FILE });

// Create HTTP server.
const server = restify.createServer();
server.use(restify.plugins.bodyParser());
server.listen(process.env.port || process.env.PORT || 3978, () => {
console.log(`\n${server.name} listening to ${server.url}`);
console.log(`\n${ server.name } listening to ${ server.url }`);
console.log('\nGet Bot Framework Emulator: https://aka.ms/botframework-emulator');
console.log('\nTo talk to your bot, open the emulator select "Open Bot"');
});
Expand Down
18 changes: 0 additions & 18 deletions samples/typescript_nodejs/02.echo-bot/tslint.json

This file was deleted.

15 changes: 15 additions & 0 deletions samples/typescript_nodejs/03.welcome-users/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
"extends": "standard",
"parser": "@typescript-eslint/parser",
"rules": {
"semi": [2, "always"],
"indent": [2, 4],
"no-return-await": 0,
"space-before-function-paren": [2, {
"named": "never",
"anonymous": "never",
"asyncArrow": "always"
}],
"template-curly-spacing": [2, "always"]
}
};
Loading

0 comments on commit 62a768d

Please sign in to comment.