Add changelog lint script (#7320)
* Add changelog lint script * Refactor lint script * spell * Fix indent * fix templateComment * add H4 check * Add category in title check * use array destructuring * Add space check
This commit is contained in:
1 parent
61b0fd003b
commit
da8d082ce0
17 files changed
+146
-11
No files matched your search
@@ -11,3 +11,5 @@ steps:
|
||||
displayName: "Lint docs"
|
||||
- script: yarn spellcheck
|
||||
displayName: "Spellcheck"
|
||||
- script: yarn lint-changelog
|
||||
displayName: "Lint changelog"
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Support file extensions `.cjs` and `.yaml.sed`([#7210](https://github.com/prettier/prettier/pull/7210) by [@sosukesuzuki](https://github.com/sosukesuzuki))
|
||||
#### Support file extensions `.cjs` and `.yaml.sed` ([#7210](https://github.com/prettier/prettier/pull/7210) by [@sosukesuzuki](https://github.com/sosukesuzuki))
|
||||
|
||||
```sh
|
||||
# Prettier stable
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### handlebars: Fix superfluous line breaks in ConcatStatement ([7051](https://github.com/prettier/prettier/pull/7051) by [@dcyriller](https://github.com/dcyriller))
|
||||
#### Fix superfluous line breaks in ConcatStatement ([#7051](https://github.com/prettier/prettier/pull/7051) by [@dcyriller](https://github.com/dcyriller))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```hbs
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### handlebars: Improve MustacheStatement printing ([#7157](https://github.com/prettier/prettier/pull/7157) by [@dcyriller](https://github.com/dcyriller))
|
||||
#### Improve MustacheStatement printing ([#7157](https://github.com/prettier/prettier/pull/7157) by [@dcyriller](https://github.com/dcyriller))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```hbs
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Fix formatting of labeled statements with comments ([#6994](https://github.com/prettier/prettier/pull/6984) by [@clement26695](https://github.com/clement26695))
|
||||
#### Fix formatting of labeled statements with comments ([#6984](https://github.com/prettier/prettier/pull/6984) by [@clement26695](https://github.com/clement26695))
|
||||
|
||||
Formatting of comments in labeled statements was not stable
|
||||
|
||||
|
||||
File renamed without changes.
@@ -1,4 +1,4 @@
|
||||
# Format `throw` like `return` ([#7070](https://github.com/prettier/prettier/pull/7070) by [@sosukesuzuki](https://github.com/sosukesuzuki))
|
||||
#### Format `throw` like `return` ([#7070](https://github.com/prettier/prettier/pull/7070) by [@sosukesuzuki](https://github.com/sosukesuzuki))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Fix moving semi for `return` to end of line-comment([#7140](https://github.com/prettier/prettier/pull/7140) by [@sosukesuzuki](https://github.com/sosukesuzuki))
|
||||
#### Fix moving semi for `return` to end of line-comment ([#7140](https://github.com/prettier/prettier/pull/7140) by [@sosukesuzuki](https://github.com/sosukesuzuki))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### MDX: fix JSX Fragment format incorrectly ([#6398](https://github.com/prettier/prettier/pull/6398) by [@JounQin](https://github.com/JounQin))
|
||||
#### Fix JSX Fragment format incorrectly ([#6398](https://github.com/prettier/prettier/pull/6398) by [@JounQin](https://github.com/JounQin))
|
||||
|
||||
Previous versions format JSX Fragment incorrectly in mdx, this has been fixed in this version.
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Don't print trailing commas after rest elements in tuples ([#7075](https://github.com/prettier/prettier/pull/7075) by [@thorn](https://github.com/thorn0))
|
||||
#### Don't print trailing commas after rest elements in tuples ([#7075](https://github.com/prettier/prettier/pull/7075) by [@thorn0](https://github.com/thorn0))
|
||||
|
||||
- A rest element is always the last element of a tuple type. Nothing can be added after it.
|
||||
- While TS is okay with this comma, [Babel doesn't parse it](https://github.com/babel/babel/issues/10769)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Remove extra indentation for arrow function on variable declaration with comment([#7094](https://github.com/prettier/prettier/pull/7094) by [@sosukesuzuki](https://github.com/sosukesuzuki))
|
||||
#### Remove extra indentation for arrow function on variable declaration with comment ([#7094](https://github.com/prettier/prettier/pull/7094) by [@sosukesuzuki](https://github.com/sosukesuzuki))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```ts
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#### Fix formatting comments for function-like nodes ([#6901](https://github.com/prettier/prettier/pull/7144) by [@armano2](https://github.com/armano2))
|
||||
#### Fix formatting comments for function-like nodes ([#7144](https://github.com/prettier/prettier/pull/7144) by [@armano2](https://github.com/armano2))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```ts
|
||||
|
||||
File renamed without changes.
@@ -1,4 +1,4 @@
|
||||
#### format vue SFC containing JSX script([#7180](https://github.com/prettier/prettier/pull/7180) by [@sosukesuzuki](https://github.com/sosukesuzuki))
|
||||
#### format vue SFC containing JSX script ([#7180](https://github.com/prettier/prettier/pull/7180) by [@sosukesuzuki](https://github.com/sosukesuzuki))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```html
|
||||
|
||||
@@ -122,6 +122,7 @@
|
||||
"gitattributes",
|
||||
"githook",
|
||||
"gitignore",
|
||||
"gitkeep",
|
||||
"Gitter",
|
||||
"glimmerjs",
|
||||
"globbing",
|
||||
|
||||
@@ -122,6 +122,7 @@
|
||||
"perf-benchmark": "yarn && yarn build && cross-env NODE_ENV=production node ./dist/bin-prettier.js --debug-benchmark --loglevel debug ${PERF_FILE:-./index.js} > /dev/null",
|
||||
"check-types": "tsc",
|
||||
"lint": "cross-env EFF_NO_LINK_RULES=true eslint . --format friendly",
|
||||
"lint-changelog": "node ./scripts/lint-changelog.js",
|
||||
"lint-docs": "prettier {.,docs,website,website/blog,changelog_unreleased,changelog_unreleased/*}/*.md --check",
|
||||
"lint-dist": "eslint --no-eslintrc --no-ignore --env=browser \"dist/!(bin-prettier|index|third-party).js\"",
|
||||
"build": "node --max-old-space-size=3072 ./scripts/build/build.js",
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
"use strict";
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const CHANGELOG_DIR = "changelog_unreleased";
|
||||
const TEMPLATE_FILE = "TEMPLATE.md";
|
||||
const CHANGELOG_CATEGORIES = [
|
||||
"angular",
|
||||
"api",
|
||||
"cli",
|
||||
"css",
|
||||
"flow",
|
||||
"graphql",
|
||||
"handlebars",
|
||||
"html",
|
||||
"javascript",
|
||||
"json",
|
||||
"less",
|
||||
"lwc",
|
||||
"markdown",
|
||||
"mdx",
|
||||
"scss",
|
||||
"typescript",
|
||||
"vue",
|
||||
"yaml"
|
||||
];
|
||||
const CHANGELOG_ROOT = path.join(__dirname, `../${CHANGELOG_DIR}`);
|
||||
const showErrorMessage = message => {
|
||||
console.error(message);
|
||||
process.exitCode = 1;
|
||||
};
|
||||
|
||||
const files = fs.readdirSync(CHANGELOG_ROOT);
|
||||
for (const file of files) {
|
||||
if (file !== TEMPLATE_FILE && !CHANGELOG_CATEGORIES.includes(file)) {
|
||||
showErrorMessage(`Please remove "${file}" from "${CHANGELOG_DIR}".`);
|
||||
}
|
||||
}
|
||||
for (const file of [TEMPLATE_FILE, ...CHANGELOG_CATEGORIES]) {
|
||||
if (!files.includes(file)) {
|
||||
showErrorMessage(`Please don't remove "${file}" from "${CHANGELOG_DIR}".`);
|
||||
}
|
||||
}
|
||||
|
||||
const authorRegex = /by \[@(.*?)\]\(https:\/\/github\.com\/\1\)/;
|
||||
const titleRegex = /^#{4} (.*?)\(\[#\d{4,}]/;
|
||||
|
||||
const template = fs.readFileSync(
|
||||
path.join(CHANGELOG_ROOT, TEMPLATE_FILE),
|
||||
"utf8"
|
||||
);
|
||||
const [templateComment] = template.match(/<!--[\s\S]*?-->/);
|
||||
const [templateAuthorLink] = template.match(authorRegex);
|
||||
|
||||
for (const category of CHANGELOG_CATEGORIES) {
|
||||
const files = fs.readdirSync(path.join(CHANGELOG_ROOT, category));
|
||||
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(/^pr-(\d{4,})\.md$/);
|
||||
const displayPath = `${CHANGELOG_DIR}/${category}/${prFile}`;
|
||||
|
||||
if (!match) {
|
||||
showErrorMessage(
|
||||
`[${displayPath}]: Filename is not in form of "pr-{PR_NUMBER}.md".`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
const [, prNumber] = match;
|
||||
const content = fs.readFileSync(
|
||||
path.join(CHANGELOG_DIR, category, prFile),
|
||||
"utf8"
|
||||
);
|
||||
const prLink = `[#${prNumber}](https://github.com/prettier/prettier/pull/${prNumber})`;
|
||||
|
||||
if (!content.includes(prLink)) {
|
||||
showErrorMessage(`[${displayPath}]: PR link "${prLink}" is missing.`);
|
||||
}
|
||||
if (!authorRegex.test(content)) {
|
||||
showErrorMessage(`[${displayPath}]: Author link is missing.`);
|
||||
}
|
||||
if (content.includes(templateComment)) {
|
||||
showErrorMessage(
|
||||
`[${displayPath}]: Please remove template comments at top.`
|
||||
);
|
||||
}
|
||||
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}]: Something wrong in title.`);
|
||||
continue;
|
||||
}
|
||||
const [, title] = titleMatch;
|
||||
const categoryInTitle = title
|
||||
.split(":")
|
||||
.shift()
|
||||
.trim();
|
||||
if (CHANGELOG_CATEGORIES.includes(categoryInTitle.toLowerCase())) {
|
||||
showErrorMessage(
|
||||
`[${displayPath}]: Please remove "${categoryInTitle}:" in title.`
|
||||
);
|
||||
}
|
||||
|
||||
if (title.startsWith(" ")) {
|
||||
showErrorMessage(
|
||||
`[${displayPath}]: Don't add extra space(s) at beginning of title.`
|
||||
);
|
||||
}
|
||||
|
||||
if (!title.endsWith(" ") || title.length - title.trimEnd().length !== 1) {
|
||||
showErrorMessage(
|
||||
`[${displayPath}]: Please put one space between title and PR link.`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user