GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — prettier/scripts/lint-changelog.js at main · prettier/prettier Expand file tree/ Copy pathlint-changelog.jsMore file actions 177 lines (159 loc) · 5.18 KB / Copy pathlint-changelog.jsFile metadata and controls177 lines (159 loc) · 5.18 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 #!/usr/bin/env node import assert from "node:assert/strict"; import fs from "node:fs"; import indexToPosition from "index-to-position"; import { fromMarkdown } from "mdast-util-from-markdown"; import { outdent } from "outdent"; import { CHANGELOG_CATEGORIES } from "./utilities/changelog.js"; const CHANGELOG_DIR = "changelog_unreleased"; const TEMPLATE_FILE = "TEMPLATE.md"; const BLOG_POST_INTRO_TEMPLATE_FILE = "BLOG_POST_INTRO_TEMPLATE.md"; const BLOG_POST_INTRO_FILE = "blog-post-intro.md"; const CHANGELOG_ROOT = new URL(`../${CHANGELOG_DIR}/`, import.meta.url); const showErrorMessage = (message) => { console.error(message); process.exitCode = 1; }; const files = fs.readdirSync(CHANGELOG_ROOT); for (const file of files) { if ( file !== TEMPLATE_FILE && file !== BLOG_POST_INTRO_FILE && file !== BLOG_POST_INTRO_TEMPLATE_FILE && !CHANGELOG_CATEGORIES.includes(file) ) { showErrorMessage(`Please remove "${file}" from "${CHANGELOG_DIR}".`); } } for (const file of [ TEMPLATE_FILE, BLOG_POST_INTRO_TEMPLATE_FILE, ...CHANGELOG_CATEGORIES, ]) { if (!files.includes(file)) { showErrorMessage(`Please don't remove "${file}" from "${CHANGELOG_DIR}".`); } } const authorRegex = /by @[\w-]+|by \[@([\w-]+)\]\(https:\/\/github\.com\/\1\)/; const titleRegex = /^#{4} (.*?)\((#\d{4,}|\[#\d{4,}\])/; const template = fs.readFileSync( new URL(TEMPLATE_FILE, CHANGELOG_ROOT), "utf8", ); const templateComments = template.match(/<!--.*?-->/gs); const [templateAuthorLink] = template.match(authorRegex); const checkedFiles = new Map(); for (const category of CHANGELOG_CATEGORIES) { const files = fs.readdirSync(new URL(`${category}/`, CHANGELOG_ROOT)); if (!files.includes(".gitkeep")) { showErrorMessage( `Please don't remove ".gitkeep" from "${CHANGELOG_DIR}/${category}".`, ); } for (const prFile of files) { if (prFile === ".gitkeep") { continue; } const match = prFile.match(/^(\d{4,})(-\d+)?\.md$/); const displayPath = `${CHANGELOG_DIR}/${category}/${prFile}`; if (!match) { showErrorMessage( `[${displayPath}]: Filename is not in form of "{PR_NUMBER}.md".`, ); continue; } const [, prNumber] = match; const prLink = `#${prNumber}`; if (checkedFiles.has(prFile)) { showErrorMessage( outdent` Duplicate files for ${prLink} found. - ${checkedFiles.get(prFile)} - ${displayPath} `, ); } checkedFiles.set(prFile, displayPath); const content = fs.readFileSync( new URL(`${category}/${prFile}`, CHANGELOG_ROOT), "utf8", ); if (!content.includes(prLink)) { showErrorMessage(`[${displayPath}]: PR link "${prLink}" is missing.`); } if (!authorRegex.test(content)) { showErrorMessage(`[${displayPath}]: Author link is missing.`); } for (const comment of templateComments) { if (comment !== "<!-- prettier-ignore -->" && content.includes(comment)) { showErrorMessage( `[${displayPath}]: Please remove ${getCommentDescription( content, comment, )}`, ); } } if (content.includes(templateAuthorLink)) { showErrorMessage( `[${displayPath}]: Please change author link to your github account.`, ); } if (!content.startsWith("#### ")) { showErrorMessage(`[${displayPath}]: Please use h4 ("####") for title.`); } const titleMatch = content.match(titleRegex); if (!titleMatch) { showErrorMessage( `[${displayPath}]: Invalid title format. Expected: "#### <title> (#12345 by @author)".`, ); continue; } const [, title] = titleMatch; validateTitle(displayPath, title); const categoryInTitle = title.split(":").shift().trim(); if ( [...CHANGELOG_CATEGORIES, "js"].includes(categoryInTitle.toLowerCase()) ) { showErrorMessage( `[${displayPath}]: Please remove "${categoryInTitle}:" in title.`, ); } if (!title.endsWith(" ") || title.length - title.trimEnd().length !== 1) { showErrorMessage( `[${displayPath}]: Please put one space between title and PR link.`, ); } if (/prettier master/i.test(content)) { showErrorMessage( `[${displayPath}]: Please use "main" instead of "master".`, ); } } } function getCommentDescription(content, comment) { const start = content.indexOf(comment); const end = start + comment.length; const [startLine, endLine] = [start, end].map( (index) => indexToPosition(content, index, { oneBased: true }).line, ); if (startLine === endLine) { return `template comment "${comment}" on line ${startLine}`; } return `template comment on line ${startLine}-${endLine}`; } // Forbid HTML in title // https://github.com/prettier/prettier/issues/17089 function validateTitle(displayPath, title) { const tree = fromMarkdown(title); assert.equal(tree.children.length, 1); assert.equal(tree.children[0].type, "paragraph"); const { children } = tree.children[0]; for (const node of children) { if (node.type === "html") { showErrorMessage( `[${displayPath}]: HTML "${node.value}" is restricted in title.`, ); } } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |