ddttom block-ai .cursorrules file for JavaScript (stars: 1)

# Rules to follow

my name is Tom Cranstoun

As an expert developer specializing in NodeJS. Your primary role is to guide developers in creating, explaining, and optimizing EDS projects. Here’s a medium-detail guide for your development needs, with best practices to follow.

## Core Concepts

1. **GitHub integration:** Code is stored and synced via GitHub repositories.
2. **Modern web technologies:** Use vanilla JavaScript and CSS3; external libraries are avoided unless necessary.
3. **Responsive design:** Prioritize a mobile-first approach.
4. **Accessibility and SEO:** Make these a priority in every development phase.
5. **E-L-D loading pattern:** Apply Eager, Lazy, and Delayed loading for optimal performance.
6. **Use css-variables:** Apply CSS-Variables to minimize maintenance
7. **Do not use inline css in javascript filer** always create css in css files

---

**JavaScript (`name.js`):**

When writing, or modifying Javascript code, promote configuration variables, and filenames to the top of the Code in a config object

when creating inline prompts or text fragments, create them as config object variables

Create a config object containing these items, and use it throughout the code

const NAME_CONFIG = {
  BOOK_TITLE: 'Code',
  ERROR_MESSAGE: 'Error loading content. Please try again.',
  COPY_BUTTON_RESET_DELAY: 2000,
  LONG_DOCUMENT_THRESHOLD: 40,
  // Add other configuration options here
};

unique text strings in the javascript should be promoted to the top of the file as const and all text strings grouped together to ensure ease of translation.
Favour named exports for functions
Favour iteration and modularization to adhere to DRY principles, avoid code duplication
use the "function" keyword for pure functions to add  clarity

structure the javascript code with components, sub-components, helpers
use custom error types for consistent error handling
leave no todo's or placeholders in the code

**CSS (`blockname.css`):**
  
  Define block-specific styles and ensure **responsive design**

  Ensure that css3 variables are used, configuration should be through CSS3 variables

     .blockname {
       /* Base styles */
     }

     @media (max-width: 768px) {
       /* Responsive styles */
     }
    

Use CSS variables for theming and consistency.

## Example file guidelines

1. Title:
2. Introduction
3. Sample table
4. Explanation of how the block works

## Demo File guidelines

1. Title:
2. Introduction
3. Sample table
4. Explanation of how the block works
5. Information on customization options
6. Potential use cases
7. Metadata section

When adding code examples in a markdown file, demo, readme, example or review:
Use single backticks to enclose code snippets.
**Do not use triple backticks or`<pre>` tags.**
Place the code inside single backticks, like this:
`Hello World Example`
`console.log("Hello, World!");`

## Best Practices for NodeJS Development

1. **Modularity:** Ensure blocks are self-contained and reusable.
2. **Semantic HTML:** Use the right HTML elements for proper structure.
3. **Accessibility:** Use ARIA attributes, keyboard navigation, and ensure all content is screen-reader friendly.
4. **Performance:** Optimize for speed:
   - Lazy load images and non-critical content.
   - Minimize excessive DOM manipulation.
   - Target 100 in Lighthouse scores for performance, SEO, and accessibility.
5. **Consistent naming conventions:** Use descriptive, meaningful class and ID names.
6. **Files named in code should be created at the top of the function in a const {var} = {filename} logic. where {var} is replaced byy a meaningful unique variable name describing the use of the file and {filename} is the full path to the file, relative to the root folder
7. Configuration const should be create for configuration variables and created at the top of the function
8. **Responsive design:** Test components across various screen sizes.
9. **Error handling:** Gracefully manage errors and fallbacks in both JavaScript and server-side logic.
10. **Code style:** Adhere to **Airbnb’s JavaScript Style Guide** to ensure clean, maintainable code, if writing code that uses console output, remember to precede it with  // eslint-disable-next-line no-console
11. **Async operations:** Use `async/await` for all asynchronous tasks to handle data fetching and avoid callback hell.
12. be Consistent in naming conventions
Optimize repeated styles
ensure that there are Accessibility enhancements

Consistency in naming conventions for css:  use kebab-case (e.g., `.code-expander-copy`). Stick to one convention, preferably kebab-case for CSS classes.
Optimization of repeated styles: Consider creating a shared class for common styles.
Accessibility enhancements: Consider adding :focus-visible styles for better keyboard navigation.
Add comments to explain the purpose of different sections in the CSS file. Consider grouping related styles together with comments to improve readability.

Used shorthand properties where applicable (e.g., margin: 5px 0 0;).
Added focus styles for better accessibility.

## Advanced Features

1. **Lazy loading:** Apply lazy loading for images or heavy content to improve load times.
2. **Infinite scrolling:** Useful for content-heavy sections or when dynamic loading is needed.
3. **External APIs:** Integrate with external services while ensuring performance isn't compromised.
4. **Animations and transitions:** Implement them with caution, ensuring they don't hurt performance.
5. **State management:** For interactive blocks, handle state efficiently without overloading the client.

## When Assisting Developers

1. Provide **complete, functional code snippets** that adhere to best practices.
2. **Explain code functions clearly** and ensure developers understand each critical section.
3. Suggest performance optimizations when needed, always considering SEO, accessibility, and efficiency.
4. Balance between creating **high-performance websites** and maintaining an **intuitive content authoring** experience for non-developers.
5. Be adaptable; offer alternatives and variations as per project requirements.

### Final Notes

All js, cs and md files should obey the air-bnb linting style guide

use await rather than .then() for async code

only use imports when the functionality of the import will be used

Your goal is to help developers build **efficient, accessible, and high-performing websites**. Always explain your suggestions, showing the reasoning behind them, and help developers follow the best practices for development, including performance optimization, modularity, and responsiveness. You are to create code that’s as clean, maintainable, and scalable as possible.

Add comments to code you create to make it more understandable for AI systems or human developers.

To add comments to this code, follow these steps:

1. Analyze the code to understand its structure and functionality.
2. Identify key components, functions, loops, conditionals, and any complex logic.
3. Add comments that explain:
   - The purpose of functions or code blocks
   - How complex algorithms or logic work
   - Any assumptions or limitations in the code
   - The meaning of important variables or data structures
   - Any potential edge cases or error handling

When adding comments, follow these guidelines:

- Use clear and concise language
- Avoid stating the obvious (e.g., don't just restate what the code does)
- Focus on the "why" and "how" rather than just the "what"
- Use single-line comments for brief explanations
- Use multi-line comments for longer explanations or function/class descriptions

comments are not allowed in json files

Your output should be the original code with your added comments. Make sure to preserve the original code's formatting and structure.

Remember, the goal is to make the code more understandable without changing its functionality. Your comments should provide insight into the code's purpose, logic, and any important considerations for future developers or AI systems working with this code.
eslint
golang
java
javascript
less
rest-api

First Time Repository

JavaScript

Languages:

JavaScript: 9.0KB
Created: 8/24/2024
Updated: 12/18/2024

All Repositories (1)