Skip to content

Commit 358d2dc

Browse files
committed
Remove outdated module export "run" and outdated "@ts-ignore"s, refactor to simplify.
1 parent 3c78c9f commit 358d2dc

File tree

1 file changed

+18
-32
lines changed

1 file changed

+18
-32
lines changed

markdownlint-cli2.js

+18-32
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ const negateGlob = (glob) => `!${glob}`;
5656
const throwForConfigurationFile = (file, error) => {
5757
throw new Error(
5858
`Unable to use configuration file '${file}'; ${error?.message}`,
59-
// @ts-ignore
6059
{ "cause": error }
6160
);
6261
};
@@ -115,7 +114,6 @@ const importOrRequireResolve = async (dirOrDirs, id, noRequire) => {
115114
} catch (error) {
116115
errors.push(error);
117116
}
118-
// @ts-ignore
119117
throw new AggregateError(
120118
errors,
121119
`Unable to require or import module '${id}'.`
@@ -778,13 +776,15 @@ const lintFiles = (fs, dirInfos, fileContents) => {
778776
const filteredFiles = filesAfterIgnores.filter(
779777
(file) => fileContents[file] === undefined
780778
);
779+
/** @type {Record<string, string>} */
781780
const filteredStrings = {};
782781
for (const file of filesAfterIgnores) {
783782
if (fileContents[file] !== undefined) {
784783
filteredStrings[file] = fileContents[file];
785784
}
786785
}
787786
// Create markdownlint options object
787+
/** @type {import("markdownlint").Options} */
788788
const options = {
789789
"files": filteredFiles,
790790
"strings": filteredStrings,
@@ -801,7 +801,6 @@ const lintFiles = (fs, dirInfos, fileContents) => {
801801
fs
802802
};
803803
// Invoke markdownlint
804-
// @ts-ignore
805804
let task = markdownlint(options);
806805
// For any fixable errors, read file, apply fixes, and write it back
807806
if (markdownlintOptions.fix) {
@@ -825,7 +824,6 @@ const lintFiles = (fs, dirInfos, fileContents) => {
825824
}
826825
}
827826
return Promise.all(subTasks).
828-
// @ts-ignore
829827
then(() => markdownlint(options)).
830828
then((fixResults) => ({
831829
...results,
@@ -1084,38 +1082,26 @@ const main = async (params) => {
10841082
return errorsPresent ? 1 : 0;
10851083
};
10861084

1087-
// Run function
1088-
const run = (overrides, args) => {
1089-
(async () => {
1090-
const argsAndArgv = args || [];
1091-
appendToArray(argsAndArgv, process.argv.slice(2));
1092-
try {
1093-
const defaultParams = {
1094-
"argv": argsAndArgv,
1095-
"logMessage": console.log,
1096-
"logError": console.error,
1097-
"allowStdin": true
1098-
};
1099-
const params = {
1100-
...defaultParams,
1101-
...overrides
1102-
};
1103-
process.exitCode = await main(params);
1104-
} catch (error) {
1105-
console.error(error);
1106-
process.exitCode = 2;
1107-
}
1108-
})();
1109-
};
1110-
11111085
// Export functions
11121086
module.exports = {
1113-
main,
1114-
run
1087+
main
11151088
};
11161089

11171090
// Run if invoked as a CLI
1118-
// @ts-ignore
11191091
if (require.main === module) {
1120-
run();
1092+
const params = {
1093+
"argv": process.argv.slice(2),
1094+
"logMessage": console.log,
1095+
"logError": console.error,
1096+
"allowStdin": true
1097+
};
1098+
main(params).
1099+
then((exitCode) => {
1100+
process.exitCode = exitCode;
1101+
}).
1102+
// eslint-disable-next-line unicorn/prefer-top-level-await
1103+
catch((error) => {
1104+
console.error(error);
1105+
process.exitCode = 2;
1106+
});
11211107
}

0 commit comments

Comments
 (0)