<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Malek abbes</title>
    <description>The latest articles on DEV Community by Malek abbes (@malekabbes).</description>
    <link>https://dev.to/malekabbes</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F302419%2F45610d4e-b15f-4e8f-8804-362cd7c43914.jpg</url>
      <title>DEV Community: Malek abbes</title>
      <link>https://dev.to/malekabbes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/malekabbes"/>
    <language>en</language>
    <item>
      <title>Suppress the warning no-unused-vars</title>
      <dc:creator>Malek abbes</dc:creator>
      <pubDate>Wed, 22 Feb 2023 12:52:06 +0000</pubDate>
      <link>https://dev.to/malekabbes/suppress-the-warning-no-unused-vars-27nl</link>
      <guid>https://dev.to/malekabbes/suppress-the-warning-no-unused-vars-27nl</guid>
      <description>&lt;p&gt;Hey fellas , &lt;br&gt;
When coding a react application , you may pass by some stuff like &lt;strong&gt;warnings&lt;/strong&gt; which can be sometimes super annoying to see in your console.&lt;br&gt;
Something like this : &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Line 7:10:  'available' is assigned a value but never used. Allowed unused vars must match /^_/u        no-unused-vars&lt;br&gt;
  Line 9:23:  'Setlistproducts' is assigned a value but never used. Allowed unused vars must match /^_/u  no-unused-vars&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So the solution for this is quite easy actually . &lt;/p&gt;

&lt;p&gt;So here's the steps :&lt;/p&gt;

&lt;p&gt;1- Open &lt;strong&gt;package.json&lt;/strong&gt; file .&lt;/p&gt;

&lt;p&gt;2- You scroll down until you hit &lt;strong&gt;eslintConfig&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And here we can add our desired rule ! &lt;br&gt;
In our case we want to avoid that warning "no-unused-vars" from appearing again.&lt;br&gt;
so in order to do that we add these lines : &lt;br&gt;
&lt;code&gt;"rules":{&lt;br&gt;
       "no-unused-vars" : [&lt;br&gt;
        "warn",{&lt;br&gt;
          "argsIgnorePattern": "^_",&lt;br&gt;
          "varsIgnorePattern": "^_"&lt;br&gt;
        }&lt;br&gt;
       ]&lt;br&gt;
    }&lt;/code&gt;&lt;br&gt;
&lt;u&gt;&lt;/u&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  BONUS :
&lt;/h2&gt;

&lt;p&gt;&lt;br&gt;
&lt;strong&gt;Customize rules&lt;/strong&gt;: You can also customize the built-in rules or create your own rules to fit your project's specific needs. For example, you can create a custom rule to enforce a specific naming convention or to require specific dependencies.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To create your custom rule you need to follow these steps : **&lt;br&gt;
Exemple : Creating a naming convention as mentioned above.&lt;br&gt;
1- Install the eslint-plugin package :&lt;br&gt;
&lt;code&gt;npm install eslint-plugin --save-dev&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
2- Create a new directory called **eslint&lt;/strong&gt; in the root of your project and create a new file called &lt;strong&gt;naming-convention.js&lt;/strong&gt; inside the previously created directory.&lt;/p&gt;

&lt;p&gt;3- In the naming-convention.js file, you define your custom rule :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  meta: {
    type: "suggestion",
    docs: {
      description: "enforce specific naming convention",
      category: "Best Practices",
      recommended: true,
    },
    schema: [
      // add any schema options here
    ],
  },

  create: function(context) {
    // your implementation of the rule goes here
  }
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4- Inside the create method, you can define the implementation of your custom rule. For example, to enforce that all React components have a specific naming convention (e.g. PascalCase), you can use the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create: function(context) {
  function checkName(node) {
    const name = node.name;
    if (!/^[A-Z][a-z0-9]*$/.test(name)) {
      context.report({
        node,
        message: "React component name should be in PascalCase"
      });
    }
  }

  return {
    JSXOpeningElement: function(node) {
      if (node.name.type === "JSXIdentifier" &amp;amp;&amp;amp; node.name.name.endsWith('Component')) {
        checkName(node.name);
      }
    }
  };
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5- So in the last step , save the file and add the new rule to your project's eslintConfig  object in the package.json file, like so:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"eslintConfig": {&lt;br&gt;
  "extends": "react-app",&lt;br&gt;
  "plugins": ["eslint-plugin"],&lt;br&gt;
  "rules": {&lt;br&gt;
    "eslint-plugin/naming-convention": "error"&lt;br&gt;
  }&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;With these steps, you have created a custom ESLint rule that enforces a specific naming convention for React components in your project. You can use a similar approach to create other custom rules that fit your project's specific needs.&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>python</category>
      <category>machinelearning</category>
      <category>career</category>
    </item>
  </channel>
</rss>
