Skip to content

Commit f82a832

Browse files
committed
feat(developer): Refactor coding guidelines and update frontend code
style Update to living coding standard for frontend, with proper do's and dont's. Separated the coding guidelines into frontend and backend (PHP). Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 3e10a7c commit f82a832

File tree

9 files changed

+1126
-534
lines changed

9 files changed

+1126
-534
lines changed

_shared_assets/static/custom.css

+13-1
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,17 @@ div#list-of-available-icons > blockquote > div > div > p {
9595
}
9696

9797
.wy-nav-content {
98-
max-width: max(800px, calc(100vw - 600px)) !important;
98+
max-width: clamp(800px, calc(100vw - 600px), 1200px) !important;
99+
}
100+
101+
.wy-nav-content section {
102+
max-width: 900px;
103+
}
104+
105+
table.docutils {
106+
min-width: 50%;
107+
}
108+
109+
#code-style table.docutils {
110+
width: 100%;
99111
}

developer_manual/docutils.conf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[restructuredtext parser]
2+
tab_width: 4
3+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
=============================
2+
CSS and HTML coding standards
3+
=============================
4+
5+
HTML
6+
----
7+
8+
- HTML should be HTML5 compliant
9+
- Avoid more than one tag per line
10+
- Always indent blocks
11+
- Try to avoid IDs inst
12+
13+
**DO**
14+
15+
.. code-block:: html
16+
17+
<button>
18+
<span class="icon icon-close"></span>
19+
Close
20+
</button>
21+
22+
**DON'T**
23+
24+
.. code-block:: html
25+
26+
<button><span class="icon icon-close"></span>Close</button>
27+
28+
CSS
29+
---
30+
31+
- Do not bind your CSS to much to your HTML structure.
32+
- Try to avoid IDs for query selectors but use classes.
33+
- Try to make your CSS reusable by grouping common attributes into classes.
34+
- Take a look at the `Writing Tactical CSS & HTML <https://www.youtube.com/watch?v=hou2wJCh3XE&feature=plcp>`_ video on YouTube.
35+
36+
**DO**:
37+
38+
.. code-block:: css
39+
40+
.list {
41+
list-style-type: none;
42+
}
43+
44+
.list > .list__item {
45+
display: inline-block;
46+
}
47+
48+
.important_list_item {
49+
color: red;
50+
}
51+
52+
**DON'T**:
53+
54+
.. code-block:: css
55+
56+
#content .myHeader ul {
57+
list-style-type: none;
58+
}
59+
60+
#content .myHeader ul li.list_item {
61+
color: red;
62+
display: inline-block;
63+
}
64+
65+
Naming convention
66+
^^^^^^^^^^^^^^^^^
67+
68+
We recommend to use the BEM (Block-Element-Modifier) naming convention for CSS classes.
69+
BEM helps with making CSS reusable and better maintainable, especially when using pre-processors like SASS.
70+
71+
**DO**:
72+
73+
.. code-block:: css
74+
75+
.button {
76+
background-color: var(--color-main-background);
77+
}
78+
79+
.button--primary {
80+
background-color: var(--color-primary);
81+
}
82+
83+
.button__icon {
84+
width: 20px;
85+
}
86+
87+
**DON'T**:
88+
89+
.. code-block:: css
90+
91+
button.btn {
92+
background-color: var(--color-main-background);
93+
}
94+
95+
button.btn.primary {
96+
background-color: var(--color-primary);
97+
}
98+
button.btn span.myIcon {
99+
width: 20px;
100+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
=================================
2+
Coding style & general guidelines
3+
=================================
4+
5+
6+
General
7+
-------
8+
9+
* Ideally, discuss your plans on the `forums <https://help.nextcloud.com>`_ to see if others want to work with you on it
10+
* We use `GitHub <https://github.com/nextcloud>`_, please get an account there and clone the repositories you want to work on
11+
* Fixes go directly to the main branch, nevertheless they need to be tested thoroughly.
12+
* New features are always developed in a branch and only merged to the main branch once they are fully done.
13+
* Software should work. We only put features into the main branch when they are complete.
14+
It's better to not have a feature instead of having one that works poorly.
15+
* It is best to start working based on an issue - create one if there is none.
16+
You describe what you want to do, ask feedback on the direction you take it and take it from there.
17+
* When you are finished, use the merge request function on GitHub to create a pull request.
18+
The other developers will look at it and give you feedback. You can signify that your PR is ready for review by adding the label "3. to review" to it.
19+
See `the code review page for more information <../prologue/bugtracker/codereviews.html>`_
20+
* It is key to keep changes separate and small. The bigger and more hairy a PR grows, the harder it is to get it in.
21+
So split things up where you can in smaller changes - if you need a small improvement like a API addition for a big feature addition, get it in first rather than adding it to the big piece of work!
22+
* Decisions are made by consensus. We strive for making the best technical decisions and as nobody can know everything, we collaborate.
23+
That means a first negative comment might not be the final word, neither is positive feedback an immediate GO. Nextcloud is built out of modular pieces (apps) and maintainers have a strong influence.
24+
In case of disagreement we consult other seasoned contributors.
25+
26+
Labels
27+
------
28+
29+
We assign labels to issues and pull requests to make it easy to find them and to signal what needs to be done.
30+
Some of these are assigned by the developers, others by QA, bug triagers, project lead or maintainers and so on.
31+
It is not desired that users/reporters of bugs assign labels themselves, unless they are developers/contributors to Nextcloud.
32+
33+
The most important labels and their meaning:
34+
35+
* Tags showing the state of the issue or PR, numbered 0-4:
36+
37+
* ``0. to triage`` - issue or feature request needs to get triaged and approved for development
38+
* ``1. to develop`` - ready to start development on this
39+
* ``2. developing`` - development in progress
40+
* ``3. to review`` - ready for review
41+
* ``4. to release`` - reviewed PR that awaits unfreeze of a branch to get merged or has pending CI jobs
42+
* ``needs info`` - this issue needs further information from the reporter, see :doc:`../../prologue/bugtracker/triaging`.
43+
This tag is typically combined with ``0. to triage`` to signal a bug report is not confirmed yet or a feature request has not been approved.
44+
45+
* Tags showing the type of issue or PR
46+
47+
* ``bug`` - this issue is a bug
48+
* ``enhancement`` - this issue is a feature request/idea for improvement of Nextcloud
49+
* ``technical debt`` - this issue or PR is about `technical debt <https://en.wikipedia.org/wiki/Technical_debt>`_
50+
51+
* Tags that classify an issue or PR
52+
53+
* ``high``, ``medium`` and ``low`` – signify how important the bug is.
54+
* ``regression`` - something that worked in a previous release but is now not working as expected or missing.
55+
* ``feature: *``, e.g. ``feature: dav`` – these tags group tickets of specific feature or subsystems.
56+
* ``design`` - this needs help from the design team or is a design-related issue/pull request
57+
* ``good first issue`` - these are issues which are relatively easy to solve and ideal for people who want to learn how to code in Nextcloud
58+
59+
* ``backport-request`` - the pull requests also needs to be applied to older Nextcloud versions. This tag is typically assigned by automation.
60+
61+
User interface
62+
--------------
63+
64+
* Software should get out of the way. Do things automatically instead of offering configuration options.
65+
* Software should be easy to use. Show only the most important elements. Secondary elements only on hover or via Advanced function.
66+
* User data is sacred. Provide undo instead of asking for confirmation - `which might be dismissed <http://www.alistapart.com/articles/neveruseawarning/>`_
67+
* The state of the application should be clear. If something loads, provide feedback.
68+
* Do not adapt broken concepts (for example design of desktop apps) just for the sake of consistency. We aim to provide a better interface, so let's find out how to do that!
69+
* Regularly reset your installation to see how the first-run experience is like. And improve it.
70+
* Ideally do `usability testing <http://jancborchardt.net/usability-in-free-software>`_ to know how people use the software.
71+
* For further UX principles, read `Alex Faaborg from Mozilla <http://uxmag.com/articles/quantifying-usability>`_.
72+
73+
Coding standards
74+
----------------
75+
76+
* Maximum line-length of 80 characters
77+
* Use tabs to indent
78+
* A tab is 4 spaces wide
79+
* Opening braces of blocks are on the same line as the definition
80+
* Quotes: ' for everything, " for HTML attributes (<p class="my_class">)
81+
* End of Lines : Unix style (LF / '\n') only
82+
* No global variables or functions
83+
* Code should be tested, ideally with unit and integration tests.
84+
* When you ``git pull``, always ``git pull --rebase`` to avoid generating extra commits like: *merged main into main*
85+
86+
The most part of Nextcloud is written in PHP, Typescript / JavaScript, so we have some more fine grained coding standards for those languages:
87+
88+
.. toctree::
89+
:maxdepth: 1
90+
91+
php
92+
javascript
93+
html_css
94+
95+
License headers
96+
---------------
97+
98+
Nextcloud is licensed under the `GNU AGPLv3 <https://www.gnu.org/licenses/agpl>`_.
99+
From June, 16 2016 on we switched to "GNU AGPLv3 or any later version" for better long-term maintainability.
100+
101+
If you create a new file please use this header:
102+
103+
.. code-block:: php
104+
105+
/**
106+
* SPDX-FileCopyrightText: [year] [your name] [<your email address>]
107+
* SPDX-License-Identifier: AGPL-3.0-or-later
108+
*/
109+
110+
The year should then be the creation time and the email address is optional.
111+
112+
If you edit an existing file please, please keep the existing license header as it is and just add your copyright notice, if you consider your changes substantial enough to claim copyright.
113+
114+
In order to do so there are two options:
115+
116+
* If a generic header is already present, please just add yourself to the AUTHORS.md file
117+
* If no generic header is present, you can add yourself with a copyright line as described above. As a rule of thumb, this is the case if you contributed more than seven lines of code.
118+
119+
An example of a generic license header where adding yourself to the AUTHORS.md
120+
file is preferred please see the example below
121+
122+
.. code-block:: php
123+
124+
/**
125+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
126+
* SPDX-License-Identifier: AGPL-3.0-or-later
127+
*/
128+
129+
The Nextcloud GmbH part only applies to employees of the company not to contributors.
130+
131+
For more, general information on SPDX headers and their usage for reuse-compliance, please see
132+
133+
* `REUSE <https://reuse.software/>`_
134+
* `SPDX <https://spdx.dev/>`_
135+

0 commit comments

Comments
 (0)