Utilizing ECMAScript 2024 Features for Modern JavaScript Development
Exploring new ECMAScript 2024 features such as Object.groupBy, Promise.withResolvers, and the /v flag in regular expressions to enhance JavaScript code.
0 likes
166 views
Rule Content
{
"title": "Utilizing ECMAScript 2024 Features for Modern JavaScript Development",
"description": "Enforce the use of ECMAScript 2024 features such as Object.groupBy, Promise.withResolvers, and the /v flag in regular expressions to enhance JavaScript code.",
"category": "JavaScript Cursor Rules",
"rules": [
{
"name": "prefer-object-groupby",
"description": "Encourage the use of Object.groupBy for grouping array elements based on a callback function.",
"applyTo": "src/**/*.js",
"pattern": "Array.prototype.reduce\\(.*\\{.*\\[.*\\].*\\}.*\\)",
"replacement": "Object.groupBy($1, $2)",
"message": "Consider using Object.groupBy for more concise and readable grouping of array elements."
},
{
"name": "prefer-promise-withresolvers",
"description": "Encourage the use of Promise.withResolvers for creating promises with exposed resolve and reject functions.",
"applyTo": "src/**/*.js",
"pattern": "new Promise\\(function\\(resolve, reject\\) \\{.*\\}\\)",
"replacement": "Promise.withResolvers()",
"message": "Consider using Promise.withResolvers for a cleaner and more straightforward promise creation."
},
{
"name": "prefer-regexp-v-flag",
"description": "Encourage the use of the /v flag in regular expressions for advanced Unicode set operations.",
"applyTo": "src/**/*.js",
"pattern": "/.*?/u",
"replacement": "/$1/v",
"message": "Consider using the /v flag in regular expressions to leverage advanced Unicode set operations."
}
]
}