Hey there! Thanks for stopping by and considering contributing to this project. Whether you're fixing bugs, improving the code, or adding cool new snippets, your help means a lot. Before diving in, let's go over a few things to keep everything smooth and consistent.
- Contributing to SnipNest 🤝
- Share a better way to write something.
- Fixing bugs is always appreciated and makes a big difference.
- Submitting useful snippet ideas helps the entire community.
The only thing we ask is that you follow the rules below to keep everything tidy and easy to work with.
Snippets live in this structure:
snippets/language/category/snippet.mdx
Here's how it breaks down:
language
: Lowercase only. For example:JavaScript
->javascript
c++
→cpp
c#
→cs
category
andsnippet
: Use kebab-case. For example:lorem-ipsum
.
Every snippet must be a .mdx
file.
Each snippet file needs two things: metadata and code blocks.
At the very top of the file, include this export with the same order of properties, please check if another snippet has the same functionality but in another language, if so, please use the same name and description:
export const metadata = {
name: "Name of the snippet", // Use short and clear names.
description: "What the snippet does in a sentence or two", // Be concise and accurate.
keywords: ["keyword1", "keyword2", "keyword3"], // Add relevant keywords in kebab-case.
contributors: ["username"], // GitHub usernames only. Do not include @ symbols.
}; // Don't omit the semicolon.
Your snippet must have two code blocks (you can use only one, that being the actual snippet, if it's really short, an example is useful for example for pasting the snippet using the Visual Studio Code extension as it pastes the snippet and the example at the same time):
-
Snippet: This is the actual code. Annotate it with the language for syntax highlighting (use the supported languages list, react snippets that have HTML tags should use
tsx
).Example:
```javascript const add = (a, b) => a + b; ```
-
Example: Show how the snippet works with an example.
Example:
```javascript add(2, 3); // 5 ```
- No Duplicates: Don't submit a snippet that duplicates built-in language functionality.
- Clear Grammar: Ensure any error messages or text in the code is grammatically correct.
- Consistent Naming: Use precise and relevant terms (e.g.,
element
instead ofitem
for dictionaries), do not include the name of the category in the snippet's file name (e.g.,chunk.mdx
instead ofchunk-array.mdx
). - File Naming: File names should match the snippet name (in kebab-case). For instance, a snippet named
Random Element
should have a file namedrandom-element.mdx
. - Only Metadata and Code: Don't add unrelated markdown content outside of the required metadata and code blocks.
- Trailing Newline: Make sure the file does not end with a trailing newline.
If you're unsure about for example what the name of the snippet's file should be, ask in the Discussions or check out the other snippets.
If you're planning to submit a TypeScript snippet, check if it already exists for JavaScript. Only submit it if it has significant differences, like generics or type annotations.
Please use a regular function, not an arrow function.
If unsure, submit it anyway, and we'll help decide.
You can submit snippets in two ways: via CLI or manually.
The CLI simplifies generating new snippet files.
Note
The CLI is in beta but safe to use. It may change in future releases.
- Clone the repository.
- Install dependencies with
pnpm install
. - Run the CLI:
pnpm snipnest --new
- Follow the prompts to create your snippet.
- Review the generated
.mdx
file and make adjustments as needed. - Submit your work via a pull request.
- Navigate to the appropriate folder for the language and category. Create them if they don't exist.
- Add a
.mdx
file for your snippet. - Follow the guidelines above to structure and format your file.
- Submit your work via a pull request.
- Create a folder in
snippets/
with the language name in lowercase.- For example:
javascript
,python
,cpp
.
- For example:
- Add categories and snippets as needed.
- Update the language list in
lib/languages.ts
. Only use icons fromdevicons-react
orlucide-react
.
- Go to the appropriate language folder.
- Create a folder for the category in kebab-case.
- For example:
data-structures
,file-handling
.
- For example:
- Add snippets inside.
- Fork the repo and create a new branch for your changes.
- Make sure your snippet follows all the rules.
- Write a clear and descriptive pull request title.
- Add an explanation of your changes.
- Be ready to respond to feedback during the review.
If changes are minor or the PR is time-sensitive, maintainers may make the necessary updates and merge the PR on your behalf.
Thanks again for contributing! If you have questions or need help, don't hesitate to reach out. 😊