Skip to content

Commit e5d2d83

Browse files
refactor: migrate to ESLint and Prettier for code quality
- Updated package.json to include ESLint, Prettier, and related dependencies. - Added scripts for linting and formatting. - Refactored import statements to use single quotes for consistency. - Adjusted formatting and indentation across multiple repository and service files. - Ensured all repository and service interfaces and methods maintain consistent formatting.
1 parent 562622f commit e5d2d83

33 files changed

+3754
-1120
lines changed

.eslintignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
.github
4+
i18n
5+
.*

.eslintrc.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
root: true,
3+
parser: '@typescript-eslint/parser',
4+
plugins: [
5+
'@typescript-eslint',
6+
"unused-imports"
7+
],
8+
extends: [
9+
'eslint:recommended',
10+
'plugin:@typescript-eslint/recommended',
11+
],
12+
rules: {
13+
"no-case-declarations": "off",
14+
"@typescript-eslint/no-unused-vars": "off",
15+
"unused-imports/no-unused-imports": "error",
16+
"unused-imports/no-unused-vars": [
17+
"warn",
18+
{
19+
"vars": "all",
20+
"varsIgnorePattern": "^_",
21+
"args": "after-used",
22+
"argsIgnorePattern": "^_"
23+
}
24+
]
25+
},
26+
};

.github/workflows/main.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Build and Publish
2+
# Triggers the workflow on push or pull request events
3+
on: [push, pull_request]
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
10+
- name: Setup Node.js environment
11+
uses: actions/setup-node@v2.1.2
12+
with:
13+
node-version: '22.11.0'
14+
15+
- name: Install dependencies
16+
run: npm i
17+
18+
- name: Install Rocket.Chat Apps cli
19+
run: npm i -g @rocket.chat/apps-cli
20+
21+
- name: ESLint check
22+
run: npm run lint
23+
24+
- name: Prettier check
25+
run: npm run prettier-check
26+
27+
- name: Typescript check
28+
run: npm run typecheck
29+
30+
- name: Bundle App
31+
run: rc-apps package

.github/workflows/package.yaml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# This workflow will be responsible to pack the app (compiled and not compiled version) to be added as asset on the release
2+
name: Package App
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types: [published]
7+
8+
permissions:
9+
contents: write
10+
# This is the main job that will be running in a virtual machine (ubuntu)
11+
jobs:
12+
package:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
# L21-L25 This is the checkout step wich is responsible authenticate the workflow
17+
- name: Checkout
18+
uses: actions/checkout@v2
19+
with:
20+
persist-credentials: false
21+
ssh-key: '${{ secrets.COMMIT_KEY }}'
22+
# L26-L31 This will set all properties from the app.json to github action env variables
23+
- name: JSON to variables
24+
uses: antifree/json-to-variables@v1.0.1
25+
with:
26+
filename: 'app.json'
27+
prefix: app
28+
# L33-L36 Setup the nodejs version
29+
- name: Setup Node.js environment
30+
uses: actions/setup-node@v2.1.2
31+
with:
32+
node-version: '14.21.3'
33+
# L40-L41 Install the dependencies
34+
- name: Install dependencies
35+
run: npm i
36+
# L43-L44 Install the apps cli
37+
- name: Install Rocket.Chat Apps cli
38+
run: npm i -g @rocket.chat/apps-cli
39+
# L46-L47 Pack the app (compiled)
40+
- name: Bundle App Compiled
41+
run: rc-apps package
42+
# L49-L50 Renames the pack (compiled)
43+
- name: Renaming Package Name
44+
run: cd dist && mv ${{ env.app_nameSlug }}_${{ env.app_version }}.zip ${{ env.app_nameSlug }}_${{ env.app_version }}-compiled.zip
45+
# L52-L53 Pack the app (not compiled)
46+
- name: Bundle App Not Compiled
47+
run: rc-apps package --no-compile
48+
# L55-L56 Renames the pack (not compiled)
49+
- name: Renaming Not Compiled Package Name
50+
run: cd dist && mv ${{ env.app_nameSlug }}_${{ env.app_version }}.zip ${{ env.app_nameSlug }}_${{ env.app_version }}-not-compiled.zip
51+
# L58-L76 Uploads both compiled and not compiled files inside the release
52+
- name: Upload TimeOff Compiled
53+
uses: svenstaro/upload-release-action@v2
54+
with:
55+
repo_token: ${{ secrets.GITHUB_TOKEN }}
56+
file: dist/${{ env.app_nameSlug}}_${{ env.app_version }}-compiled.zip
57+
asset_name: ${{ env.app_nameSlug}}_${{ env.app_version }}-compiled.zip
58+
tag: ${{ env.app_version }}
59+
overwrite: true
60+
body: ${{ github.event.release.body }}
61+
62+
- name: Upload TimeOff Not Compiled
63+
uses: svenstaro/upload-release-action@v2
64+
with:
65+
repo_token: ${{ secrets.GITHUB_TOKEN }}
66+
file: dist/${{ env.app_nameSlug }}_${{ env.app_version }}-not-compiled.zip
67+
asset_name: ${{ env.app_nameSlug }}_${{ env.app_version }}-not-compiled.zip
68+
tag: ${{ env.app_version }}
69+
overwrite: true
70+
body: ${{ github.event.release.body }}

.husky/pre-commit

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
# This loads nvm.sh and sets the correct PATH before running hook
5+
export NVM_DIR="$HOME/.nvm"
6+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
7+
8+
npm run lint
9+
npm run prettier-check

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
.*
4+
app.json

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "all",
4+
"singleQuote": true,
5+
"printWidth": 120,
6+
"useTabs": true,
7+
"tabWidth": 4
8+
}

TimeOffApp.ts

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {
2-
IAppAccessors,
3-
IConfigurationExtend,
4-
IConfigurationModify,
5-
IEnvironmentRead,
6-
IHttp,
7-
ILogger,
8-
IModify,
9-
IPersistence,
10-
IRead,
2+
IAppAccessors,
3+
IConfigurationExtend,
4+
IConfigurationModify,
5+
IEnvironmentRead,
6+
IHttp,
7+
ILogger,
8+
IModify,
9+
IPersistence,
10+
IRead,
1111
} from '@rocket.chat/apps-engine/definition/accessors';
1212
import { App } from '@rocket.chat/apps-engine/definition/App';
1313
import { IAppInfo } from '@rocket.chat/apps-engine/definition/metadata';
@@ -23,35 +23,46 @@ import { TimeOffCache } from './TimeOffCache';
2323
import { UserService } from './services/UserService';
2424

2525
export class TimeOffApp extends App implements IPostMessageSent {
26-
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
27-
super(info, logger, accessors);
28-
}
26+
constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) {
27+
super(info, logger, accessors);
28+
}
2929

30-
public async extendConfiguration(configuration: IConfigurationExtend, environmentRead: IEnvironmentRead): Promise<void> {
31-
configuration.slashCommands.provideSlashCommand(new TimeOffCommand(this));
32-
}
30+
public async extendConfiguration(
31+
configuration: IConfigurationExtend,
32+
_environmentRead: IEnvironmentRead,
33+
): Promise<void> {
34+
configuration.slashCommands.provideSlashCommand(new TimeOffCommand(this));
35+
}
3336

34-
public async onEnable(environmentRead: IEnvironmentRead, configurationModify: IConfigurationModify): Promise<boolean> {
35-
TimeOffCache.getInstance().invalidateCache();
36-
return Promise.resolve(true);
37-
}
37+
public async onEnable(
38+
_environmentRead: IEnvironmentRead,
39+
_configurationModify: IConfigurationModify,
40+
): Promise<boolean> {
41+
TimeOffCache.getInstance().invalidateCache();
42+
return Promise.resolve(true);
43+
}
3844

39-
public async checkPostMessageSent?(message: IMessage, read: IRead, http: IHttp): Promise<boolean> {
40-
// We only want to notify the user if the message was sent in a direct message
41-
return Promise.resolve(message.room.type === RoomType.DIRECT_MESSAGE);
42-
}
45+
public async checkPostMessageSent?(message: IMessage, _read: IRead, _http: IHttp): Promise<boolean> {
46+
// We only want to notify the user if the message was sent in a direct message
47+
return Promise.resolve(message.room.type === RoomType.DIRECT_MESSAGE);
48+
}
4349

44-
public async executePostMessageSent(message: IMessage, read: IRead, http: IHttp, persistence: IPersistence, modify: IModify): Promise<void> {
45-
const userRepository = new UserRepository(read);
46-
const userService = new UserService(userRepository);
50+
public async executePostMessageSent(
51+
message: IMessage,
52+
read: IRead,
53+
_http: IHttp,
54+
persistence: IPersistence,
55+
_modify: IModify,
56+
): Promise<void> {
57+
const userRepository = new UserRepository(read);
58+
const userService = new UserService(userRepository);
4759

48-
const timeOffRepository = new TimeOffRepository(this, read, persistence);
49-
const timeOffService = new TimeOffService(timeOffRepository);
60+
const timeOffRepository = new TimeOffRepository(this, read, persistence);
61+
const timeOffService = new TimeOffService(timeOffRepository);
5062

51-
const notifier = new AppNotifier(this, read);
52-
53-
const handler = new PostMessageSentHandler(this, userService, timeOffService, notifier);
54-
await handler.handle(message);
55-
}
63+
const notifier = new AppNotifier(this, read);
5664

65+
const handler = new PostMessageSentHandler(this, userService, timeOffService, notifier);
66+
await handler.handle(message);
67+
}
5768
}

TimeOffCache.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
import { ITimeOff } from "./interfaces/ITimeOff";
1+
import { ITimeOff } from './interfaces/ITimeOff';
22

33
export class TimeOffCache {
4-
private static instance: TimeOffCache;
5-
private cache: Map<string, { data: ITimeOff; expiresAt: number }>;
6-
private TTL = 60 * 60 * 1000; // 1 hour cache
7-
8-
private constructor() {
9-
this.cache = new Map();
10-
}
11-
12-
public static getInstance(): TimeOffCache {
13-
if (!TimeOffCache.instance) {
14-
TimeOffCache.instance = new TimeOffCache();
15-
}
16-
return TimeOffCache.instance;
17-
}
18-
19-
public set(userId: string, timeOffData: ITimeOff): void {
20-
const expiresAt = Date.now() + this.TTL;
21-
this.cache.set(userId, { data: timeOffData, expiresAt });
22-
}
23-
24-
public get(userId: string): ITimeOff | undefined {
25-
const cached = this.cache.get(userId);
26-
if (!cached) return undefined;
27-
28-
if (Date.now() > cached.expiresAt) {
29-
this.cache.delete(userId);
30-
return undefined;
31-
}
32-
33-
return cached.data;
34-
}
35-
36-
public invalidateUser(userId: string): void {
37-
this.cache.delete(userId);
38-
}
39-
40-
public invalidateCache(): void {
41-
this.cache.clear();
42-
}
4+
private static instance: TimeOffCache;
5+
private cache: Map<string, { data: ITimeOff; expiresAt: number }>;
6+
private TTL = 60 * 60 * 1000; // 1 hour cache
7+
8+
private constructor() {
9+
this.cache = new Map();
10+
}
11+
12+
public static getInstance(): TimeOffCache {
13+
if (!TimeOffCache.instance) {
14+
TimeOffCache.instance = new TimeOffCache();
15+
}
16+
return TimeOffCache.instance;
17+
}
18+
19+
public set(userId: string, timeOffData: ITimeOff): void {
20+
const expiresAt = Date.now() + this.TTL;
21+
this.cache.set(userId, { data: timeOffData, expiresAt });
22+
}
23+
24+
public get(userId: string): ITimeOff | undefined {
25+
const cached = this.cache.get(userId);
26+
if (!cached) return undefined;
27+
28+
if (Date.now() > cached.expiresAt) {
29+
this.cache.delete(userId);
30+
return undefined;
31+
}
32+
33+
return cached.data;
34+
}
35+
36+
public invalidateUser(userId: string): void {
37+
this.cache.delete(userId);
38+
}
39+
40+
public invalidateCache(): void {
41+
this.cache.clear();
42+
}
4343
}

app.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
"implements": [
1616
"IPostMessageSent"
1717
]
18-
}
18+
}

0 commit comments

Comments
 (0)