eslint-doc-generator
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -8,3 +8,3 @@ import { existsSync, readFileSync, writeFileSync } from 'node:fs'; | ||
import { END_RULE_HEADER_MARKER } from './markers.js'; | ||
import { findSectionHeader, format, replaceOrCreateHeader, } from './markdown.js'; | ||
import { findSectionHeader, replaceOrCreateHeader } from './markdown.js'; | ||
/** | ||
@@ -62,8 +62,7 @@ * Ensure a rule doc contains (or doesn't contain) some particular content. | ||
} | ||
const contents = readFileSync(pathToDoc).toString(); | ||
const lines = contents.split('\n'); | ||
// Regenerate the header (title/notices) of each rule doc. | ||
const newHeaderLines = generateRuleHeaderLines(description, name, plugin, pluginPrefix); | ||
replaceOrCreateHeader(lines, newHeaderLines, END_RULE_HEADER_MARKER); | ||
writeFileSync(pathToDoc, await format(lines.join('\n'), pathToDoc)); | ||
const contents = readFileSync(pathToDoc).toString(); | ||
const contentsNew = await replaceOrCreateHeader(contents, newHeaderLines, END_RULE_HEADER_MARKER, pathToDoc); | ||
writeFileSync(pathToDoc, contentsNew); | ||
// Check for potential issues with the rule doc. | ||
@@ -77,5 +76,4 @@ // Options section. | ||
// Update the rules list in the README. | ||
let readme = readFileSync(pathTo.readme, 'utf8'); | ||
readme = updateRulesList(details, readme, plugin, pluginPrefix); | ||
writeFileSync(pathTo.readme, await format(readme, pathTo.readme), 'utf8'); | ||
const readme = await updateRulesList(details, readFileSync(pathTo.readme, 'utf8'), plugin, pluginPrefix, pathTo.readme); | ||
writeFileSync(pathTo.readme, readme, 'utf8'); | ||
} |
@@ -5,7 +5,7 @@ export declare function format(str: string, filePath: string): Promise<string>; | ||
* Insert at beginning if header doesn't exist. | ||
* @param lines - lines of doc | ||
* @param newHeaderLines - lines of new header including marker | ||
* @param markdown - doc content | ||
* @param newHeader - new header including marker | ||
* @param marker - marker to indicate end of header | ||
*/ | ||
export declare function replaceOrCreateHeader(lines: string[], newHeaderLines: string[], marker: string): void; | ||
export declare function replaceOrCreateHeader(markdown: string, newHeader: string, marker: string, pathToDoc: string): Promise<string>; | ||
/** | ||
@@ -12,0 +12,0 @@ * Find the section most likely to be the top-level section for a given string. |
@@ -13,7 +13,8 @@ // General helpers for dealing with markdown files / content. | ||
* Insert at beginning if header doesn't exist. | ||
* @param lines - lines of doc | ||
* @param newHeaderLines - lines of new header including marker | ||
* @param markdown - doc content | ||
* @param newHeader - new header including marker | ||
* @param marker - marker to indicate end of header | ||
*/ | ||
export function replaceOrCreateHeader(lines, newHeaderLines, marker) { | ||
export async function replaceOrCreateHeader(markdown, newHeader, marker, pathToDoc) { | ||
const lines = markdown.split('\n'); | ||
const markerLineIndex = lines.indexOf(marker); | ||
@@ -24,4 +25,4 @@ if (markerLineIndex === -1 && lines.length > 0 && lines[0].startsWith('# ')) { | ||
} | ||
// Replace header section (or create at top if missing). | ||
lines.splice(0, markerLineIndex + 1, ...newHeaderLines); | ||
return ((await format(newHeader, pathToDoc)) + | ||
lines.slice(markerLineIndex + 1).join('\n')); | ||
} | ||
@@ -28,0 +29,0 @@ /** |
import type { Plugin, RuleDetails } from './types.js'; | ||
export declare function updateRulesList(details: RuleDetails[], markdown: string, plugin: Plugin, pluginPrefix: string): string; | ||
export declare function updateRulesList(details: RuleDetails[], markdown: string, plugin: Plugin, pluginPrefix: string, pathToReadme: string): Promise<string>; |
import { BEGIN_RULE_LIST_MARKER, END_RULE_LIST_MARKER } from './markers.js'; | ||
import { EMOJI_CONFIG_RECOMMENDED, EMOJI_DEPRECATED, EMOJI_FIXABLE, EMOJI_HAS_SUGGESTIONS, EMOJI_REQUIRES_TYPE_CHECKING, EMOJI_CONFIGS, } from './emojis.js'; | ||
import { hasCustomConfigs } from './configs.js'; | ||
import { findSectionHeader } from './markdown.js'; | ||
import { findSectionHeader, format } from './markdown.js'; | ||
function getConfigurationColumnValueForRule(rule, plugin, pluginPrefix) { | ||
@@ -63,3 +63,3 @@ const badges = []; | ||
} | ||
export function updateRulesList(details, markdown, plugin, pluginPrefix) { | ||
export async function updateRulesList(details, markdown, plugin, pluginPrefix, pathToReadme) { | ||
let listStartIndex = markdown.indexOf(BEGIN_RULE_LIST_MARKER); | ||
@@ -78,3 +78,3 @@ let listEndIndex = markdown.indexOf(END_RULE_LIST_MARKER); | ||
listStartIndex = rulesSectionIndex + rulesSectionHeader.length; | ||
listEndIndex = rulesSectionIndex + rulesSectionHeader.length; | ||
listEndIndex = rulesSectionIndex + rulesSectionHeader.length - 1; | ||
} | ||
@@ -88,16 +88,7 @@ else { | ||
} | ||
return [ | ||
// Doc before rule list marker. | ||
markdown.slice(0, Math.max(0, listStartIndex - 1)), | ||
// New begin marker. | ||
BEGIN_RULE_LIST_MARKER, | ||
'', | ||
// New rule list. | ||
generateRulesListMarkdown(details, plugin, pluginPrefix), | ||
'', | ||
// New end marker. | ||
END_RULE_LIST_MARKER, | ||
// Doc after rule list marker. | ||
markdown.slice(Math.max(0, listEndIndex)), | ||
].join('\n'); | ||
const preList = markdown.slice(0, Math.max(0, listStartIndex)); | ||
const postList = markdown.slice(Math.max(0, listEndIndex)); | ||
// New rule list. | ||
const list = await format(generateRulesListMarkdown(details, plugin, pluginPrefix), pathToReadme); | ||
return `${preList}${BEGIN_RULE_LIST_MARKER}\n\n${list}\n${END_RULE_LIST_MARKER}${postList}`; | ||
} |
@@ -6,4 +6,4 @@ import type { Plugin } from './types.js'; | ||
* @param name - rule name | ||
* @returns {string[]} - lines for new header including marker | ||
* @returns {string} - new header including marker | ||
*/ | ||
export declare function generateRuleHeaderLines(description: string, name: string, plugin: Plugin, pluginPrefix: string): string[]; | ||
export declare function generateRuleHeaderLines(description: string, name: string, plugin: Plugin, pluginPrefix: string): string; |
@@ -87,3 +87,3 @@ import { END_RULE_HEADER_MARKER } from './markers.js'; | ||
* @param name - rule name | ||
* @returns {string[]} - lines for new header including marker | ||
* @returns {string} - new header including marker | ||
*/ | ||
@@ -96,3 +96,3 @@ export function generateRuleHeaderLines(description, name, plugin, pluginPrefix) { | ||
END_RULE_HEADER_MARKER, | ||
]; | ||
].join('\n'); | ||
} |
{ | ||
"name": "eslint-doc-generator", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Automatic documentation generator for ESLint plugins and rules.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30809
534