From 7127fbe97c5fe425e6ece7f74dbcfdb07719fc2e Mon Sep 17 00:00:00 2001 From: Marc G Date: Wed, 8 May 2024 03:54:21 +0200 Subject: [PATCH] code review 1 --- lib/augmentConfig.cjs | 7 ++++--- lib/augmentConfig.mjs | 7 ++++--- lib/utils/getCacheFile.cjs | 7 ++++--- lib/utils/getCacheFile.mjs | 7 ++++--- lib/utils/getFileIgnorer.cjs | 2 +- lib/utils/getFileIgnorer.mjs | 2 +- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/augmentConfig.cjs b/lib/augmentConfig.cjs index befdf927f5..042dbb7d71 100644 --- a/lib/augmentConfig.cjs +++ b/lib/augmentConfig.cjs @@ -152,7 +152,8 @@ function absolutizePaths(config, configDir, cwd) { config.ignoreFiles = [config.ignoreFiles].flat().map((glob) => absolutizeGlob(glob, configDir)); } - const cb = (/** @type { any } */ lookup) => { + /** @type {(lookup: T) => (string | T)} */ + const toAbsolutePath = (lookup) => { if (typeof lookup === 'string') { return getModulePath(configDir, lookup, cwd); } @@ -161,11 +162,11 @@ function absolutizePaths(config, configDir, cwd) { }; if (config.plugins) { - config.plugins = [config.plugins].flat().map(cb); + config.plugins = [config.plugins].flat().map(toAbsolutePath); } if (config.processors) { - config.processors = config.processors.map(cb); + config.processors = config.processors.map(toAbsolutePath); } return config; diff --git a/lib/augmentConfig.mjs b/lib/augmentConfig.mjs index f8ebce9ed1..2cfded9222 100644 --- a/lib/augmentConfig.mjs +++ b/lib/augmentConfig.mjs @@ -150,7 +150,8 @@ function absolutizePaths(config, configDir, cwd) { config.ignoreFiles = [config.ignoreFiles].flat().map((glob) => absolutizeGlob(glob, configDir)); } - const cb = (/** @type { any } */ lookup) => { + /** @type {(lookup: T) => (string | T)} */ + const toAbsolutePath = (lookup) => { if (typeof lookup === 'string') { return getModulePath(configDir, lookup, cwd); } @@ -159,11 +160,11 @@ function absolutizePaths(config, configDir, cwd) { }; if (config.plugins) { - config.plugins = [config.plugins].flat().map(cb); + config.plugins = [config.plugins].flat().map(toAbsolutePath); } if (config.processors) { - config.processors = config.processors.map(cb); + config.processors = config.processors.map(toAbsolutePath); } return config; diff --git a/lib/utils/getCacheFile.cjs b/lib/utils/getCacheFile.cjs index 469b3a8b85..7cf48b836b 100644 --- a/lib/utils/getCacheFile.cjs +++ b/lib/utils/getCacheFile.cjs @@ -36,9 +36,10 @@ function getCacheFile(cacheFile, cwd) { return node_path.join(resolvedCacheFile, `.stylelintcache_${hash(cwd)}`); } - const fileStats = node_fs.lstatSync(resolvedCacheFile, { throwIfNoEntry: false }); - - if (looksLikeADirectory || fileStats?.isDirectory()) { + if ( + looksLikeADirectory || + node_fs.lstatSync(resolvedCacheFile, { throwIfNoEntry: false })?.isDirectory() + ) { // Return path to provided directory with generated file name. return getCacheFileForDirectory(); } diff --git a/lib/utils/getCacheFile.mjs b/lib/utils/getCacheFile.mjs index 206da1b152..f01538e710 100644 --- a/lib/utils/getCacheFile.mjs +++ b/lib/utils/getCacheFile.mjs @@ -33,9 +33,10 @@ export default function getCacheFile(cacheFile, cwd) { return join(resolvedCacheFile, `.stylelintcache_${hash(cwd)}`); } - const fileStats = lstatSync(resolvedCacheFile, { throwIfNoEntry: false }); - - if (looksLikeADirectory || fileStats?.isDirectory()) { + if ( + looksLikeADirectory || + lstatSync(resolvedCacheFile, { throwIfNoEntry: false })?.isDirectory() + ) { // Return path to provided directory with generated file name. return getCacheFileForDirectory(); } diff --git a/lib/utils/getFileIgnorer.cjs b/lib/utils/getFileIgnorer.cjs index b7657b6420..4d03ae694c 100644 --- a/lib/utils/getFileIgnorer.cjs +++ b/lib/utils/getFileIgnorer.cjs @@ -32,7 +32,7 @@ function getFileIgnorer({ ignorePath, ignorePattern, cwd }) { // utf must remain lowercased to hit the fast path // see nodejs/node#49888 encoding: 'utf8', - flag: 'rs', + flag: 'r', }); ignorer.add(ignoreText); diff --git a/lib/utils/getFileIgnorer.mjs b/lib/utils/getFileIgnorer.mjs index 044f0db21f..34c09d27ec 100644 --- a/lib/utils/getFileIgnorer.mjs +++ b/lib/utils/getFileIgnorer.mjs @@ -29,7 +29,7 @@ export default function getFileIgnorer({ ignorePath, ignorePattern, cwd }) { // utf must remain lowercased to hit the fast path // see nodejs/node#49888 encoding: 'utf8', - flag: 'rs', + flag: 'r', }); ignorer.add(ignoreText);