Skip to content

Commit 0f07c36

Browse files
authored
refactor: replace dequal w/ stable-hash (#99)
1 parent ded3e80 commit 0f07c36

File tree

3 files changed

+13
-33
lines changed

3 files changed

+13
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@
5050
"dependencies": {
5151
"@typescript-eslint/utils": "^7.4.0",
5252
"debug": "^4.3.4",
53-
"dequal": "^2.0.3",
5453
"doctrine": "^3.0.0",
5554
"eslint-import-resolver-node": "^0.3.9",
5655
"get-tsconfig": "^4.7.3",
5756
"is-glob": "^4.0.3",
5857
"minimatch": "^9.0.3",
5958
"semver": "^7.6.0",
59+
"stable-hash": "^0.0.4",
6060
"tslib": "^2.6.2"
6161
},
6262
"devDependencies": {

src/utils/export-map.ts

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import path from 'node:path'
33

44
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
55
import debug from 'debug'
6-
import { dequal } from 'dequal'
76
import type { Annotation } from 'doctrine'
87
import doctrine from 'doctrine'
98
import type { AST } from 'eslint'
109
import { SourceCode } from 'eslint'
1110
import type { TsConfigJsonResolved } from 'get-tsconfig'
1211
import { getTsconfig } from 'get-tsconfig'
12+
import stableHash from 'stable-hash'
1313

1414
import type {
1515
ChildContext,
@@ -1103,44 +1103,19 @@ function childContext(
11031103
}
11041104
}
11051105

1106-
type OptionsVersionsCache = Record<
1107-
'settings' | 'parserOptions' | 'parser',
1108-
{ value: unknown; version: number }
1109-
>
1110-
1111-
const optionsVersionsCache: OptionsVersionsCache = {
1112-
settings: { value: null, version: 0 },
1113-
parserOptions: { value: null, version: 0 },
1114-
parser: { value: null, version: 0 },
1115-
}
1116-
1117-
function getOptionsVersion(key: keyof OptionsVersionsCache, value: unknown) {
1118-
const entry = optionsVersionsCache[key]
1119-
1120-
if (!dequal(value, entry.value)) {
1121-
entry.value = value
1122-
entry.version += 1
1123-
}
1124-
1125-
return String(entry.version)
1126-
}
1127-
11281106
function makeContextCacheKey(context: RuleContext | ChildContext) {
11291107
const { settings, parserPath, parserOptions, languageOptions } = context
11301108

1131-
let hash = getOptionsVersion('settings', settings)
1132-
1133-
const usedParserOptions = languageOptions?.parserOptions ?? parserOptions
1134-
1135-
hash += getOptionsVersion('parserOptions', usedParserOptions)
1109+
let hash =
1110+
stableHash(settings) +
1111+
stableHash(languageOptions?.parserOptions ?? parserOptions)
11361112

11371113
if (languageOptions) {
1138-
const { ecmaVersion, sourceType } = languageOptions
1139-
hash += String(ecmaVersion) + String(sourceType)
1114+
hash +=
1115+
String(languageOptions.ecmaVersion) + String(languageOptions.sourceType)
11401116
}
11411117

1142-
hash += getOptionsVersion(
1143-
'parser',
1118+
hash += stableHash(
11441119
parserPath ?? languageOptions?.parser?.meta ?? languageOptions?.parser,
11451120
)
11461121

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6156,6 +6156,11 @@ sprintf-js@~1.0.2:
61566156
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
61576157
integrity sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==
61586158

6159+
stable-hash@^0.0.4:
6160+
version "0.0.4"
6161+
resolved "https://registry.yarnpkg.com/stable-hash/-/stable-hash-0.0.4.tgz#55ae7dadc13e4b3faed13601587cec41859b42f7"
6162+
integrity sha512-LjdcbuBeLcdETCrPn9i8AYAZ1eCtu4ECAWtP7UleOiZ9LzVxRzzUZEoZ8zB24nhkQnDWyET0I+3sWokSDS3E7g==
6163+
61596164
stack-utils@^2.0.3:
61606165
version "2.0.6"
61616166
resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-2.0.6.tgz#aaf0748169c02fc33c8232abccf933f54a1cc34f"

0 commit comments

Comments
 (0)