Skip to content

Commit bed8bbf

Browse files
committed
changed default cache location
1 parent f2dc7f7 commit bed8bbf

File tree

14 files changed

+33
-18
lines changed

14 files changed

+33
-18
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,21 @@ additional-tests.sol
173173
Solhint supports a caching mechanism using the `--cache` flag to avoid re-linting files that haven't changed.
174174
When enabled, Solhint stores a hash of each file's content and effective configuration, skipping analysis if neither has changed.
175175
By default, the cache is saved in `.solhintcache.json` in the current working directory.
176-
You can customize this location using the `--cache-location option`.
176+
You can customize this location using the `--cache-location option`. If no location is specified, the file will be stored in:
177+
`node_modules/.cache/solhint/.solhint-cache.json`
178+
179+
Warning:
180+
When using `cache` flag. If a file was analyzed with not error for a certain config, the hash will be stored. If the file is not changed but the config file (`.solhint.json`) has some new rules, the file will not be analyzed.
181+
To analyze it again, remove `cache` option.
177182

178183
Example:
179184
```
180185
solhint contracts/**/*.sol --cache
181186
solhint Foo.sol --cache --cache-location tmp/my-cache.json
182187
```
183188

189+
190+
184191
### Extendable rulesets
185192

186193
The rulesets provided by solhint are the following:

e2e/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ describe('e2e general tests', function () {
282282
useFixture(PATH)
283283

284284
beforeEach(() => {
285-
cacheFilePath = path.join(shell.pwd().toString(), '.solhintcache.json')
285+
cacheFilePath = path.join('node_modules', '.cache', 'solhint', '.solhintcache.json')
286286
if (fs.existsSync(cacheFilePath)) fs.unlinkSync(cacheFilePath)
287287
})
288288

lib/cache/cache-manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const fs = require('fs')
1+
const fs = require('fs-extra')
22
const crypto = require('crypto')
33
const path = require('path')
44

lib/common/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const fs = require('fs')
1+
const fs = require('fs-extra')
22
const path = require('path')
33

44
const getLocFromIndex = (text, index) => {

lib/config/config-file.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const fs = require('fs')
1+
const fs = require('fs-extra')
22
const path = require('path')
33
const _ = require('lodash')
44
const { cosmiconfigSync } = require('cosmiconfig')

lib/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const fs = require('fs')
1+
const fs = require('fs-extra')
2+
const path = require('path')
23
const parser = require('@solidity-parser/parser')
34
const glob = require('glob')
45
const ignore = require('ignore')
@@ -84,9 +85,12 @@ function processFile(file, config, rootDir = process.cwd(), explicitConfigPath)
8485
const finalConfig =
8586
config !== undefined ? config : loadConfigForFile(file, rootDir, explicitConfigPath)
8687

88+
const defaultCachePath = path.join('node_modules', '.cache', 'solhint', '.solhintcache.json')
89+
const cachePath = finalConfig.cacheLocation || defaultCachePath
90+
8791
let cacheState = null
8892
if (finalConfig.cache) {
89-
const cacheData = readCache(finalConfig.cacheLocation || '.solhintcache.json')
93+
const cacheData = readCache(cachePath)
9094
cacheState = {
9195
cacheData,
9296
updatedCache: { ...cacheData },
@@ -96,7 +100,8 @@ function processFile(file, config, rootDir = process.cwd(), explicitConfigPath)
96100
const { report, updatedCache } = processAndCache(file, finalConfig, cacheState)
97101

98102
if (finalConfig.cache && updatedCache) {
99-
writeCache(finalConfig.cacheLocation || '.solhintcache.json', updatedCache)
103+
fs.ensureDirSync(path.dirname(cachePath)) // make sure the directory exists
104+
writeCache(cachePath, updatedCache)
100105
}
101106

102107
return report
@@ -109,7 +114,9 @@ function processPath(pattern, config, rootDir = process.cwd(), explicitConfigPat
109114
const files = ignoreFilter.filter(allFiles)
110115

111116
const useCache = config?.cache
112-
const cachePath = config?.cacheLocation || '.solhintcache.json'
117+
const defaultCachePath = path.join('node_modules', '.cache', 'solhint', '.solhintcache.json')
118+
const cachePath = config?.cacheLocation || defaultCachePath
119+
113120
const cacheData = useCache ? readCache(cachePath) : {}
114121
const updatedCache = { ...cacheData }
115122

@@ -128,6 +135,7 @@ function processPath(pattern, config, rootDir = process.cwd(), explicitConfigPat
128135
}
129136

130137
if (useCache) {
138+
fs.ensureDirSync(path.dirname(cachePath)) // make sure the directory exists
131139
writeCache(cachePath, updatedCache)
132140
}
133141

lib/rules/miscellaneous/import-path-check.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const fs = require('fs')
1+
const fs = require('fs-extra')
22
const path = require('path')
33
const BaseChecker = require('../base-checker')
44
const { severityDescription } = require('../../doc/utils')

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
"semver": "^7.5.2",
6161
"strip-ansi": "^6.0.1",
6262
"table": "^6.8.1",
63-
"text-table": "^0.2.0"
63+
"text-table": "^0.2.0",
64+
"fs-extra": "^11.1.0"
6465
},
6566
"devDependencies": {
6667
"assert": "^2.0.0",
@@ -71,7 +72,6 @@
7172
"eslint-config-prettier": "^8.6.0",
7273
"eslint-plugin-import": "^2.29.1",
7374
"eslint-plugin-prettier": "^4.2.1",
74-
"fs-extra": "^11.1.0",
7575
"get-stream": "^6.0.0",
7676
"markdown-table": "^2.0.0",
7777
"mocha": "^10.2.0",

scripts/generate-rule-docs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!env node
2-
const fs = require('fs')
2+
const fs = require('fs-extra')
33
const { exec, mkdir } = require('shelljs')
44
const semver = require('semver')
55
const path = require('path')

scripts/generate-rulesets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const fs = require('fs')
1+
const fs = require('fs-extra')
22

33
const { loadRules } = require('../lib/load-rules')
44

0 commit comments

Comments
 (0)