commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

`parserPreset` in `.commitlintc.json` is ignored

Open gegenschall opened this issue 1 year ago • 4 comments

Steps to Reproduce

  1. Create .commitlintrc.json with the following contents
{
  "extends": ["@commitlint/config-conventional"],
  "parserPreset:": {
    "parserOpts": {
      "issuePrefixes": ["PREFIX-"]
    }
  },
  "rules": {
    "references-empty": [2, "never"]
  }
}
  1. Run echo "feat: some feature (PREFIX-123)" | npx commitlint and observe how an error for empty references is thrown.
  2. Run npx commitlint --print-config and observe how parserPreset.parserOpts.issuePrefixes is [ '#' ].

With a commitlint.config.js this does not happen.

Current Behavior

see above.

Expected Behavior

It should correctly pick up parserPreset from the JSON configuration.

Affected packages

  • [X] cli
  • [X] core
  • [ ] prompt
  • [ ] config-angular

Possible Solution

No response

Context

No response

commitlint --version

@commitlint/[email protected]

git --version

2.45.2

node --version

v20.13.1

gegenschall avatar Jun 19 '24 10:06 gegenschall

and observe how an error for empty references is thrown.

Please copy+paste that error.

knocte avatar Jul 06 '24 06:07 knocte

Uhm, sure:

â§—   input: feat: some feature (PREFIX-123)
✖   references may not be empty [references-empty]

✖   found 1 problems, 0 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

If you want a repro, see this repo.

gegenschall avatar Jul 11 '24 09:07 gegenschall

Uhm, can you check if this works?:

feat: some feature (#PREFIX-123)

Update: Hm, no. Should work as you described it I guess :(

escapedcat avatar Jul 11 '24 14:07 escapedcat

I have created a sharable config and need to overwrite the parser options.

I found a workaround to overwrite the @commitlint/config-conventional parserOpts presets without losing them.

index.js

import { resolveFrom } from '@commitlint/load';

// Resolve and import the conventional config
const conventionalConfigPath = resolveFrom('@commitlint/config-conventional', process.cwd());
const conventionalConfig = (await import(conventionalConfigPath)).default;

// Resolve and import the conventional parser options
const conventionalParserOptsPath = resolveFrom('conventional-changelog-conventionalcommits', process.cwd());
const conventionalParserOptsModule = await import(conventionalParserOptsPath);
const conventionalParserOpts = (await conventionalParserOptsModule.default()).parser;

export default {
  ...conventionalConfig,
  parserPreset: {
    parserOpts: {
      ...conventionalParserOpts,
      issuePrefixes: ['TNO-'],
    },
  },
};

krema avatar Oct 17 '24 13:10 krema