Skip to content

Commit

Permalink
Remove outdated module export "run" and outdated "@ts-ignore"s, refac…
Browse files Browse the repository at this point in the history
…tor to simplify.
  • Loading branch information
DavidAnson committed Nov 8, 2024
1 parent 3c78c9f commit 358d2dc
Showing 1 changed file with 18 additions and 32 deletions.
50 changes: 18 additions & 32 deletions markdownlint-cli2.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const negateGlob = (glob) => `!${glob}`;
const throwForConfigurationFile = (file, error) => {
throw new Error(
`Unable to use configuration file '${file}'; ${error?.message}`,
// @ts-ignore
{ "cause": error }
);
};
Expand Down Expand Up @@ -115,7 +114,6 @@ const importOrRequireResolve = async (dirOrDirs, id, noRequire) => {
} catch (error) {
errors.push(error);
}
// @ts-ignore
throw new AggregateError(
errors,
`Unable to require or import module '${id}'.`
Expand Down Expand Up @@ -778,13 +776,15 @@ const lintFiles = (fs, dirInfos, fileContents) => {
const filteredFiles = filesAfterIgnores.filter(
(file) => fileContents[file] === undefined
);
/** @type {Record<string, string>} */
const filteredStrings = {};
for (const file of filesAfterIgnores) {
if (fileContents[file] !== undefined) {
filteredStrings[file] = fileContents[file];
}
}
// Create markdownlint options object
/** @type {import("markdownlint").Options} */
const options = {
"files": filteredFiles,
"strings": filteredStrings,
Expand All @@ -801,7 +801,6 @@ const lintFiles = (fs, dirInfos, fileContents) => {
fs
};
// Invoke markdownlint
// @ts-ignore
let task = markdownlint(options);
// For any fixable errors, read file, apply fixes, and write it back
if (markdownlintOptions.fix) {
Expand All @@ -825,7 +824,6 @@ const lintFiles = (fs, dirInfos, fileContents) => {
}
}
return Promise.all(subTasks).
// @ts-ignore
then(() => markdownlint(options)).
then((fixResults) => ({
...results,
Expand Down Expand Up @@ -1084,38 +1082,26 @@ const main = async (params) => {
return errorsPresent ? 1 : 0;
};

// Run function
const run = (overrides, args) => {
(async () => {
const argsAndArgv = args || [];
appendToArray(argsAndArgv, process.argv.slice(2));
try {
const defaultParams = {
"argv": argsAndArgv,
"logMessage": console.log,
"logError": console.error,
"allowStdin": true
};
const params = {
...defaultParams,
...overrides
};
process.exitCode = await main(params);
} catch (error) {
console.error(error);
process.exitCode = 2;
}
})();
};

// Export functions
module.exports = {
main,
run
main
};

// Run if invoked as a CLI
// @ts-ignore
if (require.main === module) {
run();
const params = {
"argv": process.argv.slice(2),
"logMessage": console.log,
"logError": console.error,
"allowStdin": true
};
main(params).
then((exitCode) => {
process.exitCode = exitCode;
}).
// eslint-disable-next-line unicorn/prefer-top-level-await
catch((error) => {
console.error(error);
process.exitCode = 2;
});
}

0 comments on commit 358d2dc

Please sign in to comment.