Skip to content

Commit a0fdcad

Browse files
committed
fix: remove prettier formatting of outputted markdown
1 parent 63252e4 commit a0fdcad

File tree

7 files changed

+78
-265
lines changed

7 files changed

+78
-265
lines changed

lib/generator.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,10 @@ export async function generate(
174174
);
175175

176176
const contents = readFileSync(pathToDoc).toString();
177-
const contentsNew = await replaceOrCreateHeader(
177+
const contentsNew = replaceOrCreateHeader(
178178
contents,
179179
newHeaderLines,
180-
END_RULE_HEADER_MARKER,
181-
pathToDoc
180+
END_RULE_HEADER_MARKER
182181
);
183182

184183
if (options?.check) {
@@ -230,7 +229,7 @@ export async function generate(
230229

231230
// Update the rules list in the README.
232231
const readmeContents = readFileSync(pathToReadme, 'utf8');
233-
const readmeContentsNew = await updateRulesList(
232+
const readmeContentsNew = updateRulesList(
234233
details,
235234
readmeContents,
236235
plugin,

lib/markdown.ts

+3-23
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,16 @@
11
// General helpers for dealing with markdown files / content.
22

3-
export async function format(str: string, filePath: string): Promise<string> {
4-
try {
5-
const { default: prettier } = await import('prettier');
6-
const options = await prettier.resolveConfig(filePath);
7-
return prettier
8-
.format(str, {
9-
...options,
10-
parser: 'markdown',
11-
})
12-
.trimEnd(); // Trim the ending newline that prettier may add.
13-
} catch {
14-
// Skip prettier formatting if not installed.
15-
/* istanbul ignore next -- TODO: Figure out how to test when prettier is not installed. */
16-
return str;
17-
}
18-
}
19-
203
/**
214
* Replace the header of a doc up to and including the specified marker.
225
* Insert at beginning if header doesn't exist.
236
* @param markdown - doc content
247
* @param newHeader - new header including marker
258
* @param marker - marker to indicate end of header
269
*/
27-
export async function replaceOrCreateHeader(
10+
export function replaceOrCreateHeader(
2811
markdown: string,
2912
newHeader: string,
30-
marker: string,
31-
pathToDoc: string
13+
marker: string
3214
) {
3315
const lines = markdown.split('\n');
3416

@@ -39,9 +21,7 @@ export async function replaceOrCreateHeader(
3921
lines.splice(0, 1);
4022
}
4123

42-
return `${await format(newHeader, pathToDoc)}\n${lines
43-
.slice(markerLineIndex + 1)
44-
.join('\n')}`;
24+
return `${newHeader}\n${lines.slice(markerLineIndex + 1).join('\n')}`;
4525
}
4626

4727
/**

lib/rule-list.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from './emojis.js';
88
import { getConfigsForRule } from './configs.js';
99
import { getColumns, COLUMN_HEADER } from './rule-list-columns.js';
10-
import { findSectionHeader, format } from './markdown.js';
10+
import { findSectionHeader } from './markdown.js';
1111
import { getPluginRoot } from './package-json.js';
1212
import { generateLegend } from './legend.js';
1313
import { relative } from 'node:path';
@@ -271,7 +271,7 @@ function generateRulesListMarkdownWithSplitBy(
271271
return parts.join('\n\n');
272272
}
273273

274-
export async function updateRulesList(
274+
export function updateRulesList(
275275
details: RuleDetails[],
276276
markdown: string,
277277
plugin: Plugin,
@@ -284,7 +284,7 @@ export async function updateRulesList(
284284
ruleListColumns: COLUMN_TYPE[],
285285
urlConfigs?: string,
286286
splitBy?: string
287-
): Promise<string> {
287+
): string {
288288
let listStartIndex = markdown.indexOf(BEGIN_RULE_LIST_MARKER);
289289
let listEndIndex = markdown.indexOf(END_RULE_LIST_MARKER);
290290

@@ -360,7 +360,7 @@ export async function updateRulesList(
360360
ignoreConfig
361361
);
362362

363-
const newContent = await format(`${legend}\n\n${list}`, pathToReadme);
363+
const newContent = `${legend ? `${legend}\n\n` : ''}${list}`;
364364

365365
return `${preList}${BEGIN_RULE_LIST_MARKER}\n\n${newContent}\n\n${END_RULE_LIST_MARKER}${postList}`;
366366
}

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"@types/jest": "^29.1.0",
5656
"@types/mock-fs": "^4.13.1",
5757
"@types/node": "^18.7.23",
58-
"@types/prettier": "^2.7.1",
5958
"@types/sinon": "^10.0.13",
6059
"@typescript-eslint/eslint-plugin": "^5.38.1",
6160
"@typescript-eslint/parser": "^5.38.1",
@@ -77,8 +76,7 @@
7776
"typescript": "^4.8.4"
7877
},
7978
"peerDependencies": {
80-
"eslint": ">= 7",
81-
"prettier": ">= 2"
79+
"eslint": ">= 7"
8280
},
8381
"engines": {
8482
"node": "^14.18.0 || ^16.0.0 || >=18.0.0"

0 commit comments

Comments
 (0)