lint n/no-sync (#8405)

This commit is contained in:
Ulf Gebhardt 2025-04-24 21:50:13 +02:00 committed by GitHub
parent 649491f7cb
commit d4cc843662
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 20 additions and 7 deletions

View File

@ -115,7 +115,7 @@ module.exports = {
'n/no-callback-literal': 'error',
// 'n/no-deprecated-api': 'error', // part of n/recommended
// 'n/no-exports-assign': 'error', // part of n/recommended
'n/no-extraneous-import': 'off', // TODO // part of n/recommended
'n/no-extraneous-import': 'off', // duplicate of import/no-extraneous-dependencies // part of n/recommended
// 'n/no-extraneous-require': 'error', // part of n/recommended
'n/no-hide-core-modules': 'error',
'n/no-missing-import': 'off', // not compatible with typescript // part of n/recommended
@ -127,7 +127,7 @@ module.exports = {
// 'n/no-process-exit': 'error', // part of n/recommended
'n/no-restricted-import': 'error',
'n/no-restricted-require': 'error',
// 'n/no-sync': 'error',
'n/no-sync': 'error',
// 'n/no-unpublished-bin': 'error', // part of n/recommended
'n/no-unpublished-import': [
'error',

View File

@ -11,6 +11,7 @@ import { getDriver } from './neo4j'
const defaultAdmin = {
email: 'admin@example.org',
// eslint-disable-next-line n/no-sync
password: hashSync('1234', 10),
name: 'admin',
id: uuid(),

View File

@ -95,6 +95,7 @@ Factory.define('basicUser')
return slug || slugify(name, { lower: true })
})
.attr('encryptedPassword', ['password'], (password) => {
// eslint-disable-next-line n/no-sync
return hashSync(password, 10)
})

View File

@ -55,6 +55,7 @@ export async function up(next) {
const { pathname } = new URL(url, 'http://example.org')
const fileLocation = path.join(__dirname, `../../../public/${pathname}`)
const s3Location = `original${pathname}`
// eslint-disable-next-line n/no-sync
if (existsSync(fileLocation)) {
const mimeType = mime.lookup(fileLocation)
const params = {

View File

@ -33,6 +33,7 @@ export async function up(next) {
const urls = records.map((record) => record.get('url'))
const danglingUrls = urls.filter((url) => {
const fileLocation = `public${url}`
// eslint-disable-next-line n/no-sync
return !existsSync(fileLocation)
})
await transaction.run(

View File

@ -4,6 +4,7 @@
import { hashSync } from 'bcryptjs'
export default function (args) {
// eslint-disable-next-line n/no-sync
args.encryptedPassword = hashSync(args.password, 10)
delete args.password
return args

View File

@ -3,6 +3,7 @@
import fs from 'node:fs'
import path from 'node:path'
// eslint-disable-next-line n/no-sync
const readFile = (fileName) => fs.readFileSync(path.join(__dirname, fileName), 'utf-8')
export const notification = readFile('./notification.html')

View File

@ -3,6 +3,7 @@
import fs from 'node:fs'
import path from 'node:path'
// eslint-disable-next-line n/no-sync
const readFile = (fileName) => fs.readFileSync(path.join(__dirname, fileName), 'utf-8')
export const notification = readFile('./notification.html')

View File

@ -3,6 +3,7 @@
import fs from 'node:fs'
import path from 'node:path'
// eslint-disable-next-line n/no-sync
const readFile = (fileName) => fs.readFileSync(path.join(__dirname, fileName), 'utf-8')
export const signup = readFile('./signup.html')

View File

@ -20,14 +20,17 @@ afterEach(() => {
let variables = {}
// eslint-disable-next-line n/no-sync
const HumanConnectionOrg = fs.readFileSync(
path.join(__dirname, '../../../snapshots/embeds/HumanConnectionOrg.html'),
'utf8',
)
// eslint-disable-next-line n/no-sync
const pr3934 = fs.readFileSync(
path.join(__dirname, '../../../snapshots/embeds/pr3934.html'),
'utf8',
)
// eslint-disable-next-line n/no-sync
const babyLovesCat = fs.readFileSync(
path.join(__dirname, '../../../snapshots/embeds/babyLovesCat.html'),
'utf8',

View File

@ -8,6 +8,7 @@ import path from 'node:path'
import { minimatch } from 'minimatch'
// eslint-disable-next-line n/no-sync
let oEmbedProvidersFile = fs.readFileSync(
path.join(__dirname, '../../../../public/providers.json'),
'utf8',

View File

@ -152,6 +152,7 @@ const s3Upload = async ({ createReadStream, uniqueFilename, mimetype }) => {
const localFileDelete = async (url) => {
const location = `public${url}`
// eslint-disable-next-line n/no-sync
if (existsSync(location)) unlinkSync(location)
}

View File

@ -21,7 +21,7 @@ export default {
resetPassword: async (_parent, { email, nonce, newPassword }, { driver }) => {
const stillValid = new Date()
stillValid.setDate(stillValid.getDate() - 1)
const encryptedNewPassword = await bcrypt.hashSync(newPassword, 10)
const encryptedNewPassword = await bcrypt.hash(newPassword, 10)
const session = driver.session()
try {
const passwordResetTxPromise = session.writeTransaction(async (transaction) => {

View File

@ -44,7 +44,7 @@ export default {
const [currentUser] = await loginReadTxResultPromise
if (
currentUser &&
(await bcrypt.compareSync(password, currentUser.encryptedPassword)) &&
(await bcrypt.compare(password, currentUser.encryptedPassword)) &&
!currentUser.disabled
) {
delete currentUser.encryptedPassword
@ -62,15 +62,15 @@ export default {
const currentUser = await neode.find('User', user.id)
const encryptedPassword = currentUser.get('encryptedPassword')
if (!(await bcrypt.compareSync(oldPassword, encryptedPassword))) {
if (!(await bcrypt.compare(oldPassword, encryptedPassword))) {
throw new AuthenticationError('Old password is not correct')
}
if (await bcrypt.compareSync(newPassword, encryptedPassword)) {
if (await bcrypt.compare(newPassword, encryptedPassword)) {
throw new AuthenticationError('Old password and new password should be different')
}
const newEncryptedPassword = await bcrypt.hashSync(newPassword, 10)
const newEncryptedPassword = await bcrypt.hash(newPassword, 10)
await currentUser.update({
encryptedPassword: newEncryptedPassword,
updatedAt: new Date().toISOString(),