Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.5.3 - 2026-03-27

### Bug fixes

- Fix non-deterministic warning counts caused by two related bugs in the Walker:
1. The module-level `handledFiles` Set persisted across Walker instances, so when the file cache expired mid-run, re-walking produced an empty file list. Moved `handledFiles` into the Walker instance.
2. `shouldSkip()` created a new Walker on every call and depended solely on the disk cache, which could expire mid-run. Added an in-memory cache (`inMemoryCache` Map) that persists for the entire ESLint process, so `shouldSkip()` always sees the complete file list regardless of disk cache TTL.

## 1.5.2 - 2024-10-15

### Bug fixes
Expand Down
44 changes: 33 additions & 11 deletions lib/util/walker.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ function isNpmDependency(importPath) {
return !appFileImport.includes(importPath[0]);
}

const handledFiles = new Set();

function getAbsFilePath(filePath) {
// some files have no ext or are only the ext (.gitignore, .editorconfig, etc.)
const existingExt =
Expand All @@ -114,7 +112,7 @@ function getAbsFilePath(filePath) {
return filePath;
}

function handleFile(_filePath, appPath, onFile, cachedParsedFile) {
function handleFile(_filePath, appPath, onFile, cachedParsedFile, handledFiles) {
const filePath = getAbsFilePath(_filePath);
if (!filePath) {
return;
Expand Down Expand Up @@ -149,11 +147,11 @@ function handleFile(_filePath, appPath, onFile, cachedParsedFile) {
return path.resolve(path.dirname(filePath), source);
})
.forEach((importPath) => {
handleFile(importPath, appPath, onFile, cachedParsedFile);
handleFile(importPath, appPath, onFile, cachedParsedFile, handledFiles);
});
}

function handleFolder(folderPath, appPath, archList, onFile, cachedParsedFile) {
function handleFolder(folderPath, appPath, archList, onFile, cachedParsedFile, handledFiles) {
const dirents = fs.readdirSync(folderPath, { withFileTypes: true });
for (let i = 0; i < dirents.length; i += 1) {
if (dirents[i].isDirectory()) {
Expand All @@ -163,12 +161,13 @@ function handleFolder(folderPath, appPath, archList, onFile, cachedParsedFile) {
appPath,
archList,
onFile,
cachedParsedFile
cachedParsedFile,
handledFiles
);
}
} else if (dirents[i].isFile()) {
const filePath = path.resolve(folderPath, dirents[i].name);
handleFile(filePath, appPath, onFile, cachedParsedFile);
handleFile(filePath, appPath, onFile, cachedParsedFile, handledFiles);
}
}
}
Expand Down Expand Up @@ -203,15 +202,15 @@ function getInitFolder(context) {
}

function shouldSkip(context) {
const walker = new Walker(getInitFolder(context));
const appPath = getInitFolder(context);

const realPath = fs.realpathSync.native(context.physicalFilename);
const parsedFiles = process.env.METEOR_ESLINT_PLUGIN_FILES
? process.env.METEOR_ESLINT_PLUGIN_FILES.split(',').reduce(
(acc, item) => ({ ...acc, [item]: true }),
{},
)
: walker.cachedParsedFile;
: Walker.getParsedFiles(appPath);

if (!Object.keys(parsedFiles).length || !(realPath in parsedFiles)) {
debug('Skipping file', realPath);
Expand All @@ -235,17 +234,36 @@ const cacheExistsAndIsStillValid = (filePath) => {
return seconds <= EXPIRES_CACHE_IN_SECONDS;
}

// In-memory cache keyed by appPath. Survives the entire ESLint process so
// shouldSkip() never depends on the disk cache's TTL within a single run.
const inMemoryCache = new Map();

class Walker {
cachedParsedFile;
appPath;
handledFiles;

filePath() {
return path.join(this.appPath, '.eslint-meteor-files');
}

static getParsedFiles(appPath) {
if (inMemoryCache.has(appPath)) {
return inMemoryCache.get(appPath);
}
const walker = new Walker(appPath);
return walker.cachedParsedFile;
}

constructor(appPath) {
this.appPath = appPath;
this.handledFiles = new Set();

if (inMemoryCache.has(appPath)) {
this.cachedParsedFile = inMemoryCache.get(appPath);
return;
}

const useCache = cacheExistsAndIsStillValid(this.filePath());
if (!useCache) {
debug('Cache is not going to be used');
Expand All @@ -269,8 +287,10 @@ class Walker {
path.join(this.appPath, meteor.mainModule.server),
this.appPath,
onFile,
this.cachedParsedFile
this.cachedParsedFile,
this.handledFiles
);
inMemoryCache.set(this.appPath, this.cachedParsedFile);
fs.writeFileSync(this.filePath(), JSON.stringify(this.cachedParsedFile));
return;
}
Expand All @@ -282,9 +302,11 @@ class Walker {
this.appPath,
archList,
onFile,
this.cachedParsedFile
this.cachedParsedFile,
this.handledFiles
);

inMemoryCache.set(this.appPath, this.cachedParsedFile);
fs.writeFileSync(this.filePath(), JSON.stringify(this.cachedParsedFile));
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@quave/eslint-plugin-meteor-quave",
"version": "1.5.2",
"version": "1.5.3",
"description": "Quave linting rules for ESLint",
"main": "lib/index.js",
"scripts": {
Expand Down
Loading