mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 14:30:12 +01:00
Refactor to remove helpers.getPlatformIdentifier and simplify.
This commit is contained in:
parent
295e481552
commit
19dfb960f1
3 changed files with 27 additions and 68 deletions
|
|
@ -774,25 +774,14 @@ function emphasisMarkersInContent(params) {
|
|||
return byLine;
|
||||
}
|
||||
module.exports.emphasisMarkersInContent = emphasisMarkersInContent;
|
||||
/**
|
||||
* Gets the platform identifier from a string or process-like object.
|
||||
*
|
||||
* @param {string} platform Platform identifier (process.platform).
|
||||
* @param {Object} process Node.js process object.
|
||||
* @returns {string} Platform identifier.
|
||||
*/
|
||||
function getPlatformIdentifier(platform, process) {
|
||||
return (platform || (process && process.platform) || "unknown");
|
||||
}
|
||||
module.exports.getPlatformIdentifier = getPlatformIdentifier;
|
||||
/**
|
||||
* Gets the most common line ending, falling back to the platform default.
|
||||
*
|
||||
* @param {string} input Markdown content to analyze.
|
||||
* @param {string} [platform] Platform identifier (process.platform).
|
||||
* @param {Object} [process] Node.js process object.
|
||||
* @returns {string} Preferred line ending.
|
||||
*/
|
||||
function getPreferredLineEnding(input, platform) {
|
||||
function getPreferredLineEnding(input, process) {
|
||||
var cr = 0;
|
||||
var lf = 0;
|
||||
var crlf = 0;
|
||||
|
|
@ -814,10 +803,7 @@ function getPreferredLineEnding(input, platform) {
|
|||
var preferredLineEnding = null;
|
||||
if (!cr && !lf && !crlf) {
|
||||
preferredLineEnding =
|
||||
// eslint-disable-next-line node/prefer-global/process
|
||||
(getPlatformIdentifier(platform, __webpack_require__(/*! process */ "?4c74")) === "win32") ?
|
||||
"\r\n" :
|
||||
"\n";
|
||||
(process && (process.platform === "win32")) ? "\r\n" : "\n";
|
||||
}
|
||||
else if ((lf >= crlf) && (lf >= cr)) {
|
||||
preferredLineEnding = "\n";
|
||||
|
|
@ -869,11 +855,11 @@ module.exports.applyFix = applyFix;
|
|||
*
|
||||
* @param {string} input Lines of Markdown content.
|
||||
* @param {Object[]} errors RuleOnErrorInfo instances.
|
||||
* @param {string} [platform] Platform identifier (process.platform).
|
||||
* @returns {string} Corrected content.
|
||||
*/
|
||||
function applyFixes(input, errors, platform) {
|
||||
var lineEnding = getPreferredLineEnding(input, platform);
|
||||
function applyFixes(input, errors) {
|
||||
// eslint-disable-next-line node/prefer-global/process
|
||||
var lineEnding = getPreferredLineEnding(input, __webpack_require__(/*! process */ "?4c74"));
|
||||
var lines = input.split(newLineRe);
|
||||
// Normalize fixInfo objects
|
||||
var fixInfos = errors
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue