You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7b6c4f4
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: developer_manual/getting_started/coding_standards/javascript.rst
+64-45Lines changed: 64 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,15 +11,34 @@ General rules and advice
11
11
- Nextcloud uses Vue.js for its interface, for a consistent user interface we recommend apps to also use Vue with :ref:`provided components <js-library_nextcloud-vue>`.
12
12
Yet also vanilla JavaScript and HTML can be used.
13
13
- We recommend using Typescript for its type checking and improved static code analysis features.
14
-
- Do not create global variables, instead if needed use global namespace objects like ``OCA.YourApp.…``
14
+
- Do not create global variables, instead if needed use global namespace objects like ``OCA.YourApp.…``
15
15
- Use JavaScript strict mode (automatically the case when using JavaScript modules)
16
16
17
17
ESLint config
18
18
^^^^^^^^^^^^^
19
19
20
20
There is a shared configuration for `eslint <https://eslint.org/>`_ that you can use to automatically format your Nextcloud apps's JavaScript and Typescript code.
21
21
It consists of two parts: a `config package <https://github.com/nextcloud-libraries/eslint-config>`_ that contains the formatting preferences
22
-
and a `plugin <https://github.com/nextcloud-libraries/eslint-plugin>`_ to detect deprecated and removed APIs in your code. See their readmes for instructions.
22
+
and a `plugin <https://github.com/nextcloud-libraries/eslint-plugin>`_ to detect deprecated and removed APIs in your code.
23
+
24
+
Install the shared config (it pulls in ESLint and the Nextcloud plugin):
25
+
26
+
.. code-block:: bash
27
+
28
+
npm install --save-dev @nextcloud/eslint-config
29
+
30
+
Add an ``eslint.config.js`` in your app root using the flat config format (required since ``@nextcloud/eslint-config`` v9 / ESLint 9+):
``recommended`` covers TypeScript and Vue 3. Alternatives such as ``recommendedJavascript`` and ``recommendedVue2`` are documented in the `config package README <https://github.com/nextcloud-libraries/eslint-config>`_.
41
+
See also :ref:`app-npm` for the ``lint`` / ``lint:fix`` npm scripts.
23
42
24
43
Filesystem structure
25
44
^^^^^^^^^^^^^^^^^^^^
@@ -79,16 +98,16 @@ Naming and casing
79
98
80
99
- For readability only capitalize the first letter of abbreviations like ``callHttpApi()`` instead of ``callHTTPAPI()``.
81
100
- Sub-components should be prefixed.
82
-
E.g. splitting a component like ``FileListEntry`` into smaller components called ``FileListEntryName``, ``FileListEntryIcon`` …
101
+
E.g. splitting a component like ``FileListEntry`` into smaller components called ``FileListEntryName``, ``FileListEntryIcon`` …
83
102
- Components should not have single-word names, this could conflict with current or future native HTML tags as these are always single-word.
84
103
E.g. if you have a settings view, do not call it ``Settings`` but ``SettingsView`` or ``UserSettings`` etc.
85
104
86
105
.. list-table:: Use camelCase for functions, methods, properties, and variables
Copy file name to clipboardExpand all lines: developer_manual/getting_started/coding_standards/php.rst
+46Lines changed: 46 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,52 @@ PHP coding standards
4
4
5
5
Starting with Nextcloud 19 there is a shared `PHP Coding Standards Fixer <https://github.com/FriendsOfPhp/PHP-CS-Fixer>`_ configuration you can use to automatically format your app's source code. For full details see the `repository on GitHub <https://github.com/nextcloud/coding-standard/>`_.
6
6
7
+
Setup
8
+
-----
9
+
10
+
Install the shared configuration as a development dependency:
11
+
12
+
.. code-block:: bash
13
+
14
+
composer require --dev nextcloud/coding-standard
15
+
16
+
Create a ``.php-cs-fixer.dist.php`` in your app root:
17
+
18
+
.. code-block:: php
19
+
20
+
<?php
21
+
22
+
declare(strict_types=1);
23
+
24
+
require_once './vendor/autoload.php';
25
+
26
+
use Nextcloud\CodingStandard\Config;
27
+
28
+
$config = new Config();
29
+
$config
30
+
->getFinder()
31
+
->ignoreVCSIgnored(true)
32
+
->notPath('build')
33
+
->notPath('l10n')
34
+
->notPath('src')
35
+
->notPath('vendor')
36
+
->in(__DIR__);
37
+
return $config;
38
+
39
+
Add convenience scripts to ``composer.json``:
40
+
41
+
.. code-block:: json
42
+
43
+
{
44
+
"scripts": {
45
+
"cs:check": "php-cs-fixer fix --dry-run --diff",
46
+
"cs:fix": "php-cs-fixer fix"
47
+
}
48
+
}
49
+
50
+
Then run ``composer cs:check`` to list violations, or ``composer cs:fix`` to apply fixes.
51
+
Exclude ``.php-cs-fixer.dist.php`` and ``.php-cs-fixer.cache`` from your release build.
0 commit comments