diff --git a/__tests__/src/formatters/@commitlint.spec.ts b/__tests__/src/formatters/@commitlint.spec.ts index 6c07005..af8a8ab 100644 --- a/__tests__/src/formatters/@commitlint.spec.ts +++ b/__tests__/src/formatters/@commitlint.spec.ts @@ -4,9 +4,9 @@ import type * as Chalk from 'chalk'; import chalk from 'chalk'; import { type FormatOptions, Formatter, type LintReport } from 'src/blueprints'; import format, { - formatter, formatInput, - formatResult + formatResult, + formatter } from 'src/formatters/@commitlint'; const signs = [chalk.green('✔'), chalk.yellow('⚠'), chalk.red('✖')]; diff --git a/__tests__/src/formatters/custom.spec.ts b/__tests__/src/formatters/custom.spec.ts index 7d306cf..8feddcc 100644 --- a/__tests__/src/formatters/custom.spec.ts +++ b/__tests__/src/formatters/custom.spec.ts @@ -7,9 +7,9 @@ import { type Transformer } from 'src/blueprints'; import format, { - formatter, formatInput, - formatResult + formatResult, + formatter } from 'src/formatters/custom'; const notImplementedError = new Error('need to `setTransformer` first.'); diff --git a/__tests__/src/formatters/default.spec.ts b/__tests__/src/formatters/default.spec.ts index 50dd0b2..12f5f01 100644 --- a/__tests__/src/formatters/default.spec.ts +++ b/__tests__/src/formatters/default.spec.ts @@ -4,9 +4,9 @@ import type * as Chalk from 'chalk'; import chalk from 'chalk'; import { type FormatOptions, Formatter, type LintReport } from 'src/blueprints'; import format, { - formatter, formatInput, - formatResult + formatResult, + formatter } from 'src/formatters/default'; const signs = [chalk.green('✔'), chalk.yellow('⚠'), chalk.red('✖')]; diff --git a/__tests__/src/formatters/gha-annotation.spec.ts b/__tests__/src/formatters/gha-annotation.spec.ts index b125d7e..3c86e41 100644 --- a/__tests__/src/formatters/gha-annotation.spec.ts +++ b/__tests__/src/formatters/gha-annotation.spec.ts @@ -4,9 +4,9 @@ import type * as Chalk from 'chalk'; import chalk from 'chalk'; import { type FormatOptions, Formatter, type LintReport } from 'src/blueprints'; import format, { - formatter, formatInput, - formatResult + formatResult, + formatter } from 'src/formatters/gha-annotation'; const signs = ['✔', '⚠', '✖']; @@ -32,17 +32,21 @@ describe('formatters > gha-annotation', () => { let lintReport: LintReport; let formatOptions: FormatOptions; const getFormatted = { - result: (_lintOutcome?: CLint.LintOutcome) => { + input: (_lintOutcome?: CLint.LintOutcome) => { const { input, errors, warnings } = _lintOutcome ?? lintOutcome; - const type = - errors.length > 0 - ? '::error' - : warnings.length > 0 - ? '::warning' - : '::debug'; + errors.length > 0 ? 'error' : warnings.length > 0 ? 'warning' : 'debug'; + + return res([ + `::${type}::`, + '✉️ Commit Message', + nL2, + input.split(/\r?\n/)[0].trim() + ]); + }, + result: (_lintOutcome?: CLint.LintOutcome) => { + const { errors, warnings } = _lintOutcome ?? lintOutcome; - const header = `${type}::✉️ Commit Message${nL2}${input}`; const summarySign = signs[errors.length > 0 ? 2 : warnings.length > 0 ? 1 : 0]; const problems = [...errors, ...warnings].map((problem) => { @@ -59,7 +63,7 @@ describe('formatters > gha-annotation', () => { ? `${nL}Help: ${formatOptions.helpUrl}` : ''; - return res([header, nL2, body, nL2, summary, help]); + return res([body, nL2, summary, help]); } }; @@ -106,10 +110,37 @@ describe('formatters > gha-annotation', () => { }); describe('formatInput', () => { - it('should return empty array', () => { + it('should return empty array if problem not exists', () => { + lintOutcome.errors = []; + lintOutcome.warnings = []; + const formattedInput = formatInput(lintOutcome, formatOptions); + expect(formattedInput).toEqual([]); }); + + it('should correctly format input if problem not exists but verbose is true', () => { + lintOutcome.errors = []; + lintOutcome.warnings = []; + formatOptions.verbose = true; + + const formattedInput = formatInput(lintOutcome, formatOptions); + + expect(formattedInput).toEqual(getFormatted.input()); + }); + + it('should correctly format input if problem exists', () => { + const formattedInput = formatInput(lintOutcome, formatOptions); + expect(formattedInput).toEqual(getFormatted.input()); + }); + + it('should only take the first line as reuslt', () => { + lintOutcome.input = 'fix: something\n\nbody\n\nfooter'; + const formattedInput = formatInput(lintOutcome, formatOptions); + expect(formattedInput[0]).not.toInclude('\n'); + expect(formattedInput[0]).not.toInclude('body'); + expect(formattedInput[0]).not.toInclude('footer'); + }); }); describe('formatResult', () => { @@ -162,7 +193,12 @@ describe('formatters > gha-annotation', () => { const formattedReport = format(lintReport, formatOptions); const expected = lintReport.results - .map((lintOutcome) => getFormatted.result(lintOutcome).join('')) + .map( + (lintOutcome) => + getFormatted.input(lintOutcome) + + nL2 + + getFormatted.result(lintOutcome).join('') + ) .join(formatOptions.separatorBetweenCommits); expect(formattedReport).toBe(expected); diff --git a/__tests__/src/formatters/json-pretty.spec.ts b/__tests__/src/formatters/json-pretty.spec.ts index 84419fc..69a2c35 100644 --- a/__tests__/src/formatters/json-pretty.spec.ts +++ b/__tests__/src/formatters/json-pretty.spec.ts @@ -4,9 +4,9 @@ import type * as Chalk from 'chalk'; import chalk from 'chalk'; import { type FormatOptions, Formatter, type LintReport } from 'src/blueprints'; import format, { - formatter, formatInput, - formatResult + formatResult, + formatter } from 'src/formatters/json-pretty'; const signs = ['✔', '⚠', '✖']; diff --git a/__tests__/src/formatters/json.spec.ts b/__tests__/src/formatters/json.spec.ts index 2bcf5d4..b3a9523 100644 --- a/__tests__/src/formatters/json.spec.ts +++ b/__tests__/src/formatters/json.spec.ts @@ -4,9 +4,9 @@ import type * as Chalk from 'chalk'; import chalk from 'chalk'; import { type FormatOptions, Formatter, type LintReport } from 'src/blueprints'; import format, { - formatter, formatInput, - formatResult + formatResult, + formatter } from 'src/formatters/json'; const signs = ['✔', '⚠', '✖']; diff --git a/biome.jsonc b/biome.jsonc index 58256e4..5b9bfbc 100644 --- a/biome.jsonc +++ b/biome.jsonc @@ -3,9 +3,6 @@ "files": { "ignoreUnknown": true }, - "organizeImports": { - "enabled": true - }, "formatter": { "enabled": true, "attributePosition": "multiline", @@ -25,23 +22,6 @@ } } }, - "css": { - "formatter": { - "enabled": true, - "indentStyle": "space", - "indentWidth": 2, - "lineWidth": 80, - "lineEnding": "lf", - "quoteStyle": "single" - }, - "linter": { - "enabled": true - }, - "parser": { - "allowWrongLineComments": true, - "cssModules": true - } - }, "javascript": { "formatter": { "enabled": true, diff --git a/bun.lockb b/bun.lockb index ac51308..1c38796 100644 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 94a0f84..fdd1526 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,9 @@ "bugs": { "url": "https://github.com/codeismyid/commitlint-format/issues" }, - "files": ["dist"], + "files": [ + "dist" + ], "publishConfig": { "access": "public", "provenance": true @@ -45,21 +47,21 @@ }, "dependencies": {}, "peerDependencies": { - "@commitlint/types": "^19.5.0", - "chalk": "^5.4.1" + "@commitlint/types": "^19 || ^20", + "chalk": "^5" }, "devDependencies": { - "@biomejs/biome": "1.9.4", - "@commitlint/cli": "19.8.0", - "@types/bun": "latest", - "conventional-changelog-conventionalcommits": "8.0.0", + "@biomejs/biome": "2.4.13", + "@commitlint/cli": "20.5.2", + "@types/bun": "1.3.13", + "conventional-changelog-conventionalcommits": "9.3.1", "esbuild": "0.28.0", "husky": "9.1.7", - "publint": "0.3.12", - "semantic-release": "24.2.3", + "publint": "0.3.18", + "semantic-release": "25.0.3", "tsc-alias": "1.8.16", "type-coverage": "2.29.7", - "typescript": "5.8.3" + "typescript": "6.0.3" }, "type": "module", "module": "dist/index.js", diff --git a/scripts/release.ts b/scripts/release.ts index afc7d36..521b578 100644 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -167,6 +167,7 @@ const releaseOptions: SemanticRelease.Options = (() => { return { branches: RELEASE_BRANCHES, repositoryUrl: packageJson.repository.url, + // biome-ignore lint/suspicious/noTemplateCurlyInString: intended tagFormat: 'v${version}', plugins }; diff --git a/src/formatters/gha-annotation.ts b/src/formatters/gha-annotation.ts index c4b48ca..c0a072e 100644 --- a/src/formatters/gha-annotation.ts +++ b/src/formatters/gha-annotation.ts @@ -9,14 +9,8 @@ const nL2 = nL + nL; */ export const formatter = new Formatter( { - transformInput: () => [], - transformResult: (result, context) => { - const { - formatOptions: { helpUrl }, - getSign - } = context; - let formatted = ''; - + transformInput: (result) => { + const commitMsg = result.input.split(/\r?\n/)[0].trim(); const type = result.errors.length > 0 ? 'error' @@ -24,7 +18,16 @@ export const formatter = new Formatter( ? 'warning' : 'debug'; - formatted += `::${type}::✉️ Commit Message${nL2}${result.input}${nL2}`; + const formatted = `::${type}::✉️ Commit Message${nL2}${commitMsg}`; + + return [formatted]; + }, + transformResult: (result, context) => { + const { + formatOptions: { helpUrl }, + getSign + } = context; + let formatted = ''; const errorCount = result.errors.length; const warningCount = result.warnings.length; diff --git a/tsconfig.json b/tsconfig.json index 7f9be79..c0dcf46 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -33,9 +33,14 @@ "src": ["./src"], "src/*": ["./src/*"], "tsconfig.json": ["./tsconfig.json"], - "package.json": ["./package.json"] + "package.json": ["./package.json"], + "dist": ["./dist"], + "dist/*": ["./dist/*"] }, + // TypeScript V6 + "types": ["bun"], + // Others "noEmitOnError": true, "noErrorTruncation": true,