Skip to content

Commit 7455994

Browse files
Fix no shadow issues in fingerprints.ts
Rename various instances of "hash", shadowing the function with that name.
1 parent ffe9468 commit 7455994

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/fingerprints.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function hash(callback: hashCallback, input: string) {
4646
const lineNumbers = Array(BLOCK_SIZE).fill(-1);
4747

4848
// The current hash value, updated as we read each character
49-
let hash = Long.ZERO;
49+
let hashRaw = Long.ZERO;
5050
const firstMod = computeFirstMod();
5151

5252
// The current index in the window, will wrap around to zero when we reach BLOCK_SIZE
@@ -63,7 +63,7 @@ export function hash(callback: hashCallback, input: string) {
6363

6464
// Output the current hash and line number to the callback function
6565
const outputHash = function () {
66-
const hashValue = hash.toUnsigned().toString(16);
66+
const hashValue = hashRaw.toUnsigned().toString(16);
6767
if (!hashCounts[hashValue]) {
6868
hashCounts[hashValue] = 0;
6969
}
@@ -76,7 +76,7 @@ export function hash(callback: hashCallback, input: string) {
7676
const updateHash = function (current: number) {
7777
const begin = window[index];
7878
window[index] = current;
79-
hash = MOD.multiply(hash)
79+
hashRaw = MOD.multiply(hashRaw)
8080
.add(Long.fromInt(current))
8181
.subtract(firstMod.multiply(Long.fromInt(begin)));
8282

@@ -138,7 +138,7 @@ function locationUpdateCallback(
138138
// using the hash of the first line of the file.
139139
locationStartLine = 1;
140140
}
141-
return function (lineNumber: number, hash: string) {
141+
return function (lineNumber: number, hashValue: string) {
142142
// Ignore hashes for lines that don't concern us
143143
if (locationStartLine !== lineNumber) {
144144
return;
@@ -153,10 +153,10 @@ function locationUpdateCallback(
153153
// If the hash doesn't match the existing fingerprint then
154154
// output a warning and don't overwrite it.
155155
if (!existingFingerprint) {
156-
result.partialFingerprints.primaryLocationLineHash = hash;
157-
} else if (existingFingerprint !== hash) {
156+
result.partialFingerprints.primaryLocationLineHash = hashValue;
157+
} else if (existingFingerprint !== hashValue) {
158158
logger.warning(
159-
`Calculated fingerprint of ${hash} for file ${location.physicalLocation.artifactLocation.uri} line ${lineNumber}, but found existing inconsistent fingerprint value ${existingFingerprint}`
159+
`Calculated fingerprint of ${hashValue} for file ${location.physicalLocation.artifactLocation.uri} line ${lineNumber}, but found existing inconsistent fingerprint value ${existingFingerprint}`
160160
);
161161
}
162162
};
@@ -279,9 +279,9 @@ export function addFingerprints(
279279
// Now hash each file that was found
280280
for (const [filepath, callbacks] of Object.entries(callbacksByFile)) {
281281
// A callback that forwards the hash to all other callbacks for that file
282-
const teeCallback = function (lineNumber: number, hash: string) {
282+
const teeCallback = function (lineNumber: number, hashValue: string) {
283283
for (const c of Object.values(callbacks)) {
284-
c(lineNumber, hash);
284+
c(lineNumber, hashValue);
285285
}
286286
};
287287
const fileContents = fs.readFileSync(filepath).toString();

0 commit comments

Comments
 (0)