From 8ccf997b7eee0c9637d72dc863ec0f7d882c7b16 Mon Sep 17 00:00:00 2001 From: Anduin Xue Date: Sat, 12 Mar 2022 14:42:14 +0800 Subject: [PATCH] Better lint js. --- .github/manual_lint.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/manual_lint.js b/.github/manual_lint.js index fcf057f..5fb5683 100644 --- a/.github/manual_lint.js +++ b/.github/manual_lint.js @@ -7,6 +7,7 @@ const glob = require("glob"); const fs = require("fs"); var path = require('path'); +var errors = 0; var getDirectories = function (src, callback) { glob(src + '../../dishes/**/*.md', callback); @@ -29,28 +30,34 @@ getDirectories(__dirname, function (err, res) { if (titles[0].trim() != "# " + filename + "的做法") { console.error(`File ${filePath} is invalid! It's title should be: ${"# " + filename + "的做法"}! It was ${titles[0].trim()}!`); + errors++; return; } if (secondTitles.length != 4) { console.error(`File ${filePath} is invalid! It doesn't has 4 second titles!`); + errors++; return; } if (secondTitles[0].trim() != "## 必备原料和工具") { console.error(`File ${filePath} is invalid! The first title is NOT 必备原料和工具! It was ${secondTitles[0]}!`); - return; + errors++; } if (secondTitles[1].trim() != "## 计算") { console.error(`File ${filePath} is invalid! The second title is NOT 计算!`); - return; + errors++; } if (secondTitles[2].trim() != "## 操作") { console.error(`File ${filePath} is invalid! The thrid title is NOT 操作!`); - return; + errors++; } if (secondTitles[3].trim() != "## 附加内容") { console.error(`File ${filePath} is invalid! The fourth title is NOT 附加内容!`); - return; + errors++; } }); }); -}); \ No newline at end of file +}); + +if (errors > 0) { + throw `Found ${errors} errors! Please fix!`; +} \ No newline at end of file