doc/developer_manual/standards/code-style-guide.md
Our coding standards are enforced in the internal CI by various tools like Rubocop and ESLint. To make sure you always keep them in mind, you can use git hooks based on overcommit for this.
overcommit --install
This will execute several checks on the changed files whenever you commit. Feel free to add suggestion for additional interesting commit hooks. 🚀
Linters can also be run manually:
# Robocop
bundle exec rubocop --parallel
# Type checks, ESLint, Stylelint & Markdownlint
pnpm lint
# Type checks, ESLint, Stylelint & Markdownlint with automatic fixing
pnpm lint:fix
# Just type checking
pnpm lint:ts
# Just ESLint checks
pnpm lint:js
# Just ESLint checks with automatic fixing
pnpm lint:js:fix
# Just Stylelint checks
pnpm lint:css
# Just Stylelint checks with automatic fixing
pnpm lint:css:fix
# Just Markdownlint checks
pnpm lint:md
# Just Markdownlint checks with automatic fixing
pnpm lint:md:fix
# Coffeelint
coffeelint --rules ./.dev/coffeelint/rules/* app/
Rubocop will tell you. Don't forget to run it. Here are some additional tips.
&. to safely call method on possible nil variable.Hash#fetch for receiving values from hash and providing fall back value.Object#presence to return variable value while treating non Object#present? values as nil.Has*The methods are doing model related functions and events. This area is mainly used to do changes to other related objects.
For example, a model
Checks*The code contains hooks to events (e.g. after_commit), validations or another pre/post function checks.
For example:
Can*The code contains new functions without any relations to any hook or event.
For example, a model will get some new util functions
UpperCamelCase: e.g. ApolloClient
lowerCamelCase_ e.g. fileSize
UpperCamelCase: e.g. CommonDateTime.vue
ref="resize-line"${ComponentName}InstanceuseTemplateRef over ref for template references<script setup lang="ts">
import { useTemplateRef } from 'vue'
const buttonInstance = useTemplateRef('button')
const resizeLineInstance = useTemplateRef('resize-line')
const listElement = useTemplateRef('list')
</script>
<template>
<CommonButton ref="button"/>
<ResizeLine ref="resize-line"/>
<ul ref="list"/>
</template>
<script>
import { ref } from 'vue'
export const usePopoverTarget = () => {
const popoverTarget = ref()
return { popoverTarget }
}
</script>
<script setup lang="ts">
const { popoverTarget } = usePopoverTarget()
</script>
<template>
<button ref="popoverTarget"/>
</template>
TBD
UpperCamelCase:
<div>
<CommonDateTime ... />
<CommonDateTime>...</CommonDateTime>
</div>