From 9653ae71510d55ef233f17ed265844d71431efb6 Mon Sep 17 00:00:00 2001 From: AnnAngela Date: Fri, 22 Dec 2023 16:41:27 +0800 Subject: [PATCH] ci: formatter --- .github/workflows/postCommit.yaml | 6 +-- package-lock.json | 9 ++++ package.json | 1 + scripts/modules/eslint-formatter-gha.cjs | 65 ------------------------ 4 files changed, 13 insertions(+), 68 deletions(-) delete mode 100644 scripts/modules/eslint-formatter-gha.cjs diff --git a/.github/workflows/postCommit.yaml b/.github/workflows/postCommit.yaml index da9e1a31..10bc650e 100644 --- a/.github/workflows/postCommit.yaml +++ b/.github/workflows/postCommit.yaml @@ -204,11 +204,11 @@ jobs: - name: Check environment run: 'npx eslint --env-info && echo ---- && echo "stylelint: "$(npx stylelint --version) && echo ---- && echo "v8r: "$(npx v8r --version) && echo ---- && mkdir -vp .cache && echo ".cache:" && ls -lhA .cache' - name: Run eslint - run: npx eslint --cache --cache-strategy content --cache-location ".cache/" --ext js --exit-on-fatal-error --format ./scripts/modules/eslint-formatter-gha.cjs --max-warnings 0 ./src || bash scripts/infoAboutFailure.sh + run: npx eslint --cache --cache-strategy content --cache-location ".cache/" --ext js --exit-on-fatal-error --format @annangela/eslint-formatter-gha --max-warnings 0 ./src - name: Run stylelint - run: npx stylelint --cache --cache-strategy content --cache-location ".cache/" --formatter github --max-warnings 0 "src/**/*.css" || bash scripts/infoAboutFailure.sh + run: npx stylelint --cache --cache-strategy content --cache-location ".cache/" --formatter github --max-warnings 0 "src/**/*.css" - name: Run v8r - run: echo "::group::v8r output" && npx v8r && echo "::endgroup::" || bash scripts/infoAboutFailure.sh + run: echo "::group::v8r output" && npx v8r && echo "::endgroup::" - name: Check .mailmap if: needs.postCommit.result == 'success' run: node scripts/emailmapChecker/index.js diff --git a/package-lock.json b/package-lock.json index 9455133c..116c113d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "dependencies": { "@actions/artifact": "^2.0.0", "@actions/core": "^1.10.1", + "@annangela/eslint-formatter-gha": "^1.0.2", "@annangela/eslint-plugin-prefer-reflect": "^2.1.0", "@csstools/postcss-is-pseudo-class": "^4.0.4", "@csstools/postcss-media-minmax": "^1.1.1", @@ -332,6 +333,14 @@ "node": ">=6.0.0" } }, + "node_modules/@annangela/eslint-formatter-gha": { + "version": "1.0.2", + "resolved": "https://mirrors.cloud.tencent.com/npm/@annangela/eslint-formatter-gha/-/eslint-formatter-gha-1.0.2.tgz", + "integrity": "sha512-pSfnnst8cY8OxWQ/F0VCSfHo1f2hxIG+W6SjT8V98DUxLpT2qno4FZn35J42sopSc2FStgEtlKHO54dwkqVSNg==", + "engines": { + "node": "^18.17 || ^20.9" + } + }, "node_modules/@annangela/eslint-plugin-prefer-reflect": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/@annangela/eslint-plugin-prefer-reflect/-/eslint-plugin-prefer-reflect-2.1.0.tgz", diff --git a/package.json b/package.json index 80059b2e..f9c23243 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "dependencies": { "@actions/artifact": "^2.0.0", "@actions/core": "^1.10.1", + "@annangela/eslint-formatter-gha": "^1.0.2", "@annangela/eslint-plugin-prefer-reflect": "^2.1.0", "@csstools/postcss-is-pseudo-class": "^4.0.4", "@csstools/postcss-media-minmax": "^1.1.1", diff --git a/scripts/modules/eslint-formatter-gha.cjs b/scripts/modules/eslint-formatter-gha.cjs deleted file mode 100644 index ac47d15e..00000000 --- a/scripts/modules/eslint-formatter-gha.cjs +++ /dev/null @@ -1,65 +0,0 @@ -// eslint-disable-next-line strict -"use strict"; -const isInGithubActions = process.env.GITHUB_ACTIONS === "true"; -const path = require("path"); -const { debug, notice, warning, error } = require("@actions/core"); -const deprecatedRules = []; -/** - * @type { import("eslint").ESLint.Formatter["format"] } - */ -const formatter = (results) => { - if (results.length === 0) { - return "Nothing is broken, everything is fine."; - } - for (const { - filePath, messages, usedDeprecatedRules, - // eslint-disable-next-line no-unused-vars - suppressedMessages, errorCount, fatalErrorCount, warningCount, fixableErrorCount, fixableWarningCount, output, source, - } of results) { - const baseAnnotationProperties = { - title: "ESLint Annotation", - file: filePath, - }; - for (const { ruleId, replacedBy } of usedDeprecatedRules) { - if (deprecatedRules.includes(ruleId)) { - continue; - } - deprecatedRules.push(ruleId); - // @TODO: Switch to `warning` when eslint 9 is released - debug(`Deprecated rule: ${ruleId}. ${replacedBy.length > 0 ? `Please use ${replacedBy.join(" / ")} instead.` : ""} - https://eslint.org/docs/latest/rules/${ruleId}`, baseAnnotationProperties); - } - for (const { - message, severity, line, column, endLine, endColumn, ruleId, fix, - // eslint-disable-next-line no-unused-vars - messageId, nodeType, fatal, source, suggestions, - } of messages) { - const msg = `${message} (${ruleId}) ${fix ? "[maybe fixable]" : ""} - https://eslint.org/docs/latest/rules/${ruleId}${isInGithubActions ? ` @ https://github.com/${process.env.GITHUB_REPOSITORY}/blob/${process.env.GITHUB_SHAs.slice(0, 7)}/${path.relative(process.cwd(), filePath)}#L${line}${line !== endLine ? `-L${endLine}` : ""}` : ""}`; - /** - * @type {NonNullable[1]>} - */ - const annotationProperties = { - ...baseAnnotationProperties, - startLine: line, - endLine, - startColumn: column, - endColumn, - }; - debug(JSON.stringify({ msg, ...annotationProperties }, null, 4)); - switch (severity) { - case 0: - notice(msg, annotationProperties); - break; - case 1: - warning(msg, annotationProperties); - break; - case 2: - error(msg, annotationProperties); - break; - default: - break; - } - } - } - return ""; -}; -module.exports = formatter;