From 192e31fa990ab6b008dcd54c4c59fb017c234571 Mon Sep 17 00:00:00 2001 From: filipenevola Date: Fri, 15 Dec 2023 08:39:59 -0400 Subject: [PATCH] Fixes getInitFolder when no rootDirectories is informed --- .../no-sync-mongo-methods-on-server.js | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/npm-packages/eslint-plugin-meteor/lib/rules/no-sync-mongo-methods-on-server/no-sync-mongo-methods-on-server.js b/npm-packages/eslint-plugin-meteor/lib/rules/no-sync-mongo-methods-on-server/no-sync-mongo-methods-on-server.js index 95891fa8d7f..fc5f5545f99 100644 --- a/npm-packages/eslint-plugin-meteor/lib/rules/no-sync-mongo-methods-on-server/no-sync-mongo-methods-on-server.js +++ b/npm-packages/eslint-plugin-meteor/lib/rules/no-sync-mongo-methods-on-server/no-sync-mongo-methods-on-server.js @@ -10,18 +10,21 @@ const { Walker } = require('./helpers'); const { debug } = require('../../util/utilities'); const INVALID_FUNCTIONS = { - findOne: { suggestion: 'findOneAsync' }, - insert: { suggestion: 'insertAsync' }, - update: { suggestion: 'updateAsync' }, - upsert: { suggestion: 'upsertAsync' }, - remove: { suggestion: 'removeAsync' }, + findOne: { suggestion: 'findOneAsync', isCollection: true }, + insert: { suggestion: 'insertAsync', isCollection: true }, + update: { suggestion: 'updateAsync', isCollection: true }, + upsert: { suggestion: 'upsertAsync', isCollection: true }, + remove: { suggestion: 'removeAsync', isCollection: true }, createIndex: { suggestion: 'createIndexAsync', + isCollection: true, skipForRawCollection: true, debug: true, }, - fetch: { suggestion: 'fetchAsync' }, - count: { suggestion: 'countAsync' }, // TODO we can go to the parent to check if it's also a call expression from a find function + fetch: { suggestion: 'fetchAsync', isCollection: true }, + count: { suggestion: 'countAsync', isCursor: true }, + map: { suggestion: 'mapAsync', isCursor: true }, + forEach: { suggestion: 'forEachAsync', isCursor: true }, // TODO we can go to the parent to check if it's also a call expression from a find function }; const INVALID_FUNCTIONS_NAMES = Object.keys(INVALID_FUNCTIONS); @@ -35,8 +38,10 @@ function hasRawCollectionInTheChain(node) { } function getInitFolder(context) { - return `${context.cwd}/${context.settings?.meteor?.rootDirectories?.[0]}` || - context.cwd; + const optionalRootDir = context.settings?.meteor?.rootDirectories?.[0]; + return ( + (optionalRootDir && `${context.cwd}/${optionalRootDir}`) || context.cwd + ); } module.exports = { @@ -94,15 +99,9 @@ module.exports = { !Object.keys(walker.cachedParsedFile).length || !(realPath in walker.cachedParsedFile) ) { - debug( - 'Skipping', - realPath, - context.physicalFilename, - walker.cachedParsedFile - ); + debug('Skipping', realPath); return; } - debug('Found a server file!!'); // CallExpression means it's a function call so we don't throw an error for example for a property called count in an object but we do throw when it's a count() function call. if ( node.property &&