Skip to content

Add emojis by default #4535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
97 changes: 94 additions & 3 deletions @commitlint/cz-commitlint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,105 @@ In package.json

```bash
# Install commitlint cli and conventional config
npm install --save-dev @commitlint/config-conventional @commitlint/cli
npm install --save-dev @commitlint/config-conventional @commitlint/cli commitlint-config-gitmoji
# or yarn
yarn add @commitlint/config-conventional @commitlint/cli -D
yarn add @commitlint/config-conventional @commitlint/cli commitlint-config-gitmoji -D

# Simple: config with conventional
echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js
import { UserConfig } from "@commitlint/types";
import gitmoji from 'commitlint-config-gitmoji'

/**
* @type {import('@commitlint/types').UserConfig}
*/ for .js file
module.exports = {
extends: ['@commitlint/config-conventional'],
prompt: {
questions: {
type: {
description: "Select the type of change that you're committing",
enum: {
feat: {
description: "A new feature",
title: "Features",
emoji: "✨",
},
fix: {
description: "A bug fix",
title: "Bug Fixes",
emoji: "🐛",
},
docs: {
description: "Documentation only changes",
title: "Documentation",
emoji: "📚",
},
style: {
description:
"Changes that do not affect the meaning of the code (linters)",
title: "Styles",
emoji: "🎨",
},
refactor: {
description:
"A code change that neither fixes a bug nor adds a feature",
title: "Code Refactoring",
emoji: "📦",
},
perf: {
description: "A code change that improves performance",
title: "Performance Improvements",
emoji: "🚀",
},
test: {
description: "Adding missing tests or correcting existing tests",
title: "Tests",
emoji: "🚨",
},
build: {
description:
"Changes that affect the build system or external dependencies (yarn)",
title: "Builds",
emoji: "🏗️ ",
},
ci: {
description:
"Changes to our CI configuration files and scripts (GitActions)",
title: "Continuous Integrations",
emoji: "⚙️ ",
},
chore: {
description: "Other changes that don't modify src or test files",
title: "Chores",
emoji: "♻️ ",
},
revert: {
description: "Reverts a previous commit",
title: "Reverts",
emoji: "⏪",
},
},
},
},
},
parserPreset: {
parserOpts: gitmoji.parserPreset.parserOpts,
plugins: [gitmoji.parserPreset.plugins],
},
...gitmoji.rules,
...gitmoji.plugins
} as UserConfig
```

```json
.czrc

{
"path": "@commitlint/cz-commitlint",
"useGitmojis": true
}

```
### Try it out

```bash
Expand Down
39 changes: 32 additions & 7 deletions @commitlint/cz-commitlint/src/SectionHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@
}

export function combineCommitMessage(answers: Answers): string {
const { type = "", scope = "", subject = "" } = answers;
const prefix = `${type}${scope ? `(${scope})` : ""}`;
const { type = "", scope = "", subject = "" } = answers;

if (subject) {
return ((prefix ? prefix + ": " : "") + subject).trim();
} else {
return prefix.trim();
}
const questions = getQuestions();

const emoji = questions
.find(item => item.type === 'list' && item.name === 'type')?.choices

Check failure on line 35 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, 20)

Property 'choices' does not exist on type 'DistinctQuestion'.

Check failure on line 35 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, 18)

Property 'choices' does not exist on type 'DistinctQuestion'.

Check failure on line 35 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / Commitlint

Property 'choices' does not exist on type 'DistinctQuestion'.

Check failure on line 35 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, 18)

Property 'choices' does not exist on type 'DistinctQuestion'.

Check failure on line 35 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, 20)

Property 'choices' does not exist on type 'DistinctQuestion'.
?.find(choice => choice.value === type)?.emoji;

Check failure on line 36 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, 20)

Parameter 'choice' implicitly has an 'any' type.

Check failure on line 36 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, 18)

Parameter 'choice' implicitly has an 'any' type.

Check failure on line 36 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / Commitlint

Parameter 'choice' implicitly has an 'any' type.

Check failure on line 36 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, 18)

Parameter 'choice' implicitly has an 'any' type.

Check failure on line 36 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, 20)

Parameter 'choice' implicitly has an 'any' type.

const prefix = `${emoji?.trim()} ${type}${scope ? `(${scope})` : ""}`;
if (subject) {
return ((prefix ? prefix + ": " : "") + subject).trim();
}
else {
return prefix.trim();
}
}

export function getQuestions(): Array<DistinctQuestion> {
Expand Down Expand Up @@ -81,3 +88,21 @@

return questionConfig;
}

export function getEmojis() {
const headerRuleQuestionConfig = getRuleQuestionConfig("header");

if (!headerRuleQuestionConfig) {
return [];
}

const emojis = headerRuleQuestionConfig?.enumList?.map(item => {
if (typeof item === 'object') {
return { value: item.value, emoji: item.emoji || '' };

Check failure on line 101 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, 20)

Property 'emoji' does not exist on type 'ChoiceOptions | Separator | SeparatorOptions | ExpandChoiceOptions | Choice<{ name: string; value: string; }> | ListChoiceOptions<...> | CheckboxChoiceOptions<...>'.

Check failure on line 101 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, 20)

Property 'value' does not exist on type 'ChoiceOptions | Separator | SeparatorOptions | ExpandChoiceOptions | Choice<{ name: string; value: string; }> | ListChoiceOptions<...> | CheckboxChoiceOptions<...>'.

Check failure on line 101 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, 18)

Property 'emoji' does not exist on type 'ChoiceOptions | Separator | SeparatorOptions | ExpandChoiceOptions | Choice<{ name: string; value: string; }> | ListChoiceOptions<...> | CheckboxChoiceOptions<...>'.

Check failure on line 101 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-22.04, 18)

Property 'value' does not exist on type 'ChoiceOptions | Separator | SeparatorOptions | ExpandChoiceOptions | Choice<{ name: string; value: string; }> | ListChoiceOptions<...> | CheckboxChoiceOptions<...>'.

Check failure on line 101 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / Commitlint

Property 'emoji' does not exist on type 'ChoiceOptions | Separator | SeparatorOptions | ExpandChoiceOptions | Choice<{ name: string; value: string; }> | ListChoiceOptions<...> | CheckboxChoiceOptions<...>'.

Check failure on line 101 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / Commitlint

Property 'value' does not exist on type 'ChoiceOptions | Separator | SeparatorOptions | ExpandChoiceOptions | Choice<{ name: string; value: string; }> | ListChoiceOptions<...> | CheckboxChoiceOptions<...>'.

Check failure on line 101 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, 18)

Property 'emoji' does not exist on type 'ChoiceOptions | Separator | SeparatorOptions | ExpandChoiceOptions | Choice<{ name: string; value: string; }> | ListChoiceOptions<...> | CheckboxChoiceOptions<...>'.

Check failure on line 101 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, 18)

Property 'value' does not exist on type 'ChoiceOptions | Separator | SeparatorOptions | ExpandChoiceOptions | Choice<{ name: string; value: string; }> | ListChoiceOptions<...> | CheckboxChoiceOptions<...>'.

Check failure on line 101 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, 20)

Property 'emoji' does not exist on type 'ChoiceOptions | Separator | SeparatorOptions | ExpandChoiceOptions | Choice<{ name: string; value: string; }> | ListChoiceOptions<...> | CheckboxChoiceOptions<...>'.

Check failure on line 101 in @commitlint/cz-commitlint/src/SectionHeader.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-24.04, 20)

Property 'value' does not exist on type 'ChoiceOptions | Separator | SeparatorOptions | ExpandChoiceOptions | Choice<{ name: string; value: string; }> | ListChoiceOptions<...> | CheckboxChoiceOptions<...>'.
}

return { value: item, emoji: null };
})

return emojis || [];
}
31 changes: 18 additions & 13 deletions @commitlint/cz-commitlint/src/services/getRuleQuestionConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,24 @@ export default function (rulePrefix: RuleField): QuestionConfig | null {
);
// TODO emoji + title
enumList = enumRuleList
.sort((a, b) => enumNames.indexOf(a) - enumNames.indexOf(b))
.map((enumName) => {
const enumDescription = enumDescriptions[enumName]?.description;
if (enumDescription) {
return {
name: `${enumName}:`.padEnd(longest + 4) + enumDescription,
value: enumName,
short: enumName,
};
} else {
return enumName;
}
});
.sort((a, b) => enumNames.indexOf(a) - enumNames.indexOf(b))
.map((enumName) => {
const enumDescription = enumDescriptions[enumName]?.description;
const emoji = enumDescriptions[enumName]?.emoji ? enumDescriptions[enumName].emoji : '';

if (enumDescription) {
return {
name: `${emoji} ${enumName}:`.padEnd(longest + 8) + enumDescription,
value: enumName,
short: enumName,
emoji: emoji || null
};
}
else {
return enumName;
}
}
);
} else {
enumList = [...enumRuleList];
}
Expand Down
Loading