diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-06-08 17:25:10 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-06-08 17:25:25 -0300 |
commit | 77da50cb298a9e8072de9872c5c5090ab89c85c6 (patch) | |
tree | 608a9b4f4baa432956aa7f4de3bf60b1b78a41a9 | |
parent | 0d2fecadc06ff7413161d9d205605fb455f34913 (diff) |
find: report miscapitalizations preview
Man, this is overdue.
-rw-r--r-- | src/find.js | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/src/find.js b/src/find.js index e7f5cda1..e7471df9 100644 --- a/src/find.js +++ b/src/find.js @@ -56,11 +56,14 @@ export function processAvailableMatchesByName(data, { if (normalizedName in multipleNameMatches) { multipleNameMatches[normalizedName].push(thing); } else { - multipleNameMatches[normalizedName] = [results[normalizedName], thing]; + multipleNameMatches[normalizedName] = [ + results[normalizedName].thing, + thing, + ]; results[normalizedName] = null; } } else { - results[normalizedName] = thing; + results[normalizedName] = {thing, name}; } } } @@ -87,7 +90,7 @@ export function processAvailableMatchesByDirectory(data, { continue; } - results[directory] = thing; + results[directory] = {thing, directory}; } } @@ -117,13 +120,31 @@ function oopsMultipleNameMatches(mode, { `Returning null for this reference.`); } +function oopsNameCapitalizationMismatch(mode, { + matchingName, + matchedName, +}) { + return warnOrThrow(mode, + `Provided capitalization differs from the matched name. Please resolve:\n` + + `- provided: ${matchingName}\n` + + `- should be: ${matchedName}\n` + + `Returning null for this reference.`); +} + export function prepareMatchByName(mode, {byName, multipleNameMatches}) { return (name) => { const normalizedName = name.toLowerCase(); const match = byName[normalizedName]; if (match) { - return match; + if (name === match.name) { + return match.thing; + } else { + return oopsNameCapitalizationMismatch(mode, { + matchingName: name, + matchedName: match.name, + }); + } } else if (multipleNameMatches[normalizedName]) { return oopsMultipleNameMatches(mode, { name, @@ -154,7 +175,13 @@ export function prepareMatchByDirectory(mode, {referenceTypes, byDirectory}) { }); } - return byDirectory[directory]; + const match = byDirectory[directory]; + + if (match) { + return match.thing; + } else { + return null; + } }; } |