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-callback-literal': 'error',
// 'n/no-deprecated-api': 'error', // part of n/recommended // 'n/no-deprecated-api': 'error', // part of n/recommended
// 'n/no-exports-assign': '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-extraneous-require': 'error', // part of n/recommended
'n/no-hide-core-modules': 'error', 'n/no-hide-core-modules': 'error',
'n/no-missing-import': 'off', // not compatible with typescript // part of n/recommended '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-process-exit': 'error', // part of n/recommended
'n/no-restricted-import': 'error', 'n/no-restricted-import': 'error',
'n/no-restricted-require': '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-bin': 'error', // part of n/recommended
'n/no-unpublished-import': [ 'n/no-unpublished-import': [
'error', 'error',

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -44,7 +44,7 @@ export default {
const [currentUser] = await loginReadTxResultPromise const [currentUser] = await loginReadTxResultPromise
if ( if (
currentUser && currentUser &&
(await bcrypt.compareSync(password, currentUser.encryptedPassword)) && (await bcrypt.compare(password, currentUser.encryptedPassword)) &&
!currentUser.disabled !currentUser.disabled
) { ) {
delete currentUser.encryptedPassword delete currentUser.encryptedPassword
@ -62,15 +62,15 @@ export default {
const currentUser = await neode.find('User', user.id) const currentUser = await neode.find('User', user.id)
const encryptedPassword = currentUser.get('encryptedPassword') 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') 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') 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({ await currentUser.update({
encryptedPassword: newEncryptedPassword, encryptedPassword: newEncryptedPassword,
updatedAt: new Date().toISOString(), updatedAt: new Date().toISOString(),