Skip to content

feat: allow scope-enum to also config delimiter #2407

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

Closed
wants to merge 1 commit into from

Conversation

longlho
Copy link

@longlho longlho commented Jan 15, 2021

fix #2108

Allow scope-enum rule to also configure delimiter regex

Description

Motivation and Context

Usage examples

// commitlint.config.js
module.exports = {};
echo "your commit message here" | commitlint # fails/passes

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@longlho
Copy link
Author

longlho commented Jan 15, 2021

cc @escapedcat

@escapedcat escapedcat requested a review from byCedric January 15, 2021 03:06
@escapedcat
Copy link
Member

Thanks @longlho ! @armano2 would you mind taking a look?

@armano2
Copy link
Contributor

armano2 commented Jan 15, 2021

there is few things that are missing right now,

enumRuleIsActive has to be adapted to take new configuration into account:

export function enumRuleIsActive(
rule: RuleEntry
): rule is [
string,
Readonly<
[RuleConfigSeverity.Warning | RuleConfigSeverity.Error, 'always', string[]]
>
] {
return (
ruleIsActive(rule) &&
ruleIsApplicable(rule) &&
Array.isArray(rule[1][2]) &&
rule[1][2].length > 0
);
}

same for this piece of code:

const [, [, , enums]] = enumRule;
enums.forEach((enumerable) => {

currently there is no tests that validate configuration for prompt

@longlho
Copy link
Author

longlho commented Jan 15, 2021

@armano2 I made the changes. I didn't change prompt bc the new config is rather advanced to be prompted so just reserved for hand-rolling config file (if I understand it correctly).

@escapedcat
Copy link
Member

For some reasons the checks here don't start/complete.
Not sure if it's related to this?:
image
I'm not sure what this means.
@longlho would you try to rebase master and try again? Or you have other ideas how to solve this?

@longlho
Copy link
Author

longlho commented Jan 22, 2021

hmm I rebased but also don't know what's going on

@escapedcat
Copy link
Member

We had something similar before with this PR: #2224 (comment)
Does this help?

@longlho
Copy link
Author

longlho commented Jan 23, 2021

hmm I tried but no dice it seems

@longlho longlho closed this Jan 25, 2021
@longlho longlho reopened this Jan 25, 2021
@escapedcat
Copy link
Member

Ugh, this is confusing. I tried google but no luck.

@armano2
Copy link
Contributor

armano2 commented Jan 25, 2021

@escapedcat, this is not an issue, circleci was doing ~2-3 days ago https://status.circleci.com/incidents/0jqzs9bd1ff3, you should retrigger build to fix this

export function enumRuleIsActive(
rule: RuleEntry
rule: RuleEntry<EnumRuleOptions>
Copy link
Contributor

@armano2 armano2 Jan 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check is not valid, as rule, we should require RuleEntry, rn, you basically force to have correct values, than type-guard is semi useless, this works only because you force expected type mapping in getRules, and all guards are useless now

@escapedcat
Copy link
Member

Can't find this PR in the list of pipelines: https://app.circleci.com/pipelines/github/conventional-changelog/commitlint
All other PRs are there.
How to re-trigger it from my side?

): rule is
| [string, Readonly<[RuleConfigSeverity, 'always']>]
| [string, Readonly<[RuleConfigSeverity, 'always', unknown]>] {
| [string, Readonly<[RuleConfigSeverity, 'always', C]>] {

This comment was marked as outdated.

Comment on lines +125 to +128
export function getRules<C = unknown>(
prefix: string,
rules: QualifiedRules
): RuleEntry<C>[] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function returns array of unknown rules and you can't know what types thy are going to be, all what you know is that prefix stats with something

Comment on lines +112 to +115
!!(config = rule[1][2]) &&
(!enumConfigIsExtendable(config)
? config.length > 0
: Array.isArray(config.values) && config.values.length > 0)
Copy link
Contributor

@armano2 armano2 Jan 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
!!(config = rule[1][2]) &&
(!enumConfigIsExtendable(config)
? config.length > 0
: Array.isArray(config.values) && config.values.length > 0)
(Array.isArray(rule[1][2])
? rule[1][2].length > 0
: typeof rule[1][2] === 'object' &&
'values' in rule[1][2] &&
rule[1][2].length > 0)

};

let enumRule = getRules('type', rules)
let enumRule = getRules<EnumRuleOptions>('type', rules)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all of those forced types should be removed

Comment on lines -88 to +89
const rules: any = {
const rules: Record<string, RuleEntry<EnumRuleOptions>[1]> = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

@armano2
Copy link
Contributor

armano2 commented Jan 25, 2021

Can't find this PR in the list of pipelines: https://app.circleci.com/pipelines/github/conventional-changelog/commitlint
All other PRs are there.
How to re-trigger it from my side?

easiest will be pushing something to this branch, as it should retrigger build


i added some comments about type guards, type guard should change type only for stuff that actualy is validated in function, we can't have getRules return X rule as it can cause issues -> this function returns all reles that are prefixed with something

@@ -118,7 +121,7 @@ export default function getPrompt(
if (enumRule) {
const [, [, , enums]] = enumRule;

enums.forEach((enumerable) => {
(enums as string[]).forEach((enumerable) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should not do typecasts as types should be correct here, you can do something like this

Suggested change
(enums as string[]).forEach((enumerable) => {
(Array.isArray(enums) ? enums : enums.values).forEach((enumerable) => {

Comment on lines +90 to +94
function enumConfigIsExtendable(
config?: EnumRuleOptions
): config is EnumRuleExtendableOptions {
return !Array.isArray(config);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this guard is invalidas its only check is not any[]

@escapedcat
Copy link
Member

@longlho would you be able to integrate aramanos feedback? If the checks still won't pass we can do the checks locally and merge it in anyways. Not sure what's the issue with circleci here or what we could do to make this work.

@escapedcat escapedcat closed this Mar 26, 2021
@longlho
Copy link
Author

longlho commented Mar 26, 2021

sry I haven't got time to get back to this PR :(

@escapedcat
Copy link
Member

No worries, just re-open it once you find some time ❤️

bbogdanov added a commit to bbogdanov/clarity that referenced this pull request Jun 17, 2021
When doing the research we missed that commitlint has
some multi-scope predefined delimeters and what we
are currently using is in conflict with commitlint expectations.
There is a PR in commitlint repo to fix these scenarious by letting
people provide a custom delimiters for scopes but
the owner is not actively working on that.

@bbogdanov will try to join and push that PR to get
in for their next release and unblock us to get back
to what we initially anticipated.

conventional-changelog/commitlint#2407

Signed-off-by: Bogdan Bogdanov <[email protected]>
bbogdanov added a commit to bbogdanov/clarity that referenced this pull request Jun 17, 2021
When doing the research we missed that commitlint has
some multi-scope predefined delimeters and what we
are currently using is in conflict with commitlint expectations.
There is a PR in commitlint repo to fix these scenarious by letting
people provide a custom delimiters for scopes but
the owner is not actively working on that.

@bbogdanov will try to join and push that PR to get
in for their next release and unblock us to get back
to what we initially anticipated.

conventional-changelog/commitlint#2407

Signed-off-by: Bogdan Bogdanov <[email protected]>
bbogdanov added a commit to bbogdanov/clarity that referenced this pull request Jun 17, 2021
When doing the research we missed that commitlint has
some multi-scope predefined delimeters and what we
are currently using is in conflict with commitlint expectations.
There is a PR in commitlint repo to fix these scenarious by letting
people provide a custom delimiters for scopes but
the owner is not actively working on that.

@bbogdanov will try to join and push that PR to get
in for their next release and unblock us to get back
to what we initially anticipated.

conventional-changelog/commitlint#2407

Signed-off-by: Bogdan Bogdanov <[email protected]>
bbogdanov added a commit to bbogdanov/clarity that referenced this pull request Jun 17, 2021
When doing the research we missed that commitlint has
some multi-scope predefined delimeters and what we
are currently using is in conflict with commitlint expectations.
There is a PR in commitlint repo to fix these scenarious by letting
people provide a custom delimiters for scopes but
the owner is not actively working on that.

@bbogdanov will try to join and push that PR to get
in for their next release and unblock us to get back
to what we wanted in the first place.

conventional-changelog/commitlint#2407

Signed-off-by: Bogdan Bogdanov <[email protected]>
bbogdanov added a commit to bbogdanov/clarity that referenced this pull request Jun 17, 2021
When doing the research we missed that commitlint has
some multi-scope predefined delimiters and what we
are currently using is in conflict with commitlint expectations.
There is a PR in commitlint repo to fix these scenarious by letting
people provide a custom delimiters for scopes but
the owner is not actively working on that.

@bbogdanov will try to join and push that PR to get
in for their next release and unblock us to get back
to what we wanted in the first place.

conventional-changelog/commitlint#2407

Signed-off-by: Bogdan Bogdanov <[email protected]>
bbogdanov added a commit to bbogdanov/clarity that referenced this pull request Jun 17, 2021
When doing the research we missed that commitlint has
some multi-scope predefined delimiters and what we
are currently using is in conflict with commitlint expectations.
There is a PR in commitlint repo to fix these scenarios by letting
people provide a custom delimiters for scopes but
the owner is not actively working on that.

@bbogdanov will try to join and push that PR to get
in for their next release and unblock us to get back
to what we wanted in the first place.

conventional-changelog/commitlint#2407

Signed-off-by: Bogdan Bogdanov <[email protected]>
bbogdanov added a commit to bbogdanov/clarity that referenced this pull request Jun 17, 2021
When doing the research we missed that commitlint has
some multi-scope predefined delimiters and what we
are currently using is in conflict with commitlint expectations.
There is a PR in commitlint repo to fix these scenarios by letting
people provide a custom delimiters for scopes but
the owner is not actively working on that.

@bbogdanov will try to join and push that PR to get
in for their next release and unblock us to get back
to what we wanted in the first place.

conventional-changelog/commitlint#2407

Signed-off-by: Bogdan Bogdanov <[email protected]>
bbogdanov added a commit to vmware-archive/clarity that referenced this pull request Jun 17, 2021
When doing the research we missed that commitlint has
some multi-scope predefined delimiters and what we
are currently using is in conflict with commitlint expectations.
There is a PR in commitlint repo to fix these scenarios by letting
people provide a custom delimiters for scopes but
the owner is not actively working on that.

@bbogdanov will try to join and push that PR to get
in for their next release and unblock us to get back
to what we wanted in the first place.

conventional-changelog/commitlint#2407

Signed-off-by: Bogdan Bogdanov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

type-enum does NOT work with scoped package names
3 participants