Skip to content

Commit

Permalink
refactor(linting): use zero-config ts-standard
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneRifle committed Dec 6, 2022
1 parent 945783c commit 174b175
Show file tree
Hide file tree
Showing 75 changed files with 3,020 additions and 1,002 deletions.
5 changes: 0 additions & 5 deletions .eslintignore

This file was deleted.

94 changes: 0 additions & 94 deletions .eslintrc.js

This file was deleted.

6 changes: 0 additions & 6 deletions .prettierrc.js

This file was deleted.

7 changes: 0 additions & 7 deletions backend/.eslintrc.js

This file was deleted.

4 changes: 2 additions & 2 deletions backend/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const config: Config.InitialOptions = {
collectCoverageFrom: ['<rootDir>/src/**/*.{ts,js}'],
coveragePathIgnorePatterns: ['<rootDir>/build', '<rootDir>/node_modules'],
moduleNameMapper: {
'~shared/(.*)': '<rootDir>/../shared/src/$1',
},
'~shared/(.*)': '<rootDir>/../shared/src/$1'
}
}

export default config
22 changes: 0 additions & 22 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "0.1.0",
"private": true,
"scripts": {
"lint": "eslint --ext ts,tsx,js,jsx . && prettier -c \"src/**/*.{ts,tsx}\"",
"lint:fix": "eslint --fix --ext ts,tsx,js,jsx . && prettier -c --write \"src/**/*.{ts,tsx}\"",
"lint": "ts-standard",
"lint:fix": "npm run lint -- --fix",
"pre-commit": "lint-staged",
"prebuild": "rimraf build",
"build": "nest build",
Expand Down Expand Up @@ -73,7 +73,6 @@
"jest": "^28.1.3",
"lint-staged": "^13.1.0",
"pino-pretty": "^9.1.1",
"prettier": "^2.8.0",
"rimraf": "^3.0.2",
"supertest": "^6.3.1",
"ts-jest": "^28.0.8",
Expand All @@ -84,7 +83,12 @@
},
"lint-staged": {
"**/*.(js|jsx|ts|tsx)": [
"eslint --fix"
"ts-standard --fix"
]
},
"ts-standard": {
"ignore": [
"build"
]
}
}
16 changes: 8 additions & 8 deletions backend/scripts/env/loader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import fs from 'fs'
import { exit } from 'process'

/**
* This is a helper for local file runs or jest, as specified in package.json
* It emulates the loading of SSM which Lambda will do.
* This is a helper for local file runs or jest, as specified in package.json
* It emulates the loading of SSM which Lambda will do.
* This is not meant to be used in a deployment and is .mjs so we can use top-level await
*/
async function loadAllParameters() {
async function loadAllParameters () {
console.log(`Retrieving parameters for ENV=${process.env.ENV}`)

if (process.env.ENV === 'development') {
console.log('In develop mode! Not fetching from SSM param store.')
console.log(
'Please reference .env.example to populate .env.development file for development environment',
'Please reference .env.example to populate .env.development file for development environment'
)
exit(0)
}
Expand All @@ -30,8 +30,8 @@ async function loadAllParameters() {
Path: prefix,
Recursive: true,
WithDecryption: true,
...(nextToken ? { NextToken: nextToken } : {}),
}),
...(nextToken ? { NextToken: nextToken } : {})
})
)

for (const parameter of res.Parameters ?? []) {
Expand All @@ -56,14 +56,14 @@ async function loadAllParameters() {
return looksLikeJson ? `${k}=${strippedValue}` : `${k}='${strippedValue}'`
})
.join('\n')
.concat(params['NODE_ENV'] ? '' : `\nNODE_ENV=${process.env.ENV}`)
.concat(params.NODE_ENV ? '' : `\nNODE_ENV=${process.env.ENV}`)

if (Object.entries(params).length > 0) {
console.log(`Writing to file .env.${process.env.ENV}`)
await fs.promises.writeFile(`.env.${process.env.ENV}`, envString)
} else {
console.log(
`No env vars found, not writing to file .env.${process.env.ENV}`,
`No env vars found, not writing to file .env.${process.env.ENV}`
)
}
}
Expand Down
14 changes: 7 additions & 7 deletions backend/scripts/env/putter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { exit } from 'process'
import dotenv from 'dotenv'

/**
* This is a helper for local file runs or jest, as specified in package.json
* It emulates the putting of parameters into SSM which Lambda will do.
* This is a helper for local file runs or jest, as specified in package.json
* It emulates the putting of parameters into SSM which Lambda will do.
* This is not meant to be used in a deployment and is .mjs so we can use top-level await
*/
async function putAllParameters() {
async function putAllParameters () {
console.log(`Retrieving parameters for ENV=${process.env.ENV}`)

if (process.env.ENV === 'development') {
Expand All @@ -29,8 +29,8 @@ async function putAllParameters() {
Path: prefix,
Recursive: true,
WithDecryption: true,
...(nextToken ? { NextToken: nextToken } : {}),
}),
...(nextToken ? { NextToken: nextToken } : {})
})
)

for (const parameter of res.Parameters ?? []) {
Expand All @@ -53,11 +53,11 @@ async function putAllParameters() {
if (Object.keys(params).includes(k) && params[k] !== v) {
// different values, set override flag
console.log(
`aws ssm put-parameter --overwrite --name /application/${process.env.ENV}/${k} --value ${v} --type String`,
`aws ssm put-parameter --overwrite --name /application/${process.env.ENV}/${k} --value ${v} --type String`
)
} else if (!Object.keys(params).includes(k)) {
console.log(
`aws ssm put-parameter --name /application/${process.env.ENV}/${k} --value ${v} --type String`,
`aws ssm put-parameter --name /application/${process.env.ENV}/${k} --value ${v} --type String`
)
}
}
Expand Down
10 changes: 5 additions & 5 deletions backend/src/api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const apiModules = [
TerminusModule,
HealthModule,
OtpModule,
MailerModule,
MailerModule
]

@Module({
Expand All @@ -21,9 +21,9 @@ const apiModules = [
RouterModule.register([
{
path: 'api',
children: apiModules,
},
]),
],
children: apiModules
}
])
]
})
export class ApiModule {}
20 changes: 10 additions & 10 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const FRONTEND_PATH = join(__dirname, '..', '..', 'frontend', 'build')
customProps: (req) => {
const context = {
trace_id: req.headers['x-datadog-trace-id'],
xray_id: req.headers['x-amzn-trace-id'],
xray_id: req.headers['x-amzn-trace-id']
}
return { context, scope: 'NestApplication' }
},
Expand All @@ -40,15 +40,15 @@ const FRONTEND_PATH = join(__dirname, '..', '..', 'frontend', 'build')
return `${req.method ?? ''} ${req.url ?? ''} ${res.statusCode}: (${
err.name
}) ${err.message}`
},
}
},
renameContext: 'scope',
}),
renameContext: 'scope'
})
}),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useClass: DatabaseConfigService,
useClass: DatabaseConfigService
}),
ServeStaticModule.forRoot({
rootPath: FRONTEND_PATH,
Expand All @@ -60,13 +60,13 @@ const FRONTEND_PATH = join(__dirname, '..', '..', 'frontend', 'build')
if (path === join(FRONTEND_PATH, 'index.html')) {
res.setHeader('Cache-control', 'public, max-age=0')
}
},
},
}),
],
}
}
})
]
})
export class AppModule implements NestModule {
configure(consumer: MiddlewareConsumer): void {
configure (consumer: MiddlewareConsumer): void {
consumer.apply(HelmetMiddleware, SessionMiddleware).forRoutes('*')
}
}
12 changes: 6 additions & 6 deletions backend/src/auth/__tests__/auth.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ describe('AuthController', () => {
AuthService,
{
provide: getRepositoryToken(User),
useValue: mockModel,
useValue: mockModel
},
{
provide: getRepositoryToken(Session),
useValue: mockModel,
useValue: mockModel
},
{
provide: `${PinoLogger.name}:${AuthController.name}`,
useValue: console,
useValue: console
},
{
provide: `${PinoLogger.name}:${AuthService.name}`,
useValue: console,
},
],
useValue: console
}
]
}).compile()

controller = module.get<AuthController>(AuthController)
Expand Down
Loading

0 comments on commit 174b175

Please sign in to comment.