Giter Club home page Giter Club logo

danger-plugin-conventional-commitlint's Introduction

danger-plugin-conventional-commitlint

CI npm version semantic-release code style: prettier

A danger plugin to lint commit messages with commitlint

Usage

Install:

npm install --save-dev danger-plugin-conventional-commitlint

At a glance:

// dangerfile.js
import commitlint from 'danger-plugin-conventional-commitlint';
import configConventional from '@commitlint/config-conventional';

(async function dangerReport() {
  const commitlintConfig = {
    severity: 'warn',
  };
  await commitlint(configConventional.rules, commitlintConfig);
})();

Note: you must provide your own rules to the function

API

commitlint([rules], [options])

Options

severity

Type: String
Choices: 'fail' | 'warn' | 'message'
Default: 'fail'
Danger method to call when the commit message does not pass the linter


messageReplacer

Type:

(ruleOutcome: LintOutcome, commitMessage: string) => string;

Default:

There is a problem with the commit message > [Commit message] - [Error Messages]

Method to add a custom message. When not passed, a default message is shown. Example:

const messageReplacer = (
  ruleOutcome: LintOutcome,
  commitMessage: string
): string => {
  const errorsDescription = ruleOutcome.errors
    .map((error) => `<li>${error.message}</li>`)
    .join('');

  return `<p>Commit message: <b>"${commitMessage}"</b></p><ul>${errorsDescription}</ul> Suffix after commit message`;
};

Changelog

See the GitHub release history.

Contributing

See CONTRIBUTING.md.

danger-plugin-conventional-commitlint's People

Contributors

bearalliance avatar dependabot[bot] avatar kirasl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

kirasl gigamac

danger-plugin-conventional-commitlint's Issues

'Note: you must provide your own rules to the function' - how can you use custom rules?

in commitlint you can create custom rules as plugins - bit convoluted but it is what it is.
in this plugin, how can you implement a custom rule from commitlint so that a developer can have the same custom rule applied to their code locally and in dangerfile?

your note: 'Note: you must provide your own rules to the function' - doesn't really say whether you can or cannot, it just says add your own...

... but in this context, it looks like commitlint(rules, custom?) parameter rules only allows a short list matching those hard defined in the interface... ?

interface Rules { 'body-leading-blank': Array<number | string>; 'footer-leading-blank': Array<number | string>; 'header-max-length': Array<number | string>; 'scope-case': Array<number | string>; 'subject-case': Array<string[] | number | string>; 'subject-empty': Array<number | string>; 'subject-full-stop': Array<number | string>; 'type-case': Array<number | string>; 'type-empty': Array<number | string>; 'type-enum': Array<string[] | number | string>; }

if I add:
[key: string]: Array<string[] | number | string>;
I can get a rule past the interface, but it then fails in lint because it isn't defined or loaded in lint:
Error: RangeError: Found invalid rule names: my-custom-jira-rule. Supported rule names are: body-case, body-empty, body-full-stop, body-leading-blank, body-max-length, body-max-line-length, body-min-length, footer-empty, footer-leading-blank, footer-max-length, footer-max-line-length, footer-min-length, header-case, header-full-stop, header-max-length, header-min-length, references-empty, scope-case, scope-empty, scope-enum, scope-max-length, scope-min-length, signed-off-by, subject-case, subject-empty, subject-full-stop, subject-max-length, subject-min-length, subject-exclamation-mark, trailer-exists, type-case, type-empty, type-enum, type-max-length, type-min-length at lint (~/node_modules/@commitlint/lint/lib/lint.js:53:15)

Hope that makes sense ... ?
Or if I am missing a way to get the custom rules added, is there a howto? I couldn't find it...

Broken since Commitlint v18.6.0

This is incompatible with Commintlint since the v18.6.0
See the changelog
Here is the error:

Error:  RangeError: Found invalid rule names: header-trim. Supported rule names are: body-case, body-empty, body-full-stop, body-leading-blank, body-max-length, body-max-line-length, body-min-length, footer-empty, footer-leading-blank, footer-max-length, footer-max-line-length, footer-min-length, header-case, header-full-stop, header-max-length, header-min-length, references-empty, scope-case, scope-empty, scope-enum, scope-max-length, scope-min-length, signed-off-by, subject-case, subject-empty, subject-full-stop, subject-max-length, subject-min-length, subject-exclamation-mark, trailer-exists, type-case, type-empty, type-enum, type-max-length, type-min-length

Unable to run within GitHub action

I have the following in my dangerjs.js

import { message, fail, warn, danger } from "danger";
// const { exec } = require("child_process");
import commitlint from "danger-plugin-conventional-commitlint";

import configConventional from "@commitlint/config-conventional";

(async function dangerReport() {
  const commitlintConfig = {
    severity: "warn",
  };
  await commitlint(configConventional.rules, commitlintConfig);
})();

But when run in a github action receive:

Unable to evaluate the Dangerfile
 ./dangerfile.js:4
import commitlint from "danger-plugin-conventional-commitlint";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:360:[18](https://github.com/app/actions/runs/3510160765/jobs/5879744816#step:6:19))
    at wrapSafe (node:internal/modules/cjs/loader:1084:15)
    at Module._compile (node:internal/modules/cjs/loader:11[19](https://github.com/app/actions/runs/3510160765/jobs/5879744816#step:6:20):27)
...

Is there a working example I can reference?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.