Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Guidelines
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Redmine
Redmine
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
External
Guidelines
Commits
c65b3a5a
Commit
c65b3a5a
authored
Jun 26, 2017
by
Petr Hošek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JS first part
parent
a7d28090
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
0 deletions
+66
-0
JS/README.md
JS/README.md
+65
-0
README.md
README.md
+1
-0
No files found.
JS/README.md
0 → 100644
View file @
c65b3a5a
# EasyRedmine JavaScript guidelines
Main goal of this document is to highlight rules and recommendations for creation nice and maintainable JavaScript code.
## Rules strength
Rules described here comes at three different strengths.
-
DO or DON'T are mandatory for any Javascript code and it is valid reason for rejection of a merge request if not followed.
-
PREFER of AVOID is rules that should by followed but they are mandatory only for core implementation.
-
CONSIDER are not mandatory, but it makes the reviewer happy if they are followed
## Default rules
Code style defined in this document is based on W3C standard conventions:
[
JavaScript Coding Conventions
](
https://www.w3schools.com/js/js_conventions.asp
)
[
JavaScript Best Practices
](
https://www.w3schools.com/js/js_best_practices.asp
)
Exceptions from this coding styles will be described further
## Naming
-
DO name common variables with lowerCamelCase style. DON'T use snake_case or hyphens.
-
DO name classes with UpperCamelCase.
-
CONSIDER naming Constant also with lowerCamelCase
-
DO name variables with descriptive names, not by short variables as 'a'.
## Indentation + spaces
-
DO use spaces instead tabulators
-
PREFER use spaces around operators ( = + -
*
/ ), and after commas:
-
PREFER use 2 spaces as a 1 indentation step
-
PREFER use 4 spaces for continuation of previous line (if it is too long)
# Blocks
To prevent appearance of the pyramid of hell, this rules are given:
-
DO use at most 4 level of indentation.
You can use control statements to flatten the structure
```
javascript
// BAD
for
(
var
i
=
0
;
i
<
10
;
i
++
)
{
if
(
i
%
2
===
0
)
{
for
(
var
j
=
0
;
j
<
10
;
j
++
)
{
if
(
j
!==
i
)
{
// -- do something
}
}
}
}
// GOOD
for
(
var
i
=
0
;
i
<
10
;
i
++
)
{
if
(
i
%
2
!==
0
)
continue
;
for
(
var
j
=
0
;
j
<
10
;
j
++
)
{
if
(
j
===
i
)
continue
;
// -- do something
}
}
```
-
AVOID defining callback in callback
-
AVOID using very short blocks
```
javascript
var
a
=
5
;
// BAD
if
(
a
===
5
)
{
return
;
}
// GOOD
if
(
a
===
5
)
return
;
```
-
DON'T use multiline
`if`
statement without
`{}`
\ No newline at end of file
README.md
View file @
c65b3a5a
...
...
@@ -5,6 +5,7 @@
3.
Licence
4.
[
UI Guide
](
./UI/README.md
)
5.
[
DEV Guide
](
./DEV/README.md
)
6.
[
JS Guide
](
./JS/README.md
)
Easy Software Ltd.
https://www.easysoftware.com
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment