mirror of
https://github.com/jamescliffordspratt/macros.git
synced 2026-07-22 05:46:53 +00:00
Add void to floating promises in large files; restore from corruption
This commit is contained in:
parent
8d1c5a345a
commit
1aa09381a0
5 changed files with 57 additions and 4 deletions
40
fixvoid.js
Normal file
40
fixvoid.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// One-off: prefix `void` to no-floating-promises in the 4 large files
|
||||
// that couldn't be edited remotely. Reads locations from lintreport.json.
|
||||
// Run from the repo root: node fixvoid.js
|
||||
const fs = require('fs');
|
||||
|
||||
const targets = [
|
||||
'MacrosCalcRenderer.ts',
|
||||
'StorageService.ts',
|
||||
'LiveSearchModal.ts',
|
||||
'ContextMenuManager.ts',
|
||||
];
|
||||
|
||||
const report = JSON.parse(fs.readFileSync('lintreport.json', 'utf8'));
|
||||
let n = 0;
|
||||
|
||||
for (const file of report) {
|
||||
if (!targets.some((t) => file.filePath.endsWith(t))) continue;
|
||||
|
||||
const lineNos = new Set(
|
||||
file.messages
|
||||
.filter((m) => m.ruleId === '@typescript-eslint/no-floating-promises')
|
||||
.map((m) => m.line)
|
||||
);
|
||||
if (lineNos.size === 0) continue;
|
||||
|
||||
const lines = fs.readFileSync(file.filePath, 'utf8').split('\n');
|
||||
for (const ln of lineNos) {
|
||||
const i = ln - 1;
|
||||
const s = lines[i];
|
||||
const stripped = s.replace(/^[ \t]*/, '');
|
||||
if (stripped.startsWith('void ')) continue; // idempotent
|
||||
const lead = s.slice(0, s.length - stripped.length);
|
||||
lines[i] = lead + 'void ' + stripped;
|
||||
n++;
|
||||
}
|
||||
fs.writeFileSync(file.filePath, lines.join('\n'));
|
||||
console.log('updated', file.filePath.split(/[\\/]/).pop());
|
||||
}
|
||||
|
||||
console.log('prefixed', n, 'statements');
|
||||
|
|
@ -1793,4 +1793,11 @@ export class MacrosCalcRenderer {
|
|||
this.chartLoader.destroyChart(caloriesChartId);
|
||||
}
|
||||
} catch (e) {
|
||||
this.plugin.logger.er
|
||||
this.plugin.logger.error('Error destroying chart:', e);
|
||||
}
|
||||
});
|
||||
|
||||
this.charts = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1987,4 +1987,7 @@ export class NutritionalSettingTab extends PluginSettingTab {
|
|||
this.previewChart.update();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error creating previ
|
||||
console.error('Error creating preview chart:', error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1872,4 +1872,3 @@ class FileNameModal extends Modal {
|
|||
this.contentEl.empty();
|
||||
}
|
||||
}
|
||||
| ||||