Skip to content

Commit

Permalink
code review 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Mouvedia committed May 8, 2024
1 parent 83ecf67 commit 1802eed
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
7 changes: 4 additions & 3 deletions lib/augmentConfig.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {<T>(lookup: T) => (string | T)} */
const toAbsolutePath = (lookup) => {
if (typeof lookup === 'string') {
return getModulePath(configDir, lookup, cwd);
}
Expand All @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions lib/augmentConfig.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {<T>(lookup: T) => (string | T)} */
const toAbsolutePath = (lookup) => {
if (typeof lookup === 'string') {
return getModulePath(configDir, lookup, cwd);
}
Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions lib/utils/getCacheFile.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ 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();
}
Expand Down
7 changes: 4 additions & 3 deletions lib/utils/getCacheFile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/getFileIgnorer.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/getFileIgnorer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1802eed

Please sign in to comment.