Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions __tests__/src/formatters/@commitlint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('✖')];
Expand Down
4 changes: 2 additions & 2 deletions __tests__/src/formatters/custom.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down
4 changes: 2 additions & 2 deletions __tests__/src/formatters/default.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('✖')];
Expand Down
62 changes: 49 additions & 13 deletions __tests__/src/formatters/gha-annotation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ['✔', '⚠', '✖'];
Expand All @@ -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) => {
Expand All @@ -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]);
}
};

Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions __tests__/src/formatters/json-pretty.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ['✔', '⚠', '✖'];
Expand Down
4 changes: 2 additions & 2 deletions __tests__/src/formatters/json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ['✔', '⚠', '✖'];
Expand Down
20 changes: 0 additions & 20 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"files": {
"ignoreUnknown": true
},
"organizeImports": {
"enabled": true
},
"formatter": {
"enabled": true,
"attributePosition": "multiline",
Expand All @@ -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,
Expand Down
Binary file modified bun.lockb
Binary file not shown.
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"bugs": {
"url": "https://github.com/codeismyid/commitlint-format/issues"
},
"files": ["dist"],
"files": [
"dist"
],
"publishConfig": {
"access": "public",
"provenance": true
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions scripts/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
21 changes: 12 additions & 9 deletions src/formatters/gha-annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,25 @@ 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'
: result.warnings.length > 0
? '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;
Expand Down
7 changes: 6 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading