diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts
index a1a64294..3e0caabc 100644
--- a/docs/.vitepress/config.ts
+++ b/docs/.vitepress/config.ts
@@ -89,4 +89,11 @@ export default defineConfig({
{ icon: 'github', link: 'https://github.com/rrd108/vue-mess-detector' },
],
},
+ markdown: {
+ theme: {
+ light: 'vitesse-light',
+ dark: 'vitesse-dark',
+ },
+ lineNumbers: true,
+ },
})
diff --git a/docs/rules/rrd/cyclomatic-complexity.md b/docs/rules/rrd/cyclomatic-complexity.md
index f371a556..87465849 100644
--- a/docs/rules/rrd/cyclomatic-complexity.md
+++ b/docs/rules/rrd/cyclomatic-complexity.md
@@ -15,3 +15,61 @@ The more decision points a component has, the more complex it is. High complexit
- **Maintainability:** Components with high complexity are harder to maintain. By keeping complexity low, you make your code easier to maintain.
- **Scalability:** As your application grows, keeping complexity low helps manage complexity.
- **Performance:** Components with high complexity can be slower to render. By keeping complexity low, you can improve performance.
+
+## π± Examples of code for which this rule will throw a warning
+
+::: warning
+The following code has a high cyclomatic complexity, which means it contains too many decision points (such as `if`, `for`, `while` statements). High complexity can make the code difficult to understand, maintain, and test.
+:::
+
+```vue
+
+```
+
+In this example, the code's cyclomatic complexity is high due to multiple nested conditionals and loops, making the logic harder to follow and increasing the chances of bugs.
+
+## π€© How to fix it?
+
+::: tip
+To improve the code, consider refactoring to reduce the number of decision points and simplify the logic. You can break down the logic into smaller, more focused functions or components, each with lower complexity.
+:::
+
+```vue
+
+```
+
+In the refactored example, the complex nested logic is moved into separate functions or composables (`handleCondition1`, `handleCondition2`), reducing the overall cyclomatic complexity of the script. This makes the code more modular, easier to test, and maintain.
diff --git a/docs/rules/rrd/deep-indentation.md b/docs/rules/rrd/deep-indentation.md
index 26bf5891..68c201a2 100644
--- a/docs/rules/rrd/deep-indentation.md
+++ b/docs/rules/rrd/deep-indentation.md
@@ -1,3 +1,49 @@
# Deep Indentation
Checks if the indentation of the component is too deep. The default for `tabs` is 5, for `spaces` is 15.
+
+## π± Examples of code for which this rule will throw a warning
+
+::: warning
+The following code contains deep indentation, which can make the code harder to read and maintain. Excessive indentation often indicates that the code is doing too much in a single function or component, and it may benefit from refactoring.
+:::
+
+```vue
+
+```
+
+In this example, the code inside the `
+```
+
+In the refactored example, the deeply nested logic is moved into a separate function or even a custom composable (like useHandleCondition), which reduces the indentation level and makes the main code more concise and easier to read.
diff --git a/docs/rules/rrd/else-condition.md b/docs/rules/rrd/else-condition.md
index d18da564..69c2c508 100644
--- a/docs/rules/rrd/else-condition.md
+++ b/docs/rules/rrd/else-condition.md
@@ -8,3 +8,35 @@ Checks if there are any `else` condition in the `script` block. This is a code s
- **Maintainability**: Code without `else` conditions is easier to maintain and refactor.
- **Testability**: Code without `else` conditions is easier to test.
+## π± Examples of code for which this rule will throw a warning
+
+::: danger
+The following code contains an else clause. It indicates that the logic could potentially be simplified to avoid using the else statement altogether.
+:::
+
+```javascript
+function checkUserStatus(isLoggedIn) {
+ if (isLoggedIn) {
+ console.log('Welcome back!')
+ }
+ else {
+ console.log('Please log in.')
+ }
+}
+```
+
+## π€© How to fix it?
+
+::: tip
+Refactor the code to avoid the else clause by using a guard clause or combining the conditions into a single if statement. This will enhance readability and reduce complexity.
+:::
+
+```javascript
+function checkUserStatus(isLoggedIn) {
+ if (!isLoggedIn) {
+ console.log('Please log in.')
+ return // Early return to eliminate else
+ }
+ console.log('Welcome back!')
+}
+```
diff --git a/docs/rules/rrd/function-size.md b/docs/rules/rrd/function-size.md
index f4aa0fc9..51e53227 100644
--- a/docs/rules/rrd/function-size.md
+++ b/docs/rules/rrd/function-size.md
@@ -8,3 +8,116 @@ Checks if functions inside `script setup` block are less than 20 lines of code.
- **Readability**: Smaller functions are easier to read and understand.
- **Maintainability**: Smaller functions are easier to maintain and refactor.
- **Testability**: Smaller functions are easier to test.
+
+## π± Examples of code for which this rule will throw a warning
+
+::: warning
+The following code contains functions that exceed the recommended size limit. Large functions can be difficult to read, understand, and maintain.
+:::
+
+```javascript
+function dummyRegularFunction() {
+ const firstName = 'john'
+ const lastName = 'doe'
+ const age = 30
+
+ if (age < 18) {
+ console.log('Too young for this function!')
+ }
+ else {
+ console.log('Hello ', firstName)
+ }
+
+ const hobbies = ['reading', 'gaming', 'cooking']
+ for (const hobby of hobbies) {
+ console.log('I enjoy ', hobby)
+ }
+
+ const getRandomNumber = () => Math.floor(Math.random() * 100)
+ const randomNum = getRandomNumber()
+ console.log('Random number: ', randomNum)
+
+ return 'Function execution complete!'
+}
+```
+
+Another example with an arrow function:
+
+```javascript
+const getOpenBookings = page =>
+ axios
+ .get(`${import.meta.env.VITE_APP_API_URL}bookings/listOpen.json?page=${page}`, store.tokenHeader)
+ .then((res) => {
+ bookings.value = res.data.bookings
+ paginate.value = res.data.paginate
+
+ const hobbies = ['reading', 'gaming', 'cooking']
+ for (const hobby of hobbies) {
+ console.log('I enjoy ', hobby)
+ }
+
+ bookings.value = res.data.bookings
+ paginate.value = res.data.paginate
+ bookings.value = res.data.bookings
+ paginate.value = res.data.paginate
+ bookings.value = res.data.bookings
+ paginate.value = res.data.paginate
+ // Additional repetitive lines...
+ })
+ .catch(err => console.error(err))
+```
+
+## π€© How to fix it?
+
+::: tip
+Refactor the function to reduce its size by breaking it down into smaller, more focused functions. This improves readability, testability, and maintainability.
+:::
+
+For the first example:
+
+```javascript
+function logAgeMessage(age) {
+ if (age < 18) {
+ console.log('Too young for this function!')
+ }
+ else {
+ console.log('Hello ', firstName)
+ }
+}
+
+function listHobbies(hobbies) {
+ for (const hobby of hobbies) {
+ console.log('I enjoy ', hobby)
+ }
+}
+
+function dummyRegularFunction() {
+ const firstName = 'john'
+ const lastName = 'doe'
+ const age = 30
+
+ logAgeMessage(age)
+ listHobbies(['reading', 'gaming', 'cooking'])
+
+ const randomNum = Math.floor(Math.random() * 100)
+ console.log('Random number: ', randomNum)
+
+ return 'Function execution complete!'
+}
+```
+
+For the arrow function:
+
+```javascript
+const handleResponse = (res) => {
+ bookings.value = res.data.bookings
+ paginate.value = res.data.paginate
+ // Handle repetitive logic here or refactor further
+}
+
+const getOpenBookings = page =>
+ axios
+ .get(`${import.meta.env.VITE_APP_API_URL}bookings/listOpen.json?page=${page}`, store.tokenHeader)
+ .then(handleResponse)
+ .catch(err => console.error(err))
+```
diff --git a/docs/rules/rrd/parameter-count.md b/docs/rules/rrd/parameter-count.md
index 83bdde53..3cc9d99a 100644
--- a/docs/rules/rrd/parameter-count.md
+++ b/docs/rules/rrd/parameter-count.md
@@ -1,3 +1,49 @@
# Parameter Count
Checks if functions inside `script setup` block have less than 4 parameters. It handles regular and arrow functions.
+
+## π± Examples of code for which this rule will throw a warning
+
+::: warning
+The following code contains functions that exceed the recommended limit on the number of parameters. Having too many parameters in a function can make the code harder to understand and maintain.
+:::
+
+```javascript
+function dummyFuncOne(param1, param2, param3, param4, param5) {
+ return 'One'
+}
+```
+
+Another example with an arrow function:
+
+```javascript
+const dummyFuncTwo = (param1, param2, param3, param4) => {
+ return 'Two'
+}
+```
+
+## π€© How to fix it?
+
+::: tip
+Refactor the function to reduce the number of parameters by using objects, destructuring, or considering whether all parameters are necessary. This will improve readability and maintainability.
+:::
+
+For the first example:
+
+```javascript
+function dummyFuncOne({ param1, param2, param3, param4, param5 }) {
+ return 'One'
+}
+```
+
+In this refactor, the parameters are combined into a single object, making the function call cleaner and easier to understand. Alternatively, if not all parameters are needed at the same time, consider splitting the function or removing unnecessary parameters.
+
+For the arrow function:
+
+```javascript
+const dummyFuncTwo = ({ param1, param2, param3, param4 }) => {
+ return 'Two'
+}
+```
+
+This refactor also combines parameters into an object, reducing the cognitive load when using the function. This approach can help avoid the issue of excessive parameters while keeping the codebase clean and maintainable.
diff --git a/docs/rules/rrd/plain-script.md b/docs/rules/rrd/plain-script.md
index 324a7ecb..e44455b7 100644
--- a/docs/rules/rrd/plain-script.md
+++ b/docs/rules/rrd/plain-script.md
@@ -1,3 +1,46 @@
# Plain Script
Checks if the script section of a Vue component is not using `
+```
+
+## π€© How to fix it?
+
+::: tip
+Convert the plain `
+```
+
+By using `
+```
+
+In this example, the `
+```
diff --git a/docs/rules/rrd/short-variable-name.md b/docs/rules/rrd/short-variable-name.md
index e521e824..13c45394 100644
--- a/docs/rules/rrd/short-variable-name.md
+++ b/docs/rules/rrd/short-variable-name.md
@@ -1,3 +1,35 @@
# Short Variable Name
Checks if variable names inside `
+```
+
+In the example above, the variables `age`, `x`, and `y` are too short and lack meaningful context, which could confuse other developers who might not know what these variables represent.
+
+## π€© How to fix it?
+
+::: tip
+Refactor the code to use more descriptive variable names. This improves readability and makes the code more self-explanatory.
+:::
+
+```vue
+
+```
+
+In the refactored example, `userAge`, `maxItems`, and `greetingMessage` are descriptive and provide clear context, making the code easier to understand and maintain.
diff --git a/docs/rules/rrd/too-many-props.md b/docs/rules/rrd/too-many-props.md
index a6b05e6a..bf8ede1e 100644
--- a/docs/rules/rrd/too-many-props.md
+++ b/docs/rules/rrd/too-many-props.md
@@ -1,3 +1,50 @@
## Too many props
Checks if the component got more then 5 props.
+
+## π± Examples of code for which this rule will throw a warning
+
+::: warning
+The following code contains a `
+```
+
+In this example, the component defines 6 props, which exceeds the recommended limit of 5. This can make the component harder to maintain and may indicate that the component is handling too much responsibility.
+
+## π€© How to fix it?
+
+::: tip
+To improve maintainability, consider refactoring the component to reduce the number of props. This can be achieved by either breaking the component into smaller, more focused components, or by grouping related props into a single object prop.
+:::
+
+```vue
+
+```
+
+In the refactored example, the props are grouped into two objects, meta and interaction, reducing the overall number of props and making the component easier to manage and understand.
diff --git a/docs/rules/vue-caution/element-selectors-with-scoped.md b/docs/rules/vue-caution/element-selectors-with-scoped.md
index 5617690d..8c7070af 100644
--- a/docs/rules/vue-caution/element-selectors-with-scoped.md
+++ b/docs/rules/vue-caution/element-selectors-with-scoped.md
@@ -15,3 +15,54 @@ The benchmark results clearly indicate that **class selectors consistently outpe
> [!IMPORTANT]
> These findings suggest that using class selectors can lead to more efficient performance, especially in scenarios with a large number of elements. Therefore, for better performance in styling large-scale web applications **class selectors should be preferred** over element selectors.
+
+## π± Examples of code for which this rule will throw a warning
+
+::: warning
+Using element selectors within scoped styles can lead to performance issues and conflicts. The following example demonstrates how element selectors are being used incorrectly within scoped styles:
+:::
+
+```vue
+
+```
+
+In this example, the `button` and `div` element selectors are applied within a `scoped style` block. This can be problematic because it increases the specificity and the likelihood of performance degradation, especially when there are many such selectors.
+
+## π€© How to fix it?
+
+::: tip
+To improve performance and avoid conflicts, replace element selectors with class selectors. This ensures that styles are scoped more effectively and are less likely to impact other parts of the application.
+:::
+
+```vue
+
+
+
@@ -13,3 +12,122 @@ Checks if props and events are used for parent-child component communication, in
- **Testing:** Components are easier to test in isolation when they rely on props and events rather than direct parent access.
- **Scalability:** As your application grows, consistent use of props and events helps manage complexity.
- **Prevents unexpected side effects:** Avoiding prop mutation reduces the risk of unexpected changes to parent state.
+
+## π± Examples of code for which this rule will throw a warning
+
+::: warning
+Implicit parent-child communication can lead to unmanageable code and unexpected behavior. The following examples demonstrate cases where implicit communication occurs, such as *prop mutation* or using *$parent* or *getCurrentInstance*.
+:::
+
+### Example 1: Prop Mutation
+```js
+
+
+
+ // [!code warning]
+
+```
+
+In this example, the `v-model` directive directly mutates the `todo` prop, which is passed down from a parent component. This implicit communication can make the flow of data hard to follow.
+
+### Example 2: Using getCurrentInstance
+```vue{11,18-20}
+
+
+
+
+ {{ todo.text }}
+
+
+
+```
+
+In this example, the `getCurrentInstance` function is used to access the parent componentβs properties, leading to an implicit and tight coupling between the parent and child components.
+
+## π€© How to fix it?
+
+::: tip
+To avoid implicit parent-child communication, ensure that data flow is explicit and clear. Here are some strategies:
+:::
+
+### Fixing `Prop Mutation`
+Instead of mutating props directly, emit an event to the parent component to handle the change:
+```vue
+
+
+
+
+
+```
+
+### Fixing `getCurrentInstance`
+
+Instead of accessing the parent component via `getCurrentInstance`, pass down a callback function as a prop to handle the logic in the parent:
+```vue
+
+
+
+
+ {{ todo.text }}
+
+
+
+```
+
+By refactoring in this way, the component maintains clear and predictable behavior without relying on implicit communication, making the codebase easier to manage and debug.
diff --git a/docs/rules/vue-essential/global-style.md b/docs/rules/vue-essential/global-style.md
index e92ba328..c0e41971 100644
--- a/docs/rules/vue-essential/global-style.md
+++ b/docs/rules/vue-essential/global-style.md
@@ -9,3 +9,38 @@ Checks if the component is using global styles instead of `scoped` styles.  
- **Isolation** the component is isolated and has no unwanted effect on the other parts of the application.
- **Reusability** the component can be reused in other parts of the application with exactly the same look and feel.
+## π± Examples of code for which this rule will throw a warning
+
+::: warning
+The following code contains global styles, which may affect other components unintentionally.
+:::
+
+```js
+
+ Hello World
+
+
+
+```
+
+## π€© How to fix it?
+
+::: tip
+Refactor the code to use scoped styles by adding the scoped attribute to the `
+```
diff --git a/docs/rules/vue-essential/simple-prop.md b/docs/rules/vue-essential/simple-prop.md
index 204b52dc..5445d2d4 100644
--- a/docs/rules/vue-essential/simple-prop.md
+++ b/docs/rules/vue-essential/simple-prop.md
@@ -6,3 +6,29 @@ Checks if the component is using simple props definitions.
## β Why it's good to follow this rule?
- **Readability** the component is easier to understand in details.
+
+## π± Examples of code for which this rule will throw a warning
+
+::: warning
+The following code uses simple props definitions without specifying types, which can lead to unclear prop validation and potential runtime errors.
+:::
+
+```vue
+
+```
+
+## π€© How to fix it?
+
+::: tip
+Refactor the code to use detailed props definitions with type annotations to ensure better type safety and clarity.
+:::
+
+```vue
+
+```
diff --git a/docs/rules/vue-essential/single-name-component.md b/docs/rules/vue-essential/single-name-component.md
index 55585f40..4338ae84 100644
--- a/docs/rules/vue-essential/single-name-component.md
+++ b/docs/rules/vue-essential/single-name-component.md
@@ -7,3 +7,37 @@ Checks if the component name is a single word.
- **Consistency** the component name is consistent with the other components.
- **Readability** the component name is more descriptive about its goal.
+
+## π± Examples of code for which this rule will throw a warning
+
+::: warning
+The following code defines a component with a single-word name, which does not comply with the recommended naming conventions for Vue components.
+:::
+
+```vue
+// components/Header.vue
+
+
+
+ Header
+
+```
+
+## π€© How to fix it?
+
+::: tip
+Refactor the component name to use a multi-word format, which improves clarity and avoids potential naming conflicts.
+:::
+
+```vue
+// components/AppHeader.vue
+
+
+
+ Header
+
+```
diff --git a/docs/rules/vue-essential/vfor-no-key.md b/docs/rules/vue-essential/vfor-no-key.md
index ede60937..2d38ae1a 100644
--- a/docs/rules/vue-essential/vfor-no-key.md
+++ b/docs/rules/vue-essential/vfor-no-key.md
@@ -7,3 +7,35 @@ Checks if the component is using `v-for` without a `key` property. <
- **Performance** adding a `key` property to the `v-for` loop helps Vue to identify the elements and update only the changed elements.
- In certain situations a missing `key` property can lead to unexpected behavior.
+
+## π± Examples of code for which this rule will throw a warning
+
+::: warning
+The following code uses `v-for` without a key property, which can lead to rendering issues and decreased performance.
+:::
+
+```js
+
+
+
+
+```
+
+## π€© How to fix it?
+
+::: tip
+Add a `:key` property to the `v-for` directive to uniquely identify each element in the loop.
+:::
+
+```vue /3/
+
+
+
+
+```
diff --git a/docs/rules/vue-essential/vif-with-vfor.md b/docs/rules/vue-essential/vif-with-vfor.md
index 8026ba7e..b16ccbd4 100644
--- a/docs/rules/vue-essential/vif-with-vfor.md
+++ b/docs/rules/vue-essential/vif-with-vfor.md
@@ -7,3 +7,51 @@ Checks if the component is using `v-if` with `v-for`.
- **Performance** using `v-if` with `v-for` can lead to performance issues.
- **Readability** the component is easier to understand and maintain.
+
+## π± Examples of code for which this rule will throw a warning
+
+::: warning
+The following code uses `v-if` together with `v-for`, which is not recommended as it can lead to performance issues and inefficient rendering.
+:::
+
+```vue{4-5}
+
+
+
+
+```
+
+## π€© How to fix it?
+
+::: tip
+Refactor the code to use a computed property that filters the users before rendering them, eliminating the need for `v-if` within the loop.
+:::
+
+```vue
+
+
+
+
+
+
+```
diff --git a/docs/rules/vue-recommended/element-attribute-order.md b/docs/rules/vue-recommended/element-attribute-order.md
index 37fd5450..afbdcd53 100644
--- a/docs/rules/vue-recommended/element-attribute-order.md
+++ b/docs/rules/vue-recommended/element-attribute-order.md
@@ -6,3 +6,50 @@ Checks if the component always uses `is`, `v-for`, `v-if`, `v-else-if`, `v-else`
## β Why it's good to follow this rule?
- **Consistency:** It makes the code consistent and easier to maintain.
+
+## π± Examples of code for which this rule will throw a warning
+
+::: warning
+The attributes of elements (including components) should be ordered consistently. The following examples illustrate cases where the attribute order is incorrect.
+:::
+
+### Example 1: Incorrect Attribute Order
+```html
+
+
+
+```
+
+In this example, the attributes of the `` element are out of order. The `@input` directive should come after `v-model` to maintain consistent attribute ordering.
+
+### Example 2: Incorrect Attribute Order in a Different Element
+
+```html
+
+
+
+```
+
+In this example, the attributes of the `