SSG - Single Standard for Git

SSG - Single Standard for Git

47

3 min.

Definitions

The SSG standard defines requirements for the semantics, accessibility, and logic of Git.

Conventional Commits - Commit Structure

A commit message should be structured as follows:

<type>([scope]): <brief description>

[Commit body]

[Footer(s)]

Header - Required Section

Type - commit classification:

TypePurpose
featNew functionality
fixBug fix
docsDocumentation changes
styleStyle changes without logic
refactorRefactoring without new functionality
perfPerformance improvement
test (spec)Tests
choreSupport tasks
buildBuild/dependency changes
ciCI/CD scripts
revertRevert a previous commit

Scope is optional and indicates the affected part of the project (e.g., ui, api, auth):

feat(api): Added a new endpoint for users

Description describes the changes, preferably in the imperative mood, no more than 50 characters.

Body explains what has been changed and why.

The footer is used for Breaking Changes, incompatible changes are indicated with BREAKING CHANGE: or feat!, for example, feat!: deprecated api methods removed, as well as for links to issues, such as Closes #123.

Setting Up the Pipeline for a Safe Commit Process

The pipeline handles formatting, commit validation, and safe branch merging.

Required Dependencies

npm i -D \
  husky \
  lint-staged \
  @commitlint/cli \
  @commitlint/config-conventional \
  @commitlint/types \
  conventional-changelog-conventionalcommits \
  @archoleat/commitlint-define-config

Lint-staged Configuration

Lint-staged checks only staged changes:

export default {
  '*': 'prettier --write',
  'src/**/*.{tsx,ts}': 'eslint --fix',
  'src/**/*.scss': 'stylelint --fix',
};

Commitlint Configuration

Commitlint checks commit formatting and allowed types:

import { defineConfig } from '@archoleat/commitlint-define-config';

export default defineConfig({
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [
      2,
      'always',
      [
        'build',
        'chore',
        'ci',
        'docs',
        'feat',
        'fix',
        'perf',
        'refactor',
        'revert',
        'spec',
        'style',
      ],
    ],
  },
});

You can view the defineConfig plugin here

Configuring Git Hooks (Husky)

HookCommandPurpose
pre-commitnpm run lint-stagedFormatting and fixing code before committing
commit-msgnpm run commitlint --editChecking compliance with Conventional Commits

There is a bug in Husky where, if a commit fails validation, changes may sometimes be lost!

The Final Commit Process

  • Staging changes:

    git add .
    
  • Creating a commit:

    git commit -m "feat(header): added theme toggle button"
    
  • pre-commit:

    lint-staged is run, Prettier, ESLint, and Stylelint fix errors in the indexed files, and then the fixed files are re-added to the index.

  • commit-msg:

    commitlint checks that the commit message complies with the Conventional Commits guidelines.

  • Result:

    The commit is successfully completed if all checks pass, otherwise, the commit is rejected with an error message.

Similar categories:

Similar articles

  • Anatomy of a React component

    My vision for how every React component should look

    99

    8 min.

  • SSF-U - Single Standard for Fullscreen

    The SSF-U standard defines requirements for the semantics, accessibility, and logic of fullscreen

    33

    2 min.

  • SSA - Single Standard for Accordion

    The SSA standard defines requirements for the semantics, accessibility, and logic of accordion

    47

    2 min.

  • Bad Practices for Websites

    An Analysis of Critical Web Design Mistakes. Why Sliders, Autoplay, and Slow-Loading Pages Reduce Conversion Rates and Rankings on Google and Yandex

    44

    2 min.

  • SSP - Single Standard for Pagination

    The SSP standard defines requirements for the semantics, accessibility, and logic of pagination

    54

    1 min.

  • SSPS - Single Standard for Project Structure

    The SSPS standard defines requirements for the structure and naming of files and folders in a project

    165

    2 min.

  • All articles

Contact me