<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gaurav Agarwal on Medium]]></title>
        <description><![CDATA[Stories by Gaurav Agarwal on Medium]]></description>
        <link>https://medium.com/@gv.agarwal94?source=rss-9ddb08611528------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*yRcRZyR6dphUDkEy.jpg</url>
            <title>Stories by Gaurav Agarwal on Medium</title>
            <link>https://medium.com/@gv.agarwal94?source=rss-9ddb08611528------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 07:56:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gv.agarwal94/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ Supercharging ESLint Fixes and Code Quality with GitHub Copilot Chat]]></title>
            <link>https://medium.com/@gv.agarwal94/eslint-with-github-copilot-3ed820081f35?source=rss-9ddb08611528------2</link>
            <guid isPermaLink="false">https://medium.com/p/3ed820081f35</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[sonarqube]]></category>
            <category><![CDATA[code-complexity]]></category>
            <category><![CDATA[github-copilot]]></category>
            <category><![CDATA[eslint]]></category>
            <dc:creator><![CDATA[Gaurav Agarwal]]></dc:creator>
            <pubDate>Fri, 27 Jun 2025 18:54:07 GMT</pubDate>
            <atom:updated>2025-06-27T18:54:07.315Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*MQzhMtvPeRHdXiwoEdcnag.jpeg" /></figure><p>If you’ve ever stared at a complex <strong>ESLint</strong> error wondering how to refactor that block of code,<em> </em><strong><em>GitHub Copilot</em></strong> Chat might just be the coding sidekick you need. With the rise of AI tools, developers can now reduce the cognitive load of fixing linting issues and improving code readability — without leaving their IDE.</p><p>In this blog, I’ll walk you through how GitHub Copilot can <strong>fix ESLint issues</strong>, <strong>reduce code complexity</strong>, and how to <strong>use chat-based modes and commands</strong> to make your coding workflow smoother.</p><h3>🛠️ Use Case 1: Resolving ESLint Errors Using GitHub Copilot</h3><p>🔥<strong>Problem: </strong>You’ve written a function that violates ESLint rules for complexity, unused variables, or inconsistent returns.</p><pre>function processData(items) {<br>  let total = 0;<br>  for (let i = 0; i &lt; items.length; i++) {<br>    if (items[i] &amp;&amp; items[i].value !== null) {<br>      if (items[i].value &gt; 100) {<br>        total += items[i].value * 1.1;<br>      } else {<br>        total += items[i].value;<br>      }<br>    }<br>  }<br>  return total;<br>}</pre><p><strong>ESLint throws: </strong>Function ‘processData’ has a complexity of 5.</p><p><strong>Solution with GitHub Copilot Chat — </strong>Simply highlight the function and type:</p><blockquote><strong>/fix</strong> simplify and reduce complexity</blockquote><p><strong>Copilot returns:</strong></p><pre>function processData(items) {<br>  return items.reduce((total, item) =&gt; {<br>    if (!item || item.value === null) return total;<br>    return total + (item.value &gt; 100 ? item.value * 1.1 : item.value);<br>  }, 0);<br>}</pre><p>✨ <strong>Just like that, Copilot reduced the code from 9 lines to 5 and resolved the complexity issue.</strong></p><h3>🧪 Use Case 2: Understanding and Explaining ESLint Rules</h3><p>Sometimes, you want to <em>learn</em> instead of blindly applying fixes.</p><p>Use this prompt:</p><blockquote><strong>/explain</strong> why is this ESLint error thrown?</blockquote><p>Copilot gives you a breakdown of the specific rule, links to ESLint docs, and suggestions to reconfigure the rule if needed.</p><h3>🔍 Inline Chat vs Chat Panel: What’s the Difference?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HNdvqGa-Aa399pkRWYMOSA.png" /></figure><h3>🔄 Modes: Edit, Ask, and Agent</h3><p>GitHub Copilot Chat comes with multiple modes for interacting based on your task:</p><h3>🔧 Edit Mode</h3><p>Highlight code → right-click → <strong>“Copilot: Edit with Prompt”</strong></p><blockquote>Simplify this function and make it readable</blockquote><p>Copilot rewrites the code instantly.</p><h3>❓ Ask Mode</h3><p>Chat with the agent in full sentences.</p><blockquote>Why is my async function causing unhandled promise warnings?</blockquote><p>Great for debugging or learning patterns.</p><h3>🤖 Agent Mode</h3><p>Delegates a task to the Copilot agent, like setting up tests, upgrading dependencies, etc.</p><h3>💬 Useful Commands in GitHub Copilot Chat</h3><blockquote><strong>fix </strong>— Automatically fix lint errors, or suggest improvements</blockquote><blockquote><strong>explain</strong> — Explain a piece of code or ESLint warning</blockquote><blockquote><strong>tests</strong> — Generate unit tests for selected function or file</blockquote><blockquote><strong>doc</strong> — Add documentation/comments to the selected code</blockquote><blockquote><strong>codebase</strong> — Ask Copilot questions about the entire repo</blockquote><blockquote><strong>file</strong> — Ask questions specific to the current file</blockquote><blockquote><strong>generate</strong> — Generate code from a user-defined prompt</blockquote><h3>🧠 Best Practices</h3><ul><li>Use <strong><em>inline chat</em></strong> for quick changes and lint fixes.</li><li>Use <strong><em>chat panel</em></strong> when working across multiple files or refactoring a whole module.</li><li>Let Copilot <strong>teach you</strong> — use /explain liberally to understand ESLint rules or tricky code blocks.</li></ul><h3>✅ Conclusion</h3><p>GitHub Copilot Chat doesn’t just fix bugs — it <strong>amplifies your code quality</strong>, teaches you best practices, and helps you maintain cleaner, simpler code. Whether you’re squashing an ESLint error or refactoring spaghetti logic, Copilot Chat is like having a senior engineer by your side.</p><p>Ready to code cleaner?</p><blockquote><em>✨ Try Copilot Chat and give your ESLint errors an AI-powered makeover.</em></blockquote><p><strong>#GitHubCopilot #ESLint #CodeQuality #AIforDevelopers #VSCode #JavaScript #TypeScript</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3ed820081f35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enhancing Javascript with the Decorator Pattern: Body Validation & Authorization]]></title>
            <link>https://medium.com/@gv.agarwal94/enhancing-javascript-with-the-decorator-pattern-body-validation-authorization-a0702da17a44?source=rss-9ddb08611528------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0702da17a44</guid>
            <dc:creator><![CDATA[Gaurav Agarwal]]></dc:creator>
            <pubDate>Thu, 30 Jan 2025 18:04:24 GMT</pubDate>
            <atom:updated>2025-01-30T18:04:24.975Z</atom:updated>
            <content:encoded><![CDATA[<p>The <strong>Decorator Pattern</strong> is a powerful design pattern in JavaScript that enables adding behavior dynamically to functions or classes without modifying their existing structure. This makes it highly useful for cross-cutting concerns like <strong>body validation</strong> and <strong>authorization</strong> in web applications.</p><figure><img alt="Javascript Decorators" src="https://cdn-images-1.medium.com/max/1024/1*4sHduwpna9K8zTmiClqvcQ.png" /></figure><p>In this blog, we’ll explore how the <strong>Decorator Pattern</strong> can be used in JavaScript (and TypeScript) to streamline API request handling with real-world examples.</p><p><strong>Why Use the Decorator Pattern in JavaScript?</strong></p><p>When building APIs, common concerns like <strong>input validation</strong> and <strong>authorization</strong> often need to be repeated across multiple endpoints. Traditionally, this is handled using middleware, but decorators provide a <strong>cleaner, more reusable</strong> approach by keeping these concerns within the function definition itself.</p><p><strong>Benefits of the Decorator Pattern</strong></p><p>✅ <strong>Separation of Concerns</strong> — Keeps core business logic clean and focused.</p><p>✅ <strong>Reusability</strong> — Easily attach behaviors to multiple functions or classes.</p><p>✅ <strong>Improved Readability</strong> — Eliminates repetitive boilerplate code.</p><p><strong>Implementing the Decorator Pattern in JavaScript</strong></p><p><strong>1. Creating a Body Validation Decorator</strong></p><p>Let’s start with a decorator that validates the request body before processing.</p><pre>function ValidateBody(schema) {<br>    return function (target, key, descriptor) {<br>        const originalMethod = descriptor.value;<br>        descriptor.value = async function (req, res, next) {<br>            const { error } = schema.validate(req.body);<br>            if (error) {<br>                return res.status(400).json({ msg: error.details[0].message });<br>            }<br>            return originalMethod.apply(this, arguments);<br>        };<br>        return descriptor;<br>    };<br>}</pre><p><strong>Usage Example:</strong></p><p>Using <strong>Joi</strong> for schema validation:</p><pre>const Joi = require(&quot;joi&quot;);<br><br>const userSchema = Joi.object({<br>  username: Joi.string().min(3).required(),<br>  email: Joi.string().email().required(),<br>});<br><br>class UserController {<br>  @ValidateBody(userSchema)<br>  async createUser(req, res) {<br>    res.status(201).json({ msg: &quot;User created successfully!&quot; });<br>  }<br>}</pre><p><strong>2. Creating an Authorization Decorator</strong></p><p>Now, let’s implement an <strong>authorization</strong> decorator to restrict access based on user roles.</p><pre>function Authorize(allowedRoles) {<br>  return function (target, key, descriptor) {<br>    const originalMethod = descriptor.value;<br><br>    descriptor.value = async function (req, res, next) {<br>      const userRole = req.user?.role; // Assuming req.user is populated via authentication middleware<br><br>      if (!allowedRoles.includes(userRole)) {<br>        return res.status(403).json({ msg: &quot;Forbidden: Insufficient permissions&quot; });<br>      }<br><br>      return originalMethod.apply(this, arguments);<br>    };<br><br>    return descriptor;<br>  };<br>}</pre><p><strong>Usage Example:</strong></p><pre>class AdminController {<br>  @Authorize([&quot;admin&quot;])<br>  async deleteUser(req, res) {<br>    res.status(200).json({ msg: &quot;User deleted successfully!&quot; });<br>  }<br>}</pre><p><strong>Bringing It All Together</strong></p><p>Using both decorators in a controller:</p><pre>class UserController {<br>  @ValidateBody(userSchema)<br>  @Authorize([&quot;admin&quot;, &quot;moderator&quot;])<br>  async createUser(req, res) {<br>    res.status(201).json({ msg: &quot;User created successfully!&quot; });<br>  }<br>}</pre><p>With this approach:</p><p>• ValidateBody ensures only valid input is processed.</p><ul><li>Authorize restricts access to permitted roles.</li></ul><p><strong>Conclusion</strong></p><p>The <strong>Decorator Pattern</strong> in JavaScript (and TypeScript) simplifies handling <strong>validation</strong> and <strong>authorization</strong> in web applications. It enhances <strong>modularity</strong>, <strong>code reusability</strong>, and <strong>readability</strong>.</p><p>If you’re using <strong>TypeScript</strong>, decorators are even more powerful with built-in support. For a cleaner, more maintainable codebase, consider adopting decorators in your Node.js/Express or Restify project! 🚀</p><p>What are your thoughts on using decorators for request handling? Share your experiences in the comments! 👇</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0702da17a44" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>