commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

[FeatureReq] ability to fix warnings

Open Tbhesswebber opened this issue 6 years ago • 4 comments

Note: This may exist and just not be documented/be documented somewhere that I didn't look.

  1. Provide ability to pass a --fix flag to the cli or config.fix: true | "prompt" | "auto-accept" in a config file.
  2. Provide option to create config.rules.<rule name>.fix = null | () => {}

Expected Behavior

  1. Passing the flag or setting the property should cause commitlint to check rules that have the ability to be fixed automatically. 1.1. Can prompt the user to accept the change. (Could possibly add in functionality to always show prompt regardless of warnings or errors)
  2. Setting a fix property inside of a custom rule sets the method for fixing said warning or error.

Current Behavior

The current behavior seems to just accept commits with warnings without any fixing capabilities.

Affected packages

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

Possible Solution

  • alter current commit script to pipe into an additional script that applies a fix and/or prompts for confirmation
  • alter core functionality to use a custom parser that generates a commitlint "AST"

Context

I just made a commit through commitizen that apparently didn't have an empty line before the footer, but commitlint accepted it with a warning.

Tbhesswebber avatar Feb 17 '19 17:02 Tbhesswebber

Hi @Tbhesswebber! This does sound like a great idea. But this will imply a lot of changes too. So I think it's best to discuss this if and how we should approach this when @marionebl and @escapedcat have some time available.

byCedric avatar Feb 19 '19 21:02 byCedric

Just to understand this a bit better. You mean a rule could have a fix function as well. So for an easy rule, like "should have empty line before footer" the line could be added automatically?

escapedcat avatar Mar 11 '19 07:03 escapedcat

Precisely. Warning rules often have simple fixes - capitalization, new lines, etc. Rather than accepting warnings by default, it would be desirable to provide a prompt indicating the number of fixable errors and allow the user to fix all or cherrypick fixes.

Fixing options could be opted out of - or overwritten - by users or inherited from standard configurations like conventional-changelog.

Tbhesswebber avatar Mar 13 '19 07:03 Tbhesswebber

Agreed, sounds kinda nice. Not sure if we have time for this though. You would you be able to give a hand with this?

escapedcat avatar Mar 13 '19 07:03 escapedcat