diff --git a/lib/config-list.ts b/lib/config-list.ts
index 23a7ad4..bf8cabc 100644
--- a/lib/config-list.ts
+++ b/lib/config-list.ts
@@ -1,3 +1,4 @@
+import { EOL } from 'node:os';
import {
BEGIN_CONFIG_LIST_MARKER,
END_CONFIG_LIST_MARKER,
@@ -111,5 +112,5 @@ export function updateConfigsList(
ignoreConfig
);
- return `${preList}${BEGIN_CONFIG_LIST_MARKER}\n\n${list}\n\n${END_CONFIG_LIST_MARKER}${postList}`;
+ return `${preList}${BEGIN_CONFIG_LIST_MARKER}${EOL}${EOL}${list}${EOL}${EOL}${END_CONFIG_LIST_MARKER}${postList}`;
}
diff --git a/lib/generator.ts b/lib/generator.ts
index 1d633c5..75c9215 100644
--- a/lib/generator.ts
+++ b/lib/generator.ts
@@ -1,3 +1,4 @@
+import { EOL } from 'node:os';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { dirname, join, relative, resolve } from 'node:path';
import { getAllNamedOptions, hasOptions } from './rule-options.js';
@@ -168,16 +169,18 @@ export async function generate(path: string, options?: GenerateOptions) {
// The rule doc header will be added later.
let newRuleDocContents = [
ruleDocSectionInclude.length > 0
- ? ruleDocSectionInclude.map((title) => `## ${title}`).join('\n\n')
+ ? ruleDocSectionInclude
+ .map((title) => `## ${title}`)
+ .join(`${EOL}${EOL}`)
: undefined,
ruleHasOptions
- ? `## Options\n\n${BEGIN_RULE_OPTIONS_LIST_MARKER}\n${END_RULE_OPTIONS_LIST_MARKER}`
+ ? `## Options${EOL}${EOL}${BEGIN_RULE_OPTIONS_LIST_MARKER}${EOL}${END_RULE_OPTIONS_LIST_MARKER}`
: undefined,
]
.filter((section) => section !== undefined)
- .join('\n\n');
+ .join(`${EOL}${EOL}`);
if (newRuleDocContents !== '') {
- newRuleDocContents = `\n${newRuleDocContents}\n`;
+ newRuleDocContents = `${EOL}${newRuleDocContents}${EOL}`;
}
mkdirSync(dirname(pathToDoc), { recursive: true });
diff --git a/lib/markdown.ts b/lib/markdown.ts
index 3496a15..2a72cba 100644
--- a/lib/markdown.ts
+++ b/lib/markdown.ts
@@ -1,3 +1,5 @@
+import { EOL } from 'node:os';
+
// General helpers for dealing with markdown files / content.
/**
@@ -12,7 +14,7 @@ export function replaceOrCreateHeader(
newHeader: string,
marker: string
) {
- const lines = markdown.split('\n');
+ const lines = markdown.split(EOL);
const titleLineIndex = lines.findIndex((line) => line.startsWith('# '));
const markerLineIndex = lines.indexOf(marker);
@@ -22,16 +24,18 @@ export function replaceOrCreateHeader(
// Any YAML front matter or anything else above the title should be kept as-is ahead of the new header.
const preHeader = lines
.slice(0, Math.max(titleLineIndex, dashesLineIndex2 + 1))
- .join('\n');
+ .join(EOL);
// Anything after the marker comment, title, or YAML front matter should be kept as-is after the new header.
const postHeader = lines
.slice(
Math.max(markerLineIndex + 1, titleLineIndex + 1, dashesLineIndex2 + 1)
)
- .join('\n');
+ .join(EOL);
- return `${preHeader ? `${preHeader}\n` : ''}${newHeader}\n${postHeader}`;
+ return `${
+ preHeader ? `${preHeader}${EOL}` : ''
+ }${newHeader}${EOL}${postHeader}`;
}
/**
@@ -42,7 +46,7 @@ export function findSectionHeader(
str: string
): string | undefined {
// Get all the matching strings.
- const regexp = new RegExp(`## .*${str}.*\n`, 'giu');
+ const regexp = new RegExp(`## .*${str}.*${EOL}`, 'giu');
const sectionPotentialMatches = [...markdown.matchAll(regexp)].map(
(match) => match[0]
);
@@ -64,7 +68,7 @@ export function findSectionHeader(
}
export function findFinalHeaderLevel(str: string) {
- const lines = str.split('\n');
+ const lines = str.split(EOL);
const finalHeader = lines.reverse().find((line) => line.match('^(#+) .+$'));
return finalHeader ? finalHeader.indexOf(' ') : undefined;
}
diff --git a/lib/rule-doc-notices.ts b/lib/rule-doc-notices.ts
index b412d9e..fabf962 100644
--- a/lib/rule-doc-notices.ts
+++ b/lib/rule-doc-notices.ts
@@ -1,3 +1,4 @@
+import { EOL } from 'node:os';
import { END_RULE_HEADER_MARKER } from './comment-markers.js';
import {
EMOJI_DEPRECATED,
@@ -523,5 +524,5 @@ export function generateRuleHeaderLines(
),
'',
END_RULE_HEADER_MARKER,
- ].join('\n');
+ ].join(EOL);
}
diff --git a/lib/rule-list-legend.ts b/lib/rule-list-legend.ts
index 18619f9..6b11efa 100644
--- a/lib/rule-list-legend.ts
+++ b/lib/rule-list-legend.ts
@@ -1,3 +1,4 @@
+import { EOL } from 'node:os';
import {
EMOJI_DEPRECATED,
EMOJI_FIXABLE,
@@ -287,5 +288,5 @@ export function generateLegend(
);
}
- return legends.join('\\\n'); // Back slash ensures these end up displayed on separate lines.
+ return legends.join(`\\${EOL}`); // Back slash ensures these end up displayed on separate lines.
}
diff --git a/lib/rule-list.ts b/lib/rule-list.ts
index 9b5820e..5f9dccc 100644
--- a/lib/rule-list.ts
+++ b/lib/rule-list.ts
@@ -1,3 +1,4 @@
+import { EOL } from 'node:os';
import {
BEGIN_RULE_LIST_MARKER,
END_RULE_LIST_MARKER,
@@ -288,7 +289,7 @@ function generateRuleListMarkdownForRulesAndHeaders(
);
}
- return parts.join('\n\n');
+ return parts.join(`${EOL}${EOL}`);
}
/**
@@ -546,7 +547,7 @@ export function updateRulesList(
urlRuleDoc
);
- const newContent = `${legend ? `${legend}\n\n` : ''}${list}`;
+ const newContent = `${legend ? `${legend}${EOL}${EOL}` : ''}${list}`;
- return `${preList}${BEGIN_RULE_LIST_MARKER}\n\n${newContent}\n\n${END_RULE_LIST_MARKER}${postList}`;
+ return `${preList}${BEGIN_RULE_LIST_MARKER}${EOL}${EOL}${newContent}${EOL}${EOL}${END_RULE_LIST_MARKER}${postList}`;
}
diff --git a/lib/rule-options-list.ts b/lib/rule-options-list.ts
index eee4acf..4339f6c 100644
--- a/lib/rule-options-list.ts
+++ b/lib/rule-options-list.ts
@@ -1,3 +1,4 @@
+import { EOL } from 'node:os';
import {
BEGIN_RULE_OPTIONS_LIST_MARKER,
END_RULE_OPTIONS_LIST_MARKER,
@@ -159,5 +160,5 @@ export function updateRuleOptionsList(
// New rule options list.
const list = generateRuleOptionsListMarkdown(rule);
- return `${preList}${BEGIN_RULE_OPTIONS_LIST_MARKER}\n\n${list}\n\n${END_RULE_OPTIONS_LIST_MARKER}${postList}`;
+ return `${preList}${BEGIN_RULE_OPTIONS_LIST_MARKER}${EOL}${EOL}${list}${EOL}${EOL}${END_RULE_OPTIONS_LIST_MARKER}${postList}`;
}
diff --git a/lib/string.ts b/lib/string.ts
index 0fada49..6ae666e 100644
--- a/lib/string.ts
+++ b/lib/string.ts
@@ -1,3 +1,5 @@
+import { EOL } from 'node:os';
+
export function toSentenceCase(str: string) {
return str.replace(/^\w/u, function (txt) {
return txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase();
@@ -20,7 +22,7 @@ export function capitalizeOnlyFirstLetter(str: string) {
}
function sanitizeMarkdownTableCell(text: string): string {
- return text.replace(/\|/gu, '\\|').replace(/\n/gu, '
');
+ return text.replace(/\|/gu, '\\|').replace(new RegExp(EOL, 'gu'), '
');
}
export function sanitizeMarkdownTable(