Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: drop eslint #148

Merged
merged 1 commit into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/fastifyAwilixPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ const { AwilixManager } = require('awilix-manager')
const fp = require('fastify-plugin')

const diContainerProxy = awilix.createContainer({
injectionMode: 'PROXY',
injectionMode: 'PROXY'
})

const diContainerClassic = awilix.createContainer({
injectionMode: 'CLASSIC',
injectionMode: 'CLASSIC'
})

function plugin(fastify, opts, next) {
function plugin (fastify, opts, next) {
if (opts.container && opts.injectionMode) {
return next(
new Error(
'If you are passing pre-created container explicitly, you cannot specify injection mode',
),
'If you are passing pre-created container explicitly, you cannot specify injection mode'
)
)
}

Expand All @@ -32,7 +32,7 @@ function plugin(fastify, opts, next) {
asyncDispose: opts.asyncDispose,
asyncInit: opts.asyncInit,
eagerInject: opts.eagerInject,
strictBooleanEnforced: opts.strictBooleanEnforced,
strictBooleanEnforced: opts.strictBooleanEnforced
})
const disposeOnResponse = opts.disposeOnResponse === true || opts.disposeOnResponse === undefined
const disposeOnClose = opts.disposeOnClose === true || opts.disposeOnClose === undefined
Expand Down Expand Up @@ -80,12 +80,12 @@ function plugin(fastify, opts, next) {

const fastifyAwilixPlugin = fp(plugin, {
fastify: '4.x',
name: '@fastify/awilix',
name: '@fastify/awilix'
})

module.exports = {
diContainer: diContainerProxy,
diContainerProxy,
diContainerClassic,
fastifyAwilixPlugin,
fastifyAwilixPlugin
}
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const {
diContainer,
fastifyAwilixPlugin,
diContainerProxy,
diContainerClassic,
diContainerClassic
} = require('./fastifyAwilixPlugin')

module.exports = {
diContainer,
diContainerClassic,
diContainerProxy,
fastifyAwilixPlugin,
fastifyAwilixPlugin
}
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
"test": "c8 --100 node --test",
"test:ci": "npm run lint && npm run test:typescript && npm run test",
"test:typescript": "tsd",
"lint": "eslint \"lib/**/*.js\" lib/index.js",
"lint:fix": "eslint --fix \"lib/**/*.js\" lib/index.js",
"prettier": "prettier --write \"{lib,test}/**/*.js\" lib/index.js lib/index.d.ts"
"lint": "standard | snazzy",
"lint:fix": "standard --fix | snazzy"
},
"dependencies": {
"awilix-manager": "^5.1.0",
Expand All @@ -33,11 +32,9 @@
"@types/node": "^22.0.0",
"awilix": "^10.0.2",
"c8": "^10.1.2",
"eslint": "^9.5.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"fastify": "^4.26.2",
"prettier": "^3.2.5",
"snazzy": "^9.0.0",
"standard": "^17.1.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not neostandard?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One dep to rule them all: when we have these silly trouble due a breaking change, it is always a pain if we use one different library for every repo. Pain means time that nobody wants to invest in these tasks.

This pr is no brainier because we run these deps on every other fastify repo. We know them, we trust them.

Evaluating something else is something that we need to do (standard is no more used in the main repo), but it is a different task imho

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good!

"tsd": "^0.31.0"
},
"homepage": "http://github.com/fastify/fastify-awilix",
Expand Down
32 changes: 15 additions & 17 deletions test/awilixManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,30 @@ let isInittedGlobal = false
let isDisposedGlobal = false

class InitSetClass {
constructor() {
constructor () {
isInittedGlobal = true
}
}

class AsyncInitSetClass {
constructor() {}

async init() {
async init () {
isInittedGlobal = true
}

async dispose() {
async dispose () {
isDisposedGlobal = true
}
}

const variations = [
{
injectionMode: 'PROXY',
container: diContainer,
container: diContainer
},
{
injectionMode: 'CLASSIC',
container: diContainerClassic,
},
container: diContainerClassic
}
]

describe('awilixManager', () => {
Expand All @@ -63,13 +61,13 @@ describe('awilixManager', () => {
'dependency1',
asClass(InitSetClass, {
lifetime: 'SINGLETON',
eagerInject: true,
}),
eagerInject: true
})
)
app = fastify({ logger: false })
await app.register(fastifyAwilixPlugin, {
eagerInject: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
await app.ready()

Expand All @@ -81,13 +79,13 @@ describe('awilixManager', () => {
'dependency1',
asClass(AsyncInitSetClass, {
lifetime: 'SINGLETON',
asyncInit: 'init',
}),
asyncInit: 'init'
})
)
app = fastify({ logger: false })
await app.register(fastifyAwilixPlugin, {
asyncInit: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
await app.ready()

Expand All @@ -99,13 +97,13 @@ describe('awilixManager', () => {
'dependency1',
asClass(AsyncInitSetClass, {
lifetime: 'SINGLETON',
asyncDispose: 'dispose',
}),
asyncDispose: 'dispose'
})
)
app = fastify({ logger: false })
await app.register(fastifyAwilixPlugin, {
asyncDispose: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
await app.ready()
await app.close()
Expand Down
68 changes: 34 additions & 34 deletions test/fastifyAwilixPlugin.dispose.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const assert = require('node:assert')
const { fastifyAwilixPlugin, diContainer, diContainerClassic } = require('../lib')

class UserRepository {
constructor() {
constructor () {
this.disposeCounter = 0
}

dispose() {
dispose () {
this.disposeCounter++
}
}
Expand All @@ -23,15 +23,15 @@ let storedUserRepositoryScoped
const variations = [
{
injectionMode: 'PROXY',
container: diContainer,
container: diContainer
},
{
injectionMode: 'CLASSIC',
container: diContainerClassic,
},
container: diContainerClassic
}
]

function getCompletedRequests(output) {
function getCompletedRequests (output) {
return output.filter((line) => {
try {
return JSON.parse(line).msg === 'request completed'
Expand All @@ -43,7 +43,7 @@ function getCompletedRequests(output) {

describe('fastifyAwilixPlugin', () => {
let app, output
let write = process.stdout.write
const write = process.stdout.write

beforeEach(() => {
storedUserRepository = undefined
Expand All @@ -65,7 +65,7 @@ describe('fastifyAwilixPlugin', () => {
assert.equal(userRepository.disposeCounter, 0)

res.send({
status: 'OK',
status: 'OK'
})
}

Expand All @@ -80,7 +80,7 @@ describe('fastifyAwilixPlugin', () => {
assert.equal(userRepositoryScoped.disposeCounter, 0)

res.send({
status: 'OK',
status: 'OK'
})
}

Expand All @@ -89,13 +89,13 @@ describe('fastifyAwilixPlugin', () => {
app.register(fastifyAwilixPlugin, {
disposeOnClose: true,
disposeOnResponse: false,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
variation.container.register({
userRepository: asClass(UserRepository, {
lifetime: Lifetime.SINGLETON,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})

app.post('/', endpoint)
Expand All @@ -116,13 +116,13 @@ describe('fastifyAwilixPlugin', () => {
app.register(fastifyAwilixPlugin, {
disposeOnClose: false,
disposeOnResponse: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
variation.container.register({
userRepository: asClass(UserRepository, {
lifetime: Lifetime.SINGLETON,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})

app.post('/', endpoint)
Expand All @@ -147,13 +147,13 @@ describe('fastifyAwilixPlugin', () => {
await app.register(fastifyAwilixPlugin, {
disposeOnClose: false,
disposeOnResponse: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
variation.container.register({
userRepository: asClass(UserRepository, {
lifetime: Lifetime.SINGLETON,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})

let storedError = null
Expand Down Expand Up @@ -181,21 +181,21 @@ describe('fastifyAwilixPlugin', () => {
app.register(fastifyAwilixPlugin, {
disposeOnClose: false,
disposeOnResponse: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})

variation.container.register({
userRepository: asClass(UserRepository, {
lifetime: Lifetime.SINGLETON,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})
app.addHook('onRequest', (request, reply, done) => {
request.diScope.register({
userRepositoryScoped: asClass(UserRepository, {
lifetime: Lifetime.SCOPED,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})
done()
})
Expand All @@ -220,21 +220,21 @@ describe('fastifyAwilixPlugin', () => {
app.register(fastifyAwilixPlugin, {
disposeOnClose: true,
disposeOnResponse: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})

variation.container.register({
userRepository: asClass(UserRepository, {
lifetime: Lifetime.SINGLETON,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})
app.addHook('onRequest', (request, reply, done) => {
request.diScope.register({
userRepositoryScoped: asClass(UserRepository, {
lifetime: Lifetime.SCOPED,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})
done()
})
Expand All @@ -261,13 +261,13 @@ describe('fastifyAwilixPlugin', () => {
app.register(fastifyAwilixPlugin, {
disposeOnClose: true,
disposeOnResponse: true,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
variation.container.register({
userRepository: asClass(UserRepository, {
lifetime: Lifetime.SINGLETON,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})

app.post('/', endpoint)
Expand All @@ -287,13 +287,13 @@ describe('fastifyAwilixPlugin', () => {
app.register(fastifyAwilixPlugin, {
disposeOnClose: false,
disposeOnResponse: false,
injectionMode: variation.injectionMode,
injectionMode: variation.injectionMode
})
variation.container.register({
userRepository: asClass(UserRepository, {
lifetime: Lifetime.SINGLETON,
dispose: (service) => service.dispose(),
}),
dispose: (service) => service.dispose()
})
})

app.post('/', endpoint)
Expand Down
Loading