@@ -18,28 +18,59 @@ If you have a feature request or want to fix a bug, feel free to:
18
18
19
19
---
20
20
21
+ ## Snippets Guidelines
22
+
23
+ ### Snippet Format
24
+
25
+ ** All** snippets should follow the following structure:
26
+ - A ` code ` segment, containing a function with the actual snippet functionnality
27
+ - An ` example ` segement, containing one or more examples of use
28
+
29
+ Example in javascript:
30
+ ``` js
31
+ function example (x ) {
32
+ return x * 2 ;
33
+ }
34
+
35
+ // Usage:
36
+ example (5 ) // Returns: 10
37
+ ```
38
+ If your function doesn't return anything just show how to use it. \
39
+ If the result of your function is too complicated to be expressed in a single comment, your snippet is probably too complex to begin with.
40
+
41
+ ### Snippet boundaries
42
+
43
+ To ** check if your snippet will not get refused** ask yourself those questions:
44
+ - ** Does the standard library of my language provide an easy way of doing this ?**
45
+ - ** Does that snippet have a real, and practical use case ?**
46
+ - ** Could it be split into separate parts to be better understood ?**
47
+
48
+ If one of question is true, then your snippet will most likely get refused !
49
+
50
+ ---
51
+
21
52
## Adding Snippets
22
53
23
54
### Adding a New Snippet
24
55
25
- To add a new code snippet:
56
+ 1 . ** Ensure your snippet match [ guidelines ] ( #snippets-guidelines ) **
26
57
27
- 1 . ** Navigate to the relevant folder:**
58
+ 2 . ** Navigate to the relevant folder:**
28
59
29
60
- Go to the ` /snippets ` folder in the root directory.
30
61
- Locate the folder for the programming language of your snippet, such as ` javascript ` or ` python ` .
31
62
32
- 2 . ** Choose the correct category:**
63
+ 3 . ** Choose the correct category:**
33
64
34
65
- Within the language folder, find the relevant category folder for your snippet.
35
66
- If no suitable category exists, refer to [ Adding a New Category] ( #adding-a-new-category ) .
36
67
37
- 3 . ** Create a markdown file:**
68
+ 4 . ** Create a markdown file:**
38
69
39
70
- Create a new file with a ` .md ` extension.
40
71
- Name the file appropriately, keeping it descriptive and concise.
41
72
42
- 4 . ** Add your snippet:**
73
+ 5 . ** Add your snippet:**
43
74
44
75
- Use the following format to structure your snippet:
45
76
@@ -74,11 +105,11 @@ console.log(formatDate(new Date())); // Output: '2024-12-10'
74
105
```
75
106
````
76
107
77
- 5 . ** Use syntax highlighting:**
108
+ 6 . ** Use syntax highlighting:**
78
109
- Enclose your code with triple backticks (```).
79
110
- Specify the language after the first set of backticks for syntax highlighting.
80
111
81
- 6 . ** Test your snippet:**
112
+ 7 . ** Test your snippet:**
82
113
- Ensure your code runs as expected. \
83
114
To test that your snippets are formatted correctly use the ` snippets:check ` script:
84
115
```
0 commit comments