We use EditorConfig to automatically apply certain styling standards before files are saved locally. Some editors and IDEs honor the .editorconfig
settings automatically by default.
If your editor or IDE does not automatically support .editorconfig
, we suggest investigating to see if a plugin exists. For example, a plugin for vim.
Lefthook is a Git hooks manager that allows custom logic to be executed prior to Git committing or pushing. GitLab comes with Lefthook configuration (lefthook.yml
), but it must be installed.
We have a lefthook.yml
checked in but it is ignored until Lefthook is installed.
We were using Overcommit prior to Lefthook, so you may want to uninstall it first with overcommit --uninstall
.
You can install lefthook in different ways. If you do not choose to install it globally (for example, via Homebrew or package managers), and only want to use it for the GitLab project, you can install the Ruby gem via:
Install Lefthook managed Git hooks:
# If installed globally
lefthook install
# Or if installed via ruby gem
bundle exec lefthook install
Test Lefthook is working by running the Lefthook pre-push
Git hook:
# If installed globally
lefthook run pre-push
# Or if installed via ruby gem
bundle exec lefthook run pre-push
This should return the Lefthook version and the list of executable commands with output.
Lefthook configurationLefthook is configured with a combination of:
lefthook.yml
.We have a custom lefthook target to run all the linters with auto-fix capabilities, but just on the files which changed in your branch.
# If installed globally
lefthook run auto-fix
# Or if installed via ruby gem
bundle exec lefthook run auto-fix
Disable Lefthook temporarily
To disable Lefthook temporarily, you can set the LEFTHOOK
environment variable to 0
. For instance:
You can run the pre-commit
, pre-push
, and auto-fix
hooks manually. For example:
bundle exec lefthook run pre-push
For more information, check out Lefthook documentation.
Skip Lefthook checks per tagTo skip some checks based on tags when pushing, you can set the LEFTHOOK_EXCLUDE
environment variable. For instance:
LEFTHOOK_EXCLUDE=frontend,documentation git push ...
As an alternative, you can create lefthook-local.yml
with this structure:
pre-push:
exclude_tags:
- frontend
- documentation
For more information, check out Lefthook documentation.
Skip or enable a specific Lefthook checkTo skip or enable a check based on its name when pushing, you can add skip: true
or skip: false
to the lefthook-local.yml
section for that hook. For instance, you might want to enable the gettext check to detect issues with locale/gitlab.pot
:
pre-push:
commands:
gettext:
skip: false
For more information, check out Lefthook documentation Skipping commands section.
Database migrationsSee the dedicated Database Migrations Style Guide.
JavaScriptSee the dedicated JS Style Guide.
SCSSSee the dedicated SCSS Style Guide.
RubySee the dedicated Ruby Style Guide.
GoSee the dedicated Go standards and style guidelines.
Shell commands (Ruby)See the dedicated Guidelines for shell commands in the GitLab codebase.
Shell scriptingSee the dedicated Shell scripting standards and style guidelines.
Publishing NPM packages to npmjs.comSee the dedicated npmjs package publishing guide.
MarkdownWe’re following Ciro Santilli’s Markdown Style Guide.
DocumentationSee the dedicated Documentation Style Guide.
Guidelines for good practicesGood practice examples demonstrate encouraged ways of writing code while comparing with examples of practices to avoid. These examples are labeled as “Bad” or “Good”. In GitLab development guidelines, when presenting the cases, it’s recommended to follow a “first-bad-then-good” strategy. First demonstrate the “Bad” practice (how things could be done, which is often still working code), and then how things should be done better, using a “Good” example. This is typically an improved example of the same code.
Consider the following guidelines when offering examples:
# Better
and # Best
.Although the bad-then-good approach is acceptable for the GitLab development guidelines, do not use it for user documentation. For user documentation, use Do and Don’t. For examples, see the Pajamas Design System.
PythonSee the dedicated Python Development Guidelines.
MiscCode should be written in US English.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4