Skip to content

Commit

Permalink
chore(lint): add some ts related rules
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledmashaly committed Mar 29, 2023
1 parent ce8a228 commit ab4e892
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 36 deletions.
69 changes: 59 additions & 10 deletions packages/backend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,78 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"extends": [
"../../.eslintrc.json"
],
"ignorePatterns": [
"!**/*"
],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"files": [
"*.ts",
"*.tsx",
"*.js",
"*.jsx"
],
"parserOptions": {
"project": [
"packages/backend/tsconfig.*?.json"
]
},
"rules": {
"brace-style": "off",
"comma-dangle": "off",
"indent": "off",
"no-console": "error",
"quotes": "off",
"semi": "off",
"@typescript-eslint/brace-style": ["error", "stroustrup"],
"@typescript-eslint/comma-dangle": ["error", "always-multiline"],
"@typescript-eslint/indent": ["error", 4],
"@typescript-eslint/quotes": ["error", "single"],
"@typescript-eslint/semi": ["warn", "never"]
"@typescript-eslint/brace-style": [
"error",
"stroustrup"
],
"@typescript-eslint/comma-dangle": [
"error",
"always-multiline"
],
"@typescript-eslint/indent": [
"error",
4
],
"@typescript-eslint/quotes": [
"error",
"single"
],
"@typescript-eslint/semi": [
"warn",
"never"
],
"no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-redundant-type-constituents": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/adjacent-overload-signatures": "error",
"comma-spacing": "off",
"@typescript-eslint/comma-spacing": [
"error",
{
"before": false,
"after": true
}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"files": [
"*.ts",
"*.tsx"
],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"files": [
"*.js",
"*.jsx"
],
"rules": {}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EntitySchema } from 'typeorm'
import { ApIdSchema, BaseColumnSchemaPart } from '../helper/base-entity'
import { EncryptedObject } from '../helper/encryption'

export type AppConnectionSchema = AppConnection & { project: Project , value: EncryptedObject}
export type AppConnectionSchema = AppConnection & { project: Project, value: EncryptedObject}

export const AppConnectionEntity = new EntitySchema<AppConnectionSchema>({
name: 'app_connection',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { databaseConnection } from '../database/database-connection'
import { buildPaginator } from '../helper/pagination/build-paginator'
import { paginationHelper } from '../helper/pagination/pagination-utils'
import { AppConnectionEntity } from './app-connection.entity'
import axios, { AxiosError } from 'axios'
import axios from 'axios'
import { createRedisLock } from '../database/redis-connection'
import { decryptObject, encryptObject } from '../helper/encryption'
import { getEdition } from '../helper/secret-helper'
Expand All @@ -29,7 +29,7 @@ const appConnectionRepo = databaseConnection.getRepository(AppConnectionEntity)

export const appConnectionService = {
async upsert({ projectId, request }: { projectId: ProjectId, request: UpsertConnectionRequest }): Promise<AppConnection> {
let response: any = request.value
let response: Record<string, unknown> = request.value
switch (request.value.type) {
case AppConnectionType.CLOUD_OAUTH2:
response = await claimWithCloud({
Expand Down Expand Up @@ -216,7 +216,7 @@ async function claim(request: {
redirectUrl: string,
code: string,
codeVerifier: string
}): Promise<unknown> {
}): Promise<Record<string, unknown>> {
try {
const params = {
client_id: request.clientId,
Expand All @@ -239,7 +239,7 @@ async function claim(request: {
).data
return { ...formatOAuth2Response(response), client_id: request.clientId, client_secret: request.clientSecret }
}
catch (e: unknown | AxiosError) {
catch (e: unknown) {
logger.error(e)
throw new ActivepiecesError({
code: ErrorCode.INVALID_CLAIM, params: {
Expand All @@ -253,11 +253,11 @@ async function claim(request: {

async function claimWithCloud(request: {
pieceName: string; code: string; codeVerifier: string, edition: string; clientId: string
}): Promise<unknown> {
}): Promise<Record<string, unknown>> {
try {
return (await axios.post('https://secrets.activepieces.com/claim', request)).data
}
catch (e: unknown | AxiosError) {
catch (e: unknown) {
logger.error(e)
throw new ActivepiecesError({
code: ErrorCode.INVALID_CLOUD_CLAIM, params: {
Expand All @@ -267,7 +267,7 @@ async function claimWithCloud(request: {
}
}

function formatOAuth2Response(response: Record<string, any>) {
function formatOAuth2Response(response: unknown) {
const secondsSinceEpoch = Math.round(Date.now() / 1000)
const formattedResponse: BaseOAuth2ConnectionValue = {
access_token: response['access_token'],
Expand All @@ -283,7 +283,7 @@ function formatOAuth2Response(response: Record<string, any>) {
return formattedResponse
}

function deleteProps(obj: Record<string, any>, prop: string[]) {
function deleteProps(obj: Record<string, unknown>, prop: string[]) {
for (const p of prop) {
delete obj[p]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const appEventRoutingController = async (fastify: FastifyInstance) => {
},
async (
request: FastifyRequest<{
Body: any;
Body: unknown;
Params: {
pieceName: string;
}
Expand All @@ -38,7 +38,7 @@ export const appEventRoutingController = async (fastify: FastifyInstance) => {
pieceName: pieceName,
event: eventPayload,
})

logger.info(`Received event ${event} with identifier ${identifierValue} in app ${pieceName}`)
if (event && identifierValue) {
const listeners = await appEventRoutingService.listListeners({
Expand All @@ -58,4 +58,4 @@ export const appEventRoutingController = async (fastify: FastifyInstance) => {
},
)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const authenticationController = async (app: FastifyInstance) => {
},
async (request: FastifyRequest<{ Body: SignUpRequest }>, reply: FastifyReply) => {
const userCreated = await flagService.getOne(ApFlagId.USER_CREATED)
const signUpEnabled = (await system.getBoolean(SystemProp.SIGN_UP_ENABLED)) ?? false
const signUpEnabled = system.getBoolean(SystemProp.SIGN_UP_ENABLED) ?? false
if (userCreated && !signUpEnabled) {
reply.code(403).send({
message: 'Sign up is disabled',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const collectionController = async (fastify: FastifyInstance) => {
Body: UpdateCollectionRequest;
}>,
) => {
const collection = await collectionService.getOne({ id: request.params.collectionId,projectId: request.principal.projectId })
const collection = await collectionService.getOne({ id: request.params.collectionId, projectId: request.principal.projectId })
if (collection === null) {
throw new ActivepiecesError({
code: ErrorCode.COLLECTION_NOT_FOUND,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function validateProps(props: PieceProperty, input: Record<string, unknown>) {

function buildSchema(props: PieceProperty): TSchema {
const entries = Object.entries(props)
const nonNullableUnknownPropType = Type.Not(Type.Null(),Type.Unknown())
const nonNullableUnknownPropType = Type.Not(Type.Null(), Type.Unknown())
const propsSchema: Record<string, TSchema> = {}
for (let i = 0; i < entries.length; ++i) {
const property = entries[i][1]
Expand All @@ -251,7 +251,7 @@ function buildSchema(props: PieceProperty): TSchema {
})
break
case PropertyType.CHECKBOX:
propsSchema[name] = Type.Union([Type.Boolean(),Type.String({})])
propsSchema[name] = Type.Union([Type.Boolean(), Type.String({})])
break
case PropertyType.NUMBER:
// Because it could be a variable
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/app/flows/flow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const flowService = {
}
},
async update({ flowId, projectId, request }: { projectId: ProjectId, flowId: FlowId, request: FlowOperationRequest }): Promise<Flow | null> {
const flowLock = await createRedisLock()
const flowLock = createRedisLock()
try {
await flowLock.acquire(flowId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ProjectId,
SeekPage,
Trigger,
TriggerEvent ,
TriggerEvent,
TriggerHookType,
TriggerType,
} from '@activepieces/shared'
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/app/helper/engine-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const engineHelper = {
return result as void
},

async executeProp(operation: ExecutePropsOptions): Promise<DropdownState<any> | Record<string, DynamicPropsValue>> {
async executeProp(operation: ExecutePropsOptions): Promise<DropdownState<unknown> | Record<string, DynamicPropsValue>> {
const sandbox = sandboxManager.obtainSandbox()
let result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const openapiController = async (fastify: FastifyInstance) => {
fastify.get(
'/',
async () => {
return JSON.stringify(fastify.swagger(),null,2)
return JSON.stringify(fastify.swagger(), null, 2)
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function btoa(value: string): string {
return Buffer.from(value).toString('base64')
}

export function encodeByType(type: string, value: any): string | null {
export function encodeByType(type: string, value: unknown): string | null {
if (value === null) return null

switch (type) {
Expand All @@ -21,14 +21,14 @@ export function encodeByType(type: string, value: any): string | null {
return `${value}`
}
case 'string': {
return encodeURIComponent(value)
return encodeURIComponent(value as string)
}
case 'object': {
/**
* if reflection type is Object, check whether an object is a date.
* see: https://github.com/rbuckton/reflect-metadata/issues/84
*/
if (typeof value.getTime === 'function') {
if (typeof (value as Record<string, unknown>).getTime === 'function') {
return (value as Date).getTime().toString()
}

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/app/helper/pagination/paginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export enum Order {
DESC = 'DESC',
}

export type CursorParam = Record<string, any>
export type CursorParam = Record<string, unknown>

export interface CursorResult {
beforeCursor: string | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async function downloadFiles(
projectId: ProjectId,
flowVersion: FlowVersion,
): Promise<void> {
const flowLock = await createRedisLock()
const flowLock = createRedisLock()
try {
logger.info(`[${flowVersion.id}] Acquiring flow lock to build codes`)
await flowLock.acquire(flowVersion.id)
Expand Down
5 changes: 4 additions & 1 deletion packages/backend/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
"src/**/*.d.ts",
"test/**/*.test.ts",
"test/**/*.spec.ts",
"test/**/*.d.ts",
]
}

0 comments on commit ab4e892

Please sign in to comment.