Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
const editor = vscode.window.activeTextEditor;
if (editor) {
const document = editor.document;
if (isMarkdownDocument(document)) {
const name = document.uri.toString();
const text = document.getText();
const {config} = getConfig(document);
const errors = markdownlintWrapper(name, text, config);
const fixedText = markdownlintRuleHelpers.applyFixes(text, errors);
if (text !== fixedText) {
return editor.edit((editBuilder) => {
const start = document.lineAt(0).range.start;
const end = document.lineAt(document.lineCount - 1).range.end;
editBuilder.replace(new vscode.Range(start, end), fixedText);
}).then(resolve, reject);
}
}
}
return resolve();
});
}
files.forEach(file => {
fixOptions.files = [file];
const fixResult = markdownlint.sync(fixOptions);
const fixes = fixResult[file].filter(error => error.fixInfo);
if (fixes.length > 0) {
const originalText = fs.readFileSync(file, fsOptions);
const fixedText = markdownlintRuleHelpers.applyFixes(originalText, fixes);
if (originalText !== fixedText) {
fs.writeFileSync(file, fixedText, fsOptions);
}
}
});
}