debian-mirror-gitlab/doc/development/contributing/style_guides.md

116 lines
4.2 KiB
Markdown
Raw Normal View History

2021-01-03 14:25:43 +05:30
---
type: reference, dev
stage: none
group: Development
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#designated-technical-writers
---
2018-12-13 13:39:08 +05:30
# Style guides
2020-04-08 14:13:33 +05:30
## Editor/IDE styling standardization
We use [EditorConfig](https://editorconfig.org/) to automatically apply certain styling
standards before files are saved locally. Most editors/IDEs will honor the `.editorconfig`
settings automatically by default. If your editor/IDE does not automatically support `.editorconfig`,
we suggest investigating to see if a plugin exists. For instance here is the
[plugin for vim](https://github.com/editorconfig/editorconfig-vim).
2020-03-13 15:44:24 +05:30
## Pre-commit static analysis
2020-10-24 23:57:45 +05:30
You should install [`overcommit`](https://github.com/sds/overcommit) to automatically check for
2020-03-13 15:44:24 +05:30
static analysis offenses before committing locally.
2020-10-24 23:57:45 +05:30
After installing `overcommit`, run the following in your GitLab source directory:
2020-03-13 15:44:24 +05:30
```shell
2020-04-22 19:07:51 +05:30
make -C tooling/overcommit
2020-03-13 15:44:24 +05:30
```
2020-10-24 23:57:45 +05:30
Then before a commit is created, `overcommit` automatically checks for RuboCop (and other checks)
offenses on every modified file.
2020-03-13 15:44:24 +05:30
2020-10-24 23:57:45 +05:30
This saves you time as you don't have to wait for the same errors to be detected by CI/CD.
2020-03-13 15:44:24 +05:30
2020-10-24 23:57:45 +05:30
`overcommit` relies on a pre-commit hook to prevent commits that violate its ruleset. To override
this behavior, pass the `OVERCOMMIT_DISABLE` environment variable. For example,
`OVERCOMMIT_DISABLE=1 git rebase master` to rebase while disabling the Git hook.
2020-03-13 15:44:24 +05:30
## Ruby, Rails, RSpec
Our codebase style is defined and enforced by [RuboCop](https://github.com/rubocop-hq/rubocop).
You can check for any offenses locally with `bundle exec rubocop --parallel`.
On the CI, this is automatically checked by the `static-analysis` jobs.
For RuboCop rules that we have not taken a decision on yet, we follow the
[Ruby Style Guide](https://github.com/rubocop-hq/ruby-style-guide),
[Rails Style Guide](https://github.com/rubocop-hq/rails-style-guide), and
[RSpec Style Guide](https://github.com/rubocop-hq/rspec-style-guide) as general
guidelines to write idiomatic Ruby/Rails/RSpec, but reviewers/maintainers should
be tolerant and not too pedantic about style.
Similarly, some RuboCop rules are currently disabled, and for those,
reviewers/maintainers must not ask authors to use one style or the other, as both
are accepted. This isn't an ideal situation since this leaves space for
[bike-shedding](https://en.wiktionary.org/wiki/bikeshedding), and ideally we
should enable all RuboCop rules to avoid style-related
discussions/nitpicking/back-and-forth in reviews.
Additionally, we have a dedicated
2020-05-24 23:13:21 +05:30
[newlines style guide](../newlines_styleguide.md), as well as dedicated
2020-03-13 15:44:24 +05:30
[test-specific style guides and best practices](../testing_guide/index.md).
2020-07-28 23:09:34 +05:30
### Creating new RuboCop cops
Typically it is better for the linting rules to be enforced programmatically as it
reduces the aforementioned [bike-shedding](https://en.wiktionary.org/wiki/bikeshedding).
To that end, we encourage creation of new RuboCop rules in the codebase.
When creating a new cop that could be applied to multiple applications, we encourage you
to add it to our [GitLab Styles](https://gitlab.com/gitlab-org/gitlab-styles) gem.
2020-03-13 15:44:24 +05:30
## Database migrations
See the dedicated [Database Migrations Style Guide](../migration_style_guide.md).
## JavaScript
See the dedicated [JS Style Guide](../fe_guide/style/javascript.md).
## SCSS
See the dedicated [SCSS Style Guide](../fe_guide/style/scss.md).
## Go
See the dedicated [Go standards and style guidelines](../go_guide/index.md).
## Shell commands (Ruby)
See the dedicated [Guidelines for shell commands in the GitLab codebase](../shell_commands.md).
## Shell scripting
See the dedicated [Shell scripting standards and style guidelines](../shell_scripting_guide/index.md).
## Markdown
2020-07-28 23:09:34 +05:30
We're following [Ciro Santilli's Markdown Style Guide](https://cirosantilli.com/markdown-style-guide/).
2020-03-13 15:44:24 +05:30
## Documentation
See the dedicated [Documentation Style Guide](../documentation/styleguide.md).
## Python
See the dedicated [Python Development Guidelines](../python_guide/index.md).
## Misc
Code should be written in [US English](https://en.wikipedia.org/wiki/American_English).
2018-12-13 13:39:08 +05:30
---
[Return to Contributing documentation](index.md)