How to use @commitlint/lint - 8 common examples

To help you get started, we’ve selected a few @commitlint/lint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / repo-automation-bots / packages / conventional-commit-lint / src / conventional-commit-lint.ts View on Github external
let message = context.payload.pull_request.title;
    // if there is only one commit, lint the commit rather than
    // the pull request title:
    if (commits.length === 1) {
      message = commits[0].commit.message;
    }

    // support "foo!: message" syntax, see:
    // https://github.com/conventional-changelog/commitlint/pull/767
    message = message.replace('!:', ':');

    let text = '';
    let lintError = false;

    const result = await lint(message, rules);
    if (result.valid === false) {
      lintError = true;
      text += `:x: linting errors for "*${result.input}*"\n`;
      result.errors.forEach(error => {
        text += `* ${error.message}\n`;
      });
      text += '\n\n';
    }

    // post the status of commit linting to the PR, using:
    // https://developer.github.com/v3/checks/
    let checkParams = context.repo({
      name: 'conventionalcommits.org',
      conclusion: 'success' as Conclusion,
      head_sha: commits[commits.length - 1].sha,
    });
github cozy / cozy.github.io / en / commitlint-config-cozy / index.spec.js View on Github external
it('respect max length', async () => {
      const valideLength =
        'fix: This line contains exactly 72 characters meaning it passes the test'
      expect((await lint(valideLength, rules)).valid).toBeTruthy()

      const invalidLength =
        'refactor: This one contains more than 72 so it really should not pass the test because no one can read the end'
      expect((await lint(invalidLength, rules)).valid).toBeFalsy()
    })
github cozy / cozy.github.io / en / commitlint-config-cozy / index.spec.js View on Github external
it('respect max length', async () => {
      const valideLength =
        'fix: This line contains exactly 72 characters meaning it passes the test'
      expect((await lint(valideLength, rules)).valid).toBeTruthy()

      const invalidLength =
        'refactor: This one contains more than 72 so it really should not pass the test because no one can read the end'
      expect((await lint(invalidLength, rules)).valid).toBeFalsy()
    })
github cozy / cozy.github.io / en / commitlint-config-cozy / index.spec.js View on Github external
it('respect scope', async () => {
      const validScope = ['LineChart', 'balance history']
      for (const scope of validScope) {
        expect((await lint(`feat(${scope}): Bar`, rules)).valid).toBeTruthy()
      }
    })
github cozy / cozy.github.io / en / commitlint-config-cozy / index.spec.js View on Github external
it('can use emojis in your commit subject', async () => {
      const validEmojis = [
        'fix: 🔍 This is a valid commit',
        'fix: This is a valid commit 🔍'
      ]
      for (const emoji of validEmojis) {
        expect((await lint(emoji, rules)).valid).toBeTruthy()
      }

      const invalidEmojis = '🔍 fix: This is an invalid commit'
      expect((await lint(invalidEmojis, rules)).valid).toBeFalsy()
    })
  })
github cozy / cozy.github.io / en / commitlint-config-cozy / index.spec.js View on Github external
it('can use emojis in your commit subject', async () => {
      const validEmojis = [
        'fix: 🔍 This is a valid commit',
        'fix: This is a valid commit 🔍'
      ]
      for (const emoji of validEmojis) {
        expect((await lint(emoji, rules)).valid).toBeTruthy()
      }

      const invalidEmojis = '🔍 fix: This is an invalid commit'
      expect((await lint(invalidEmojis, rules)).valid).toBeFalsy()
    })
  })
github cozy / cozy.github.io / en / commitlint-config-cozy / index.spec.js View on Github external
it('respect max length', async () => {
      const validBody = [`fix: Bar\n\nWith a small body`]
      for (const body of validBody) {
        expect((await lint(body, rules)).valid).toBeTruthy()
      }

      const invalidBody = [
        `fix: Bar\n\n${TOO_LONG}`,
        `fix: Bar\n\nWith a small body\n${TOO_LONG}`
      ]
      for (const body of invalidBody) {
        expect((await lint(body, rules)).valid).toBeFalsy()
      }
    })
  })
github toptal / simple-react-calendar / config / _ci / danger / conventionalCommit.js View on Github external
commits.forEach(async (commit) => {
    const result = await lint(
      commit.message,
      rules,
      parserPreset
        ? {
            parserOpts: parserPreset.parserOpts,
          }
        : {}
    )

    if (!result.valid) {
      if (result.errors.length > 0) {
        let message = `The commit - ${commit.sha.trim()} doesn't conform the conventional commit guidelines. \n\n**Errors**:\n\n`

        message += table([['Message'], ...result.errors.map((error) => [error.message])])

        message += `\n\n💡 For a guidance on how to fix this problem please refer to [https://www.conventionalcommits.org](https://www.conventionalcommits.org)`

@commitlint/lint

Lint a string against commitlint rules

MIT
Latest version published 16 days ago

Package Health Score

100 / 100
Full package analysis

Popular @commitlint/lint functions