question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

type-enum does NOT work with scoped package names

See original GitHub issue

type-enum does not work if the enum values are scoped packages such @foo/bar.

Expected Behavior

Commit message such as fix(@foo/bar): fix some bug should be supported, in a monorepo setting where the repo hosts multiple scoped npm packages.

Current Behavior

It prints a confusing error message: scope must be one of [@foo/bar, .... The error message doesn’t say that slashes are used as a delimiter in this rule.

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

Do not use slashes as the multi-scope values delimeter.

Steps to Reproduce (for bugs)

  1. First step

Setup husky to use commitlint as the commit-msg hook in the repo root’s package.json:

  // in package.json
  "husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  },
  1. Second step

Use the following commitlint config:

commitlint.config.js
module.exports = {
  rules: {
    'scope-enum': [2, 'always', '@foo/bar'],
  },
};

Try to do a commit with commit message fix(@foo/bar): fix some bug.

Context

Our repo https://github.com/formatjs/formatjs is a monorepo that hosts the source code multiple packages. Most of the packages are scoped to @formatjs/. We use the scope-enum linter rule to ensure that each commit correctly specify the affected packages. This information is critical because we use Lerna to version and publish the packages, and Lerna reads these commit messages for semantic versioning.

Your Environment

Executable Version
commitlint --version 9.1.2
git --version 2.25.0
node --version 14.9.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jdbruijncommented, Oct 20, 2020

@pyrocat101 I think this issue can be resolved using my plugin commitlint-plugin-function-rules.

Using the plugin, you can write something like this as commitlint config. Hope this helps!

module.exports = {
  extends: ['@commitlint/config-conventional'],
  plugins: ['commitlint-plugin-function-rules'],
  rules: {
    'scope-enum': [0], // level: disabled
    'function-rules/scope-enum': [
      2, // level: error
      'always',
      (parsed) => {
        const allowedScopes = ['@foo/bar'];
        if (!parsed.scope || allowedScopes.includes(parsed.scope)) {
          return [true];
        }

        return [false, `scope must be one of ${allowedScopes.join(', ')}`];
      },
    ],
  },
};
0reactions
RS-Sauttercommented, Nov 8, 2022

@pyrocat101 I think this issue can be resolved using my plugin commitlint-plugin-function-rules.

Using the plugin, you can write something like this as commitlint config. Hope this helps!

module.exports = {
  extends: ['@commitlint/config-conventional'],
  plugins: ['commitlint-plugin-function-rules'],
  rules: {
    'scope-enum': [0], // level: disabled
    'function-rules/scope-enum': [
      2, // level: error
      'always',
      (parsed) => {
        const allowedScopes = ['@foo/bar'];
        if (!parsed.scope || allowedScopes.includes(parsed.scope)) {
          return [true];
        }

        return [false, `scope must be one of ${allowedScopes.join(', ')}`];
      },
    ],
  },
};

@escapedcat I think this plugin should be part of the main code. It should be allowed to define a custom rule based on a function, what do you think?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript resolve types for private scoped package
How do you properly reference types published as part of a scoped package? If it is being referenced properly, why are the types...
Read more >
Enumeration declaration - cppreference.com
Each enumerator becomes a named constant of the enumeration's type (that is, name), visible in the enclosing scope, and can be used whenever ......
Read more >
Enumeration (or enum) in C - GeeksforGeeks
If we do not explicitly assign values to enum names, the compiler by default assigns values starting from 0. For example, in the...
Read more >
Chapter 7. Packages and Modules - Oracle Help Center
A package may not contain two members of the same name, or a compile-time error ... level packages in scope and the meaning...
Read more >
Simulink Enumerations - MATLAB & Simulink - MathWorks
Enumerated data is data that is restricted to a finite set of values. ... axis displays the names of the enumerated values only...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found