<?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 Jason Savelli on Medium]]></title>
        <description><![CDATA[Stories by Jason Savelli on Medium]]></description>
        <link>https://medium.com/@savellijason?source=rss-34d50a0db533------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_M7lDA3TK8d_RXwmqJJJ6g.jpeg</url>
            <title>Stories by Jason Savelli on Medium</title>
            <link>https://medium.com/@savellijason?source=rss-34d50a0db533------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 01:25:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@savellijason/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[Amplitude setup in a NX monorepo]]></title>
            <link>https://splio.tech/amplitude-setup-in-a-nx-monorepo-9a4537e317fe?source=rss-34d50a0db533------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a4537e317fe</guid>
            <category><![CDATA[nx]]></category>
            <category><![CDATA[amplitude]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[monorepo]]></category>
            <dc:creator><![CDATA[Jason Savelli]]></dc:creator>
            <pubDate>Thu, 06 Feb 2025 13:12:38 GMT</pubDate>
            <atom:updated>2025-02-06T13:12:38.357Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*1tGpIzxVugyOf6wBr9ftzQ.png" /></figure><h4>What is Amplitude and why do we want it ?</h4><p><a href="https://amplitude.com/"><strong>Amplitude</strong></a> is a powerful analytics platform for tracking user behavior. Having good data quality is important as a company, to understand how your users interact with your product which will lead to data-driven decisions.</p><p>By visualizing funnels, retention, and engagement metrics, you can prioritize features, spot drop-offs, and improve overall performance to align your product with user needs.</p><p>In this article, we will explore the primary concerns associated with using Amplitude within a monorepo and how to address them. While the examples provided focus on a monorepo, the solutions are equally applicable to a regular repository, with the added benefit of requiring fewer configurations.</p><h4>Common Amplitude implementation with SDK</h4><pre>import * as amplitude from &#39;@amplitude/analytics-browser&#39;;<br><br>type MyComponentProps = {<br>  userId: string<br>}<br><br>const MyComponent = ({ userId }: MyComponentProps) =&gt; {<br>  const handleClick = () =&gt; {<br>    // No type safety on event name or properties 👎<br>    amplitude.track(&quot;my tracking event&quot;, {<br>      myProperty: &quot;my property value&quot;,<br>    })<br>  }<br><br>  useEffect(() =&gt; {<br>    amplitude.init(process.env.AMPLI_KEY, userId)<br>  }, [userId])<br><br><br><br>  return (<br>    &lt;button onClick={handleClick}&gt;Click&lt;/button&gt;<br>  )<br>}</pre><p>To ensure quality data, there is 4 points we want to focus on:</p><ul><li>Typed events and properties. It’d be nice to take advantage of Typescript to ensure we have no typo in events and properties and have powerful autocompletion.</li><li>We want to avoid having events that aren’t expected on the tracking plan anymore, or unused properties on existing events.</li><li>We want to know which events are implemented yet, and which one are missing.</li><li>As we’re working in a monorepo, we would want to scope specific events to the packages they are relative to.</li></ul><p><strong>Ampli CLI to the rescue</strong></p><p>According to the official documentation, instead of using the Amplitude SDK, we could instead use <a href="https://amplitude.com/docs/sdks/ampli/ampli-cli">Ampli CLI</a> which seems to be the perfect tools for us, as it will answer all of ours problematics</p><p>First, we need to setup properly our Amplitude dashboard. We need to add in our project, a source for our tracking plan , our one and only source of truth when it comes to tracking.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7VMR_Xnadls6BHU2NsS0iA.png" /></figure><p>Once it’s done, we can proceed to <strong>Ampli CLI</strong> installation.</p><pre>npm i -g @amplitude/ampli</pre><p><strong>Editor’s Note: </strong><em>On the official documentation, sometimes it is installed as a global package, sometimes as a project dependency. I personally think it should always be a project dependency, but it sometimes fails on some command such as </em><em>status which is an important command we’ll see later.</em></p><p>Now, we want to login to <strong>Amplitude through the CLI</strong></p><pre>ampli login</pre><p>Next, we will add a custom command in one of our package, so we can run ampli CLI inside this specific package without having to checkout the directory every time.</p><pre>// libs/packages/my-cool-package/project.json<br><br>{<br> ...<br> &quot;ampli&quot;: {<br>    &quot;metadata&quot;: {<br>      &quot;description&quot;: &quot;Run Amplitude CLI inside the package&quot;<br>    },<br>    &quot;command&quot;: &quot;ampli&quot;,<br>    &quot;options&quot;: {<br>      &quot;cwd&quot;: &quot;./libs/packages/my-cool-package&quot;<br>    }<br>  }<br>}</pre><p>Everything is now ready for the setup inside the package, let’s init our package</p><pre>yarn nx run packages-my-cool-package:ampli pull --omit-api-keys</pre><p>You will be asked few informations:</p><ul><li>Workspace is your Amplitude project</li><li>The source is the source we created earlier</li><li>The other things depends on your package, but this is what it should look like for a Typescript package</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5vxzZVaHKu9pBbtjWBpC2Q.png" /><figcaption>yarn nx run packages-my-cool-package:ampli pull</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t7QMsMtj4ods5xPxkE5tzQ.png" /><figcaption>Generated files from the previous command</figcaption></figure><p>In the main ESlint file, we will forbid the import of the amplitude package, because we want to enforce using the generated ampli file, which contain all the Typescript flavor, instead of the amplitude package.</p><pre>// eslint.config.js</pre><pre>module.exports = [<br>  ...,<br>  &#39;@typescript-eslint/no-restricted-imports&#39;: [<br>      // https://typescript-eslint.io/rules/no-restricted-imports/<br>      &#39;error&#39;,<br>      {<br>        patterns: [<br>          {<br>            group: [&#39;@amplitude/*&#39;],<br>            message:<br>              &#39;Imports from @amplitude/* are forbidden. Refer to Notion Amplitude internal documentation.&#39;,<br>          },<br>        ],<br>      },<br>    ],<br>]</pre><p>Also, as these files are auto-generated, we want to ignore them from ESlint. If you plan to use Amplitude for every single package of your monorepo, you can add the following in your main eslint config file, but I personally think it’s better to have it in each package that use amplitude.</p><pre>// /libs/packages/my-cool-package/eslint.config.js<br><br>module.exports = [<br>  {<br>    // This folder is autogenerated by Amplitude CLI, we shouldn&#39;t lint it<br>    ignores: [&#39;src/ampli/*&#39;],<br>  },<br>];</pre><h4>Initialize Amplitude with generated tool</h4><p>Before anything else, we have to load Amplitude, otherwise, no any events will be sent, and we’ll lose important data.</p><p><strong>Editor’s note</strong>: <em>Amplitude </em><em>load offers a lot of customization. While the documentation is not really helpful, it’s worth taking few minutes to discover all the available options.</em></p><pre>import { ampli } from &#39;../../ampli&#39;;<br><br>const App = () =&gt; {<br><br>  useEffect(() =&gt; {<br>    const isTestEnv = process.env.NODE_ENV === &#39;test&#39;;<br>    const apiKey = process.env.AMPLI_API_KEY;<br><br>    ampli.load({<br>      // We don&#39;t want to really send the tracking event in test environment<br>      disabled: isTestEnv,<br>      client: {<br>        apiKey,<br>        configuration: {<br>          autocapture: {<br>            attribution: false,<br>            elementInteractions: false,<br>            fileDownloads: false,<br>            formInteractions: false,<br>            pageViews: true,<br>            sessions: false,<br>          },<br>          userId,<br>        },<br>      },<br>    })<br>  }, [userId])<br>}<br><br>return (<br>  &lt;div&gt;<br>    &lt;p&gt;my app&lt;/p&gt;<br>  &lt;/div&gt;<br>)</pre><h4>Implement a new event with ampli CLI</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l_pnykoGvSSp6M3PChqueA.png" /></figure><p>Now that Amplitude is setup and loaded, we can add our first event using the new CLI. Let’s take this event as example. Here we have an event <strong>my tracking event</strong> with a property named <strong>myCoolProperty</strong>, which is an enum.</p><p>We added example-source as a source on this event so if we run the <strong>pull </strong>command we used earlier, as we’ve configured our package using this source, the CLI will generate for us all the typescript types and add the event as ampli property !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aRwPbwBVCyF6Cc6zUovTyw.png" /><figcaption>Typescript autocomplete suggest the added event</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OJnARYcnla_xsk2QaLeuvg.png" /><figcaption>Typescript autocomplete suggest the added event property !</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jLqylXaBdU5mu4kVAb8StA.png" /><figcaption>Typescript throw an error if we try to use an event that doesn’t exist in the tracking plan with the matching source</figcaption></figure><p>As you can see, here with these few configuration steps, we’ve fixed all of our initial concerns :</p><ul><li>We now have generated types for our events, properties</li><li>If an event is removed from amplitude, or the package source is removed from the event, running the pull command will automatically update the generated types, leading to a Typescript error, so we’ll know the event has been removed.</li><li>As we’re associating a source per package, a package only knows the event associated to his source.</li></ul><p>Here, only <strong>one point</strong> of our initial concerns <strong>is missing</strong> : <strong>Identify events from tracking plan that aren’t implemented yet.</strong></p><h4>Adding an existing event</h4><p>As we are using ampli CLI, we can take advantage of all its powerful feature, including the status command. This command is the second most helpful for us as for a given package / source, it will tell us which events are used / unused with this command :yarn nx run packages-my-cool-package:ampli status</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*b-c9Mj3fx6n33_mCTTAegg.png" /><figcaption>All the event from the package’s associated source are used</figcaption></figure><p><strong>Real case scenario</strong> : In the meantime, our product manager added a new event for our package source, but we don’t know which one. As we have events autocompletion, we would find it, but the more the package is growing, the more it becomes a bit hard to identify which one is missing. Running the previous command will now give the following</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*e5tkHo3BKYhSvBRgj9hc8g.png" /><figcaption>An event from the associated package’s source is missing !</figcaption></figure><p>We now know that New Cool Event is not implemented yet in this package, and this, was how to fix our last concern about how to identify existing events that aren’t implemented yet.</p><p>It’s important to note that this <strong>will NOT update the generated types</strong>, you will still have to run the pull command to update your generated ampli file.</p><p><strong>Editor’s Note</strong><em> : The </em><em>status command is run on a specific package, which mean a specific source. This event could have already been implemented on another source, but it still will be in error for this package.</em></p><h4>Bonus: How to go through Ad blockers</h4><p>Ad blockers have become increasingly popular over the years. While they enhance users’ web experiences, some also detect Amplitude API calls when events are sent as ads and block them, resulting in the loss of important data.</p><p>To address this issue, Amplitude provides a serverUrl parameter in the configuration object of the generated ampli file. This URL specifies where all sent events will be dispatched. By redirecting all events to a reverse proxy, you can ensure they are forwarded back to Amplitude by your own server, which mean that Ad blockers can’t block them.</p><p>You can learn more about this problematic and how to address it <a href="https://amplitude.com/docs/analytics/domain-proxy">on the official documentation</a></p><pre>ampli.load({<br>    ...<br>    client: {<br>      apiKey,<br>        ....<br>        serverUrl: &#39;https://my-own-url.fr&#39;,<br>      },<br>    },<br>  })</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ucq-iPW2auZ3Z2Fu0m7I6Q.png" /></figure><h4>Next steps: Amplitude in CI</h4><p>We previously saw that with the help of the status command, we can identify events that aren’t implemented yet in a given package, but we have to run this command manually.</p><p>A cool idea would be to run this command in the <strong>CI </strong>to automatically check events implementation, and as we’re using <strong>NX </strong>to manage our monorepo, we have the possibility to automatically run the status command on package that have been modified in a given merge request instead of all the packages.</p><p>Unfortunately I didn’t implemented it yet so I can’t share how it looks like for a GitLab CI, but <a href="https://amplitude.com/docs/sdks/ampli/validate-in-ci">here on the official documentation</a>, you can have a glimpse on how to do it.</p><h4>Conclusion</h4><p>We now have a clean way to implement Amplitude in our NX monorepo:</p><ul><li>We’re sure to have no typo in our events names nor properties</li><li>Always up to date data</li><li>A way to identify non implemented yet events</li><li>Avoid data loss due to ad blockers</li><li>Events scoped per package</li></ul><p>Thank you for reading our article. Feel free to ask any questions or provide any feedbacks. Hope it helps you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a4537e317fe" width="1" height="1" alt=""><hr><p><a href="https://splio.tech/amplitude-setup-in-a-nx-monorepo-9a4537e317fe">Amplitude setup in a NX monorepo</a> was originally published in <a href="https://splio.tech/">Splio Product Engineering &amp; Design</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ESLint v8.x legacy config migration to v9 with flat config, on a Monorepo using NX]]></title>
            <link>https://splio.tech/eslint-v8-x-legacy-config-migration-to-v9-with-flat-config-on-a-monorepo-using-nx-ca5168976c6a?source=rss-34d50a0db533------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca5168976c6a</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[eslint]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[nx]]></category>
            <dc:creator><![CDATA[Jason Savelli]]></dc:creator>
            <pubDate>Wed, 27 Nov 2024 19:54:55 GMT</pubDate>
            <atom:updated>2024-11-27T19:54:55.279Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L-w8gn0wFmNzOMCx1JJ_Mw.png" /><figcaption>ESLint v9 migration</figcaption></figure><p>ESlint announced the 10th September, 2024 that the <a href="https://eslint.org/blog/2024/09/eslint-v8-eol-version-support/">8.x version EOL will happen the 5th October, 2024</a>.</p><p>As for every tooling from the JS ecosystem, it can be a bit complex to upgrade a dependency version to the next major version, and in our case, we already are late, as we’re using the v8.x version, but with their legacy config.</p><p>It’s time for us to do the update, but it can be really intimidating for various reasons : a lot of breaking changes, incompatible plugins, existing configuration being too complex, different paradigms, monorepo context making everything more complex, etc.</p><p>In this article, we’ll go through the whole migration process and encountered errors up to the end of the migration. Note that even if you’re not working within a mono repository, it still can help you, you’ll just have to ignore monorepo specificities.</p><p><strong>Editor’s Note:</strong> <em>Jump to the end of the article if you want to look at a working configuration in NX mono repository without going through all the extra steps.</em></p><h4>🤔 Current situation</h4><ul><li>As with every company that has a product that has existed for a while, we’ve accumulated a bit of technical debt. We’re using deprecated plugins such as <a href="https://www.npmjs.com/package/eslint-config-airbnb">eslint-config-airbnb</a>, and <a href="https://github.com/typescript-eslint/typescript-eslint/pull/8833">some of the rules we use</a> are deprecated in the latest versions.</li><li>We’re using a “recent” version of ESLint (v8.57), but we’re still using the <a href="https://eslint.org/docs/latest/use/configure/configuration-files-deprecated">legacy and deprecated ESLintRC config file format</a>. We need to move forward with the new flat config format to stay up-to-date with our lint tooling.</li><li>Our configuration has evolved incrementally over a few years and therefore includes a lot of rules, some of which don’t make sense for us as we keep turning them off or ignoring them. Also, our files are a bit messy due to my misunderstanding of how to properly manage rules inside a monorepo 🙈</li></ul><h4>🎯 What do we aim for ?</h4><ul><li>First, we want to use the new flat config format. It’s the new standard and seems easier to read and maintain, which is definitely a plus.</li><li>Next, we want to replace the deprecated plugins and rules with new ones as much as possible.</li><li>Finally, it would be great to clean up our dev dependencies to keep only the plugins and rules that still make sense for us.</li></ul><h4><strong>Let’s get started !</strong></h4><p>As mentioned in the title, we’re managing a monorepo using NX. NX provides really great tools to manage a monorepo, and we’re in luck; they’ve made a <a href="https://nx.dev/recipes/tips-n-tricks/flat-config">recipe on how to migrate to the ESLint flat config</a>, which includes a migration script 🎉</p><pre>nx g @nx/eslint:convert-to-flat-config</pre><p><strong>Editor’s Note: </strong><em>Your ESLint related files must have </em><em>.json or </em><em>.yml extensions, otherwise you’ll encounter an error running the script</em></p><p>Here is our file before (<strong>.eslintrc.json</strong>) :</p><pre>// eslintrc.json<br><br>{<br>  &quot;root&quot;: true,<br>  &quot;extends&quot;: [&quot;plugin:prettier/recommended&quot;],<br>  &quot;plugins&quot;: [&quot;@nx&quot;],<br>  &quot;overrides&quot;: [<br>    {<br>      &quot;files&quot;: [&quot;*.mdx&quot;],<br>      &quot;extends&quot;: [&quot;plugin:mdx/recommended&quot;]<br>    },<br>    {<br>      &quot;files&quot;: [&quot;*.js&quot;, &quot;*.jsx&quot;],<br>      &quot;extends&quot;: [<br>        &quot;plugin:@nx/javascript&quot;,<br>        &quot;airbnb&quot;,<br>        &quot;plugin:react/jsx-runtime&quot;<br>      ],<br>      &quot;rules&quot;: {<br>        // Forces to use `single`, but still accepts double or backtick when needed<br>        &quot;quotes&quot;: [&quot;error&quot;, &quot;single&quot;, { &quot;avoidEscape&quot;: true }],<br><br>        // Avoid having to specify extension when importing files in .js environment<br>        &quot;import/extensions&quot;: [<br>          &quot;error&quot;,<br>          &quot;ignorePackages&quot;,<br>          {<br>            &quot;ts&quot;: &quot;never&quot;,<br>            &quot;tsx&quot;: &quot;never&quot;,<br>            &quot;js&quot;: &quot;never&quot;,<br>            &quot;jsx&quot;: &quot;never&quot;,<br>            &quot;json&quot;: &quot;always&quot;<br>          }<br>        ]<br>      },<br>      &quot;settings&quot;: {<br>        // Make JS file understand correctly the path when importing from a TS file<br>        &quot;import/resolver&quot;: {<br>          &quot;node&quot;: {<br>            &quot;extensions&quot;: [&quot;.js&quot;, &quot;.jsx&quot;, &quot;.json&quot;, &quot;.ts&quot;, &quot;.tsx&quot;]<br>          }<br>        }<br>      }<br>    },<br>    {<br>      &quot;files&quot;: [&quot;*.ts&quot;, &quot;*.tsx&quot;],<br>      &quot;extends&quot;: [<br>        &quot;plugin:@nx/typescript&quot;,<br>        &quot;airbnb&quot;,<br>        &quot;airbnb-typescript&quot;,<br>        &quot;plugin:react/jsx-runtime&quot;<br>      ],<br>      &quot;parserOptions&quot;: {<br>        &quot;project&quot;: &quot;tsconfig.base.json&quot;<br>      },<br>      &quot;rules&quot;: {<br>        /** We have to disable base rules and instead use the specific typescript rule  */<br>        &quot;quotes&quot;: 0,<br>        &quot;@typescript-eslint/quotes&quot;: [<br>          &quot;error&quot;,<br>          &quot;single&quot;,<br>          { &quot;avoidEscape&quot;: true }<br>        ],<br>        &quot;@typescript-eslint/no-empty-function&quot;: &quot;off&quot;,<br>        &quot;@typescript-eslint/indent&quot;: &quot;off&quot;,<br>        &quot;@typescript-eslint/comma-dangle&quot;: &quot;off&quot;,<br>        &quot;@typescript-eslint/no-unused-vars&quot;: &quot;error&quot;<br>      }<br>    },<br>    {<br>      &quot;files&quot;: [&quot;*.json&quot;],<br>      &quot;parser&quot;: &quot;jsonc-eslint-parser&quot;,<br>      &quot;rules&quot;: {}<br>    },<br>    {<br>      &quot;files&quot;: [&quot;*.ts&quot;, &quot;*.tsx&quot;, &quot;*.js&quot;, &quot;*.jsx&quot;],<br>      &quot;plugins&quot;: [&quot;n&quot;],<br>      &quot;rules&quot;: {<br>        // Avoid forbidden relation between nx tags<br>        &quot;@nx/enforce-module-boundaries&quot;: [<br>          &quot;error&quot;,<br>          {<br>            &quot;depConstraints&quot;: [<br>              {<br>                &quot;sourceTag&quot;: &quot;client&quot;,<br>                &quot;onlyDependOnLibsWithTags&quot;: [&quot;page&quot;, &quot;page-graphql&quot;, &quot;shared&quot;]<br>              },<br>              {<br>                &quot;sourceTag&quot;: &quot;server&quot;,<br>                &quot;onlyDependOnLibsWithTags&quot;: [&quot;module&quot;, &quot;shared&quot;]<br>              },<br>              {<br>                &quot;sourceTag&quot;: &quot;page&quot;,<br>                &quot;onlyDependOnLibsWithTags&quot;: [&quot;ui&quot;, &quot;shared&quot;]<br>              },<br>              {<br>                &quot;sourceTag&quot;: &quot;shared&quot;,<br>                &quot;onlyDependOnLibsWithTags&quot;: [&quot;shared&quot;]<br>              },<br>              {<br>                &quot;sourceTag&quot;: &quot;page-graphql&quot;,<br>                &quot;onlyDependOnLibsWithTags&quot;: [&quot;graphql&quot;, &quot;shared&quot;]<br>              }<br>            ]<br>          }<br>        ],<br>        &quot;import/no-named-as-default&quot;: &quot;off&quot;,<br>        &quot;import/no-extraneous-dependencies&quot;: &quot;off&quot;,<br>        &quot;import/no-default-export&quot;: &quot;error&quot;, // Forbid default exports<br>        &quot;object-curly-newline&quot;: &quot;off&quot;,<br>        &quot;jsx-a11y/label-has-associated-control&quot;: &quot;off&quot;,<br>        &quot;react/jsx-wrap-multilines&quot;: &quot;off&quot;,<br>        &quot;react/function-component-definition&quot;: &quot;off&quot;,<br>        &quot;implicit-arrow-linebreak&quot;: &quot;off&quot;,<br>        &quot;function-paren-newline&quot;: &quot;off&quot;,<br>        &quot;react/require-default-props&quot;: &quot;off&quot;,<br>        &quot;no-confusing-arrow&quot;: &quot;off&quot;,<br>        &quot;react-hooks/exhaustive-deps&quot;: &quot;error&quot;,<br>        &quot;react/jsx-closing-tag-location&quot;: &quot;off&quot;,<br>        &quot;operator-linebreak&quot;: &quot;off&quot;,<br>        &quot;import/prefer-default-export&quot;: &quot;off&quot;,<br>        &quot;no-multi-spaces&quot;: &quot;off&quot;,<br>        &quot;react/jsx-indent&quot;: &quot;off&quot;,<br>        &quot;react/jsx-props-no-spreading&quot;: &quot;off&quot;,<br>        &quot;react/jsx-curly-newline&quot;: &quot;off&quot;,<br>        &quot;jsx-a11y/aria-role&quot;: &quot;off&quot;,<br>        &quot;jsx-a11y/click-events-have-key-events&quot;: &quot;off&quot;,<br>        // https://github.com/reduxjs/redux-toolkit/issues/521#issuecomment-641176135<br>        &quot;no-param-reassign&quot;: [&quot;error&quot;, { &quot;props&quot;: false }],<br>        &quot;comma-dangle&quot;: 0,<br>        &quot;indent&quot;: &quot;off&quot;,<br>        &quot;no-process-env&quot;: &quot;error&quot;,<br>        &quot;jsx-quotes&quot;: [&quot;error&quot;, &quot;prefer-single&quot;],<br>        // Format our code is prettier job<br>        &quot;react/jsx-one-expression-per-line&quot;: &quot;off&quot;<br>      }<br>    }<br>  ],<br>  &quot;ignorePatterns&quot;: [&quot;**/*&quot;]<br>}</pre><p>And now our new file after running the script (renamed to <strong>eslint.config.js</strong>)</p><pre>// eslint.config.js<br><br>const { FlatCompat } = require(&#39;@eslint/eslintrc&#39;);<br>const js = require(&#39;@eslint/js&#39;);<br>const nxEslintPlugin = require(&#39;@nx/eslint-plugin&#39;);<br><br>const compat = new FlatCompat({<br>  baseDirectory: __dirname,<br>  recommendedConfig: js.configs.recommended,<br>});<br><br>module.exports = [<br>  ...compat.extends(&#39;plugin:prettier/recommended&#39;),<br>  { plugins: { &#39;@nx&#39;: nxEslintPlugin } },<br>  ...compat.config({ extends: [&#39;plugin:mdx/recommended&#39;] }).map((config) =&gt; ({<br>    ...config,<br>    files: [&#39;**/*.mdx&#39;],<br>    rules: {<br>      ...config.rules,<br>    },<br>  })),<br>  ...compat<br>    .config({<br>      extends: [&#39;plugin:@nx/javascript&#39;, &#39;airbnb&#39;, &#39;plugin:react/jsx-runtime&#39;],<br>      settings: {<br>        &#39;import/resolver&#39;: {<br>          node: { extensions: [&#39;.js&#39;, &#39;.jsx&#39;, &#39;.json&#39;, &#39;.ts&#39;, &#39;.tsx&#39;] },<br>        },<br>      },<br>    })<br>    .map((config) =&gt; ({<br>      ...config,<br>      files: [&#39;**/*.js&#39;, &#39;**/*.jsx&#39;],<br>      rules: {<br>        ...config.rules,<br>        quotes: [&#39;error&#39;, &#39;single&#39;, { avoidEscape: true }],<br>        &#39;import/extensions&#39;: [<br>          &#39;error&#39;,<br>          &#39;ignorePackages&#39;,<br>          {<br>            ts: &#39;never&#39;,<br>            tsx: &#39;never&#39;,<br>            js: &#39;never&#39;,<br>            jsx: &#39;never&#39;,<br>            json: &#39;always&#39;,<br>          },<br>        ],<br>      },<br>    })),<br>  ...compat<br>    .config({<br>      extends: [<br>        &#39;plugin:@nx/typescript&#39;,<br>        &#39;airbnb&#39;,<br>        &#39;airbnb-typescript&#39;,<br>        &#39;plugin:react/jsx-runtime&#39;,<br>      ],<br>    })<br>    .map((config) =&gt; ({<br>      ...config,<br>      files: [&#39;**/*.ts&#39;, &#39;**/*.tsx&#39;],<br>      rules: {<br>        ...config.rules,<br>        quotes: 0,<br>        &#39;@typescript-eslint/quotes&#39;: [&#39;error&#39;, &#39;single&#39;, { avoidEscape: true }],<br>        &#39;@typescript-eslint/no-empty-function&#39;: &#39;off&#39;,<br>        &#39;@typescript-eslint/indent&#39;: &#39;off&#39;,<br>        &#39;@typescript-eslint/comma-dangle&#39;: &#39;off&#39;,<br>        &#39;@typescript-eslint/no-unused-vars&#39;: &#39;error&#39;,<br>      },<br>      languageOptions: { parserOptions: { project: &#39;tsconfig.base.json&#39; } },<br>    })),<br>  {<br>    files: [&#39;**/*.json&#39;],<br>    // Override or add rules here<br>    rules: {},<br>    languageOptions: { parser: require(&#39;jsonc-eslint-parser&#39;) },<br>  },<br>  ...compat.config({ plugins: [&#39;n&#39;] }).map((config) =&gt; ({<br>    ...config,<br>    files: [&#39;**/*.ts&#39;, &#39;**/*.tsx&#39;, &#39;**/*.js&#39;, &#39;**/*.jsx&#39;],<br>    rules: {<br>      ...config.rules,<br>      &#39;@nx/enforce-module-boundaries&#39;: [<br>        &#39;error&#39;,<br>        {<br>          depConstraints: [<br>            {<br>              sourceTag: &#39;client&#39;,<br>              onlyDependOnLibsWithTags: [&#39;page&#39;, &#39;page-graphql&#39;, &#39;shared&#39;],<br>            },<br>            {<br>              sourceTag: &#39;server&#39;,<br>              onlyDependOnLibsWithTags: [&#39;module&#39;, &#39;shared&#39;],<br>            },<br>            {<br>              sourceTag: &#39;page&#39;,<br>              onlyDependOnLibsWithTags: [&#39;ui&#39;, &#39;shared&#39;],<br>            },<br>            {<br>              sourceTag: &#39;shared&#39;,<br>              onlyDependOnLibsWithTags: [&#39;shared&#39;],<br>            },<br>            {<br>              sourceTag: &#39;page-graphql&#39;,<br>              onlyDependOnLibsWithTags: [&#39;graphql&#39;, &#39;shared&#39;],<br>            },<br>          ],<br>        },<br>      ],<br>      &#39;import/no-named-as-default&#39;: &#39;off&#39;,<br>      &#39;import/no-extraneous-dependencies&#39;: &#39;off&#39;,<br>      &#39;import/no-default-export&#39;: &#39;error&#39;,<br>      &#39;object-curly-newline&#39;: &#39;off&#39;,<br>      &#39;jsx-a11y/label-has-associated-control&#39;: &#39;off&#39;,<br>      &#39;react/jsx-wrap-multilines&#39;: &#39;off&#39;,<br>      &#39;react/function-component-definition&#39;: &#39;off&#39;,<br>      &#39;implicit-arrow-linebreak&#39;: &#39;off&#39;,<br>      &#39;function-paren-newline&#39;: &#39;off&#39;,<br>      &#39;react/require-default-props&#39;: &#39;off&#39;,<br>      &#39;no-confusing-arrow&#39;: &#39;off&#39;,<br>      &#39;react-hooks/exhaustive-deps&#39;: &#39;error&#39;,<br>      &#39;react/jsx-closing-tag-location&#39;: &#39;off&#39;,<br>      &#39;operator-linebreak&#39;: &#39;off&#39;,<br>      &#39;import/prefer-default-export&#39;: &#39;off&#39;,<br>      &#39;no-multi-spaces&#39;: &#39;off&#39;,<br>      &#39;react/jsx-indent&#39;: &#39;off&#39;,<br>      &#39;react/jsx-props-no-spreading&#39;: &#39;off&#39;,<br>      &#39;react/jsx-curly-newline&#39;: &#39;off&#39;,<br>      &#39;jsx-a11y/aria-role&#39;: &#39;off&#39;,<br>      &#39;jsx-a11y/click-events-have-key-events&#39;: &#39;off&#39;,<br>      &#39;no-param-reassign&#39;: [&#39;error&#39;, { props: false }],<br>      &#39;comma-dangle&#39;: 0,<br>      indent: &#39;off&#39;,<br>      &#39;no-process-env&#39;: &#39;error&#39;,<br>      &#39;jsx-quotes&#39;: [&#39;error&#39;, &#39;prefer-single&#39;],<br>      &#39;react/jsx-one-expression-per-line&#39;: &#39;off&#39;,<br>    },<br>  })),<br>  {<br>    ignores: [<br>      &#39;# libs/shared/ui/stories&#39;,<br>      &#39;lib/graphql/src/gemerated/schema.graphql.ts&#39;,<br>    ],<br>  },<br>];</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*9RInThSdd807li5IYws02A.png" /><figcaption>New libs needed for ESLint v9 have been added, and ESLint package has been updated</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*2WCpseMX1YRGpXS8unZfiw.png" /><figcaption>All eslint related file have been renamed to <strong>eslint.config.js</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*07B4b8a4wTgQ0NP-S_A90A.png" /><figcaption>ESLint output within VSCode after running the NX script to migrate to flat config</figcaption></figure><p>While the migration script itself didn’t throw any errors, our ESLint configuration seems broken. On a personal note, I think that the new compat utils make the file readability even worse.</p><p>In conclusion: The migration script provided by NX is really powerful and did an amazing job, but with our codebase, it’s sadly not a perfect fit. Also, it didn’t fix our own issues concerning deprecated rules, rule scopes, etc. Let’s restart from scratch 💥.</p><p>Editor’s Note: <em>I didn’t know at the time, but the error in the ESLint output of my IDE is because I’m using </em><em>react-hooks/exhaustive-deps: &#39;error&#39; inside my main </em><em>eslint.config.js while the plugin is not imported here but in my packages&#39; </em><em>eslint.config.js. Also, at the moment I&#39;m writing this message, the latest stable version of </em><em>react-hooks/exhaustive-deps doesn&#39;t support flat config, only the release candidate version does.</em></p><h4>🚧 Fresh restart</h4><p>According to <a href="https://eslint.org/docs/latest/use/configure/migration-guide">the official v9 migration guide</a>, and from what we saw after the migration, the configuration is now an array of objects. Also, the way to use plugins and recommended rules from these plugins has changed, as we can see here on the<a href="http://ESLint official documentation about predefined configurations."> ESLint official documentation about predefined configurations.</a></p><p>Editor’s Note: <em>eslint.config.js files will use </em><em>require and </em><em>module.exports instead of </em><em>import and </em><em>export default. While this should work for most projects, ⚠️ </em><strong><em>ES modules don&#39;t work with NX at the moment with </em></strong><strong><em>.js extensions ⚠️</em></strong></p><pre>// eslint.config.js<br><br>const eslint = require(&#39;@eslint/js&#39;);<br><br>module.exports = [<br>  // Using recommended ESLint presets<br>  eslint.configs.recommended<br>];</pre><p>Now, since most of our files are written in TypeScript, we want to add back the TypeScript ESLint parser and recommended config. On top of this, let’s not forget we work in an NX monorepo, and they provide us with some cool presets to use.</p><pre>// eslint.config.js<br><br>const eslint = require(&#39;@eslint/js&#39;);<br>const tseslint = require(&#39;typescript-eslint&#39;);<br>const nx = require(&#39;@nx/eslint-plugin&#39;);<br><br>module.exports = [<br>  eslint.configs.recommended,<br>  ...tseslint.configs.recommended,<br>  ...tseslint.configs.stylistic,<br>  ...nx.configs[&#39;flat/base&#39;],<br>  ...nx.configs[&#39;flat/typescript&#39;],<br>  ...nx.configs[&#39;flat/javascript&#39;],<br>  {<br>    files: [&#39;**/*.ts&#39;, &#39;**/*.tsx&#39;],<br>    languageOptions: {<br>      parserOptions: {<br>        projectService: {<br>          defaultProject: &#39;tsconfig.base.json&#39;, // tsconfig file to fallback when no `tsconfig.json` is found<br>          allowDefaultProject: [<br>            // Files that are allow to fallback on default project -&gt; https://typescript-eslint.io/blog/announcing-typescript-eslint-v8#project-service<br>            &#39;jest.config.ts&#39;,<br>          ],<br>        },<br>        tsconfigRootDir: __dirname,<br>        ecmaFeatures: {<br>          jsx: true,<br>        },<br>      },<br>    },<br>  },<br>];</pre><p>Great, now we have a solid starter config. Let’s override our first rule as an example:</p><pre>// eslint.config.js<br><br>const eslint = require(&#39;@eslint/js&#39;);<br>const tseslint = require(&#39;typescript-eslint&#39;);<br>const nx = require(&#39;@nx/eslint-plugin&#39;);<br><br>module.exports = [<br>  eslint.configs.recommended,<br>  ...tseslint.configs.recommended,<br>  ...tseslint.configs.stylistic,<br>  ...nx.configs[&#39;flat/base&#39;],<br>  ...nx.configs[&#39;flat/typescript&#39;],<br>  ...nx.configs[&#39;flat/javascript&#39;],<br>  // As we&#39;re not specifying any files here, it will be applied to every parsed files.<br>  {<br>    rules: {<br>      &#39;no-console&#39;: &#39;warn&#39;, // https://eslint.org/docs/latest/rules/no-console<br>    },<br>  },<br>  // But this config will only be applied to files that matches the global pattern<br>  {<br>    files: [&#39;**/*.ts&#39;, &#39;**/*.tsx&#39;],<br>    languageOptions: {<br>      parserOptions: {<br>        projectService: {<br>          defaultProject: &#39;tsconfig.base.json&#39;, // tsconfig file to fallback when no `tsconfig.json` is found<br>          allowDefaultProject: [<br>            // Files that are allow to fallback on default project -&gt; https://typescript-eslint.io/blog/announcing-typescript-eslint-v8#project-service<br>            &#39;jest.config.ts&#39;,<br>          ],<br>        },<br>        tsconfigRootDir: __dirname,<br>        ecmaFeatures: {<br>          jsx: true,<br>        },<br>      },<br>    },<br>  },<br>];</pre><p>Now that we have a solid root eslint.config.js , let’s try to create one of our package eslint.config.js .</p><pre>// libs/packages/your-cool-package-name/eslint.config.js<br><br>const eslintReactBaseConfig = require(&#39;../../../eslint.config&#39;);<br><br>module.exports = [<br>  ...baseConfig,<br>]</pre><p>Since we’re working with plain JavaScript files, there’s no more extends nor root: false as before. We can simply import our files and spread them into our config 🤩.</p><p>This package is, in fact, a React package. NX also provides us with a starter config for React that we’ll use. Since it contains rules specific to React, we want to use it inside the packages’ eslint.config.js, and not in the root config file.</p><pre>// libs/packages/your-cool-package-name/eslint.config.js<br><br>const eslintReactBaseConfig = require(&#39;../../../eslint-react-base-config&#39;);<br>const nx = require(&#39;@nx/eslint-plugin&#39;);<br><br>module.exports = [<br>  // The order is really important here<br>  ...nx.configs[&#39;flat/react&#39;], // 1st we take nx react config<br>  ...eslintReactBaseConfig, // 2nd we take our own config that might overrides nx react config<br>];</pre><p>In this specific package, I want to ensure that my config is correctly applied. Let’s try to override the no-console rule we added in the root config file so that it throws an error only in this package.</p><pre>// libs/packages/your-cool-package-name/eslint.config.js<br><br>const eslintReactBaseConfig = require(&#39;../../../eslint-react-base-config&#39;);<br>const nx = require(&#39;@nx/eslint-plugin&#39;);<br><br>module.exports = [<br>  // The order is really important here<br>  ...nx.configs[&#39;flat/react&#39;], // 1st we take nx react config<br>  ...eslintReactBaseConfig, // 2nd we take our own config that might overrides nx react config<br>  {<br>    rules: {<br>      &#39;no-console&#39;: &#39;error&#39;,<br>    }<br>  },<br>];</pre><p>Without any override :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*ObGtOtOV3pu_ZV0Eda93XQ.png" /><figcaption>test-file.tsx warning due to console.log rule in root eslint.config.js</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*BD4rpCW5Zq1hH4peKXeiCA.png" /><figcaption>yarn nx run packages-your-cool-package-name-dashboard:lint → Runs ESLint on our package using the package using it’s own eslint.config.js → Display a warning ✅</figcaption></figure><p>After overriding libs/packages/your-cool-package-name/eslint.config.js :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*-f7uayCpf_filZQXKfuCNA.png" /><figcaption>test-file.tsx error due to console.log rule override in libs/packages/campaign-dashboard/eslint.config.js</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*_0FtYQ59Yqs1zMCxnIUTJQ.png" /><figcaption>yarn nx run packages-your-cool-package-name:lint → Runs ESLint on our package using the package using it’s own eslint.config.js → Throw an error ✅</figcaption></figure><p>It seems to work great in the IDE and with the NX lint task 🎉. Let’s now check with our lint-staged pre-commit (regular Husky and lint-staged setup). The commit should be canceled as we have an error due to the console.log in our test-file.tsx.</p><pre>// package.json<br>{<br> .....<br>  &quot;lint-staged&quot;: {<br>    &quot;*.{ts,tsx,js,jsx}&quot;: &quot;eslint&quot;<br>  },<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*NLYjER4Kpv9xSRmbr6_bkA.png" /><figcaption>Lint-staged didn’t throw any error, even if we had an error</figcaption></figure><p>What happened? As far as I understand, NX previously worked by <strong>ignoring all files</strong> in the main .eslintrc.json with ignorePatterns: [&quot;**/*&quot;], which we removed because this is not supported anymore with the new flat config. Then, for each package, it reverted this with ignorePatterns: [&quot;!**/*&quot;]. But we can&#39;t do that anymore with the new flat configuration, and therefore, the lint-staged script uses the main eslint.config.js file, which does not include the specific package rule override for no-console.</p><p>After few research, the best solution so far that I found was to :</p><ul><li>Have, for each one of our packages, a .lintstagedrc configuration file.</li><li>Remove the lint-staged part in the package.json</li></ul><pre>diff --git a/libs/packages/your-cool-package-name/.lintstagedrc b/libs/packages/your-cool-package-name/.lintstagedrc<br>new file mode 100644<br>index 000000000..d1c7c3137<br>--- /dev/null<br>+++ b/libs/packages/your-cool-package-name/.lintstagedrc<br>@@ -0,0 +1,3 @@<br>+{<br>+  &quot;*.{ts,tsx,js,jsx}&quot;: &quot;eslint&quot;<br>+}<br>diff --git a/package.json b/package.json<br>index beb083737..5cece1d8b 100644<br>--- a/package.json<br>+++ b/package.json<br>@@ -208,8 +208,5 @@<br>     &quot;webpack-dev-server&quot;: &quot;^5.1.0&quot;,<br>     &quot;whatwg-fetch&quot;: &quot;^3.6.20&quot;<br>   },<br>-  &quot;packageManager&quot;: &quot;yarn@4.4.1&quot;,<br>-  &quot;lint-staged&quot;: {<br>-    &quot;*.{ts,tsx,js,jsx}&quot;: &quot;eslint&quot;<br>-  }<br>+  &quot;packageManager&quot;: &quot;yarn@4.4.1&quot;<br> }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*_6NT16jDykmWbFKhYe2ASg.png" /><figcaption>lint-stage throw an ESLint error 🎉</figcaption></figure><p>Now we can see that an error is thrown ! Our new .lintstagedrc file is used to parse the added test-file.tsx . That’s a bit of additional boilerplate, but it does work great !</p><h4>Conclusion</h4><p>At this point we have:</p><ul><li>A working root eslint.config.js which extends from the recommended rules from ESLintand TSLint.</li><li>A package that extends from our root eslint.config.js and allows us to override specific rules.</li><li>NX lint task and pre-commit works great.</li></ul><p>Next steps will be to:</p><ul><li>Add back, one by one, the rules that we want to keep from our previous config.</li><li>Uninstall unused dev dependencies that we won’t keep.</li><li>Celebrate 🎉</li></ul><p>Thanks for reading this article 🙏 Hope it helped you. Do not hesitate to post a comment if you have any questions or issues with your migration.</p><h4>Our own final ESLint configurations after migration</h4><p>In case you want some inspiration for your ESlint configuration, here’s what our configs looks like</p><pre>// eslint.config.js<br><br>const eslint = require(&#39;@eslint/js&#39;);<br>const tseslint = require(&#39;typescript-eslint&#39;);<br>const nx = require(&#39;@nx/eslint-plugin&#39;);<br>const eslintPluginPrettierRecommended = require(&#39;eslint-plugin-prettier/recommended&#39;);<br>const stylistic = require(&#39;@stylistic/eslint-plugin&#39;);<br><br>module.exports = [<br>  eslint.configs.recommended,<br>  ...tseslint.configs.recommended,<br>  ...tseslint.configs.stylistic,<br>  ...nx.configs[&#39;flat/base&#39;],<br>  ...nx.configs[&#39;flat/typescript&#39;],<br>  ...nx.configs[&#39;flat/javascript&#39;],<br>  eslintPluginPrettierRecommended, // The order is important here, it must be the last imported plugin<br>  {<br>    plugins: {<br>      &#39;@stylistic&#39;: stylistic, // https://eslint.style/packages/default#install<br>    },<br><br>    rules: {<br>      &#39;no-console&#39;: [&#39;error&#39;, { allow: [&#39;warn&#39;, &#39;error&#39;, &#39;info&#39;] }], // https://eslint.org/docs/latest/rules/no-console<br>      &#39;no-var&#39;: &#39;error&#39;, // https://eslint.org/docs/latest/rules/no-var&#39;<br>      &#39;no-process-env&#39;: &#39;error&#39;, // Use &quot;getEnvVariables&quot; utils instead -&gt; https://eslint.org/docs/latest/rules/no-process-env<br>      &#39;consistent-return&#39;: &#39;error&#39;, // https://typescript-eslint.io/rules/consistent-return/<br>      &#39;no-dupe-keys&#39;: &#39;off&#39;, // Already handlded by Typescript tsconfig -&gt; https://eslint.org/docs/latest/rules/no-dupe-keys<br>      &#39;jsx-a11y/aria-role&#39;: &#39;off&#39;, // https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/aria-role.md<br>      &#39;default-case&#39;: &#39;error&#39;, // Added by nx react flat config -&gt; https://eslint.org/docs/latest/rules/default-case<br>      &#39;no-unused-vars&#39;: &#39;off&#39;, // Using TS rule instead which also works with non TS files -&gt; https://eslint.org/docs/latest/rules/no-unused-vars#vars-local<br>      &#39;@typescript-eslint/no-unused-vars&#39;: &#39;error&#39;, // https://typescript-eslint.io/rules/no-unused-vars<br>      &#39;no-nested-ternary&#39;: &#39;error&#39;, // https://eslint.org/docs/latest/rules/no-nested-ternary<br>      &#39;no-shadow&#39;: &#39;off&#39;, // Using TS rule isntead which also works with non TS Files -&gt; https://eslint.org/docs/latest/rules/no-shadow<br>      &#39;@typescript-eslint/no-shadow&#39;: &#39;error&#39;, // https://typescript-eslint.io/rules/no-shadow<br>      &#39;no-use-before-define&#39;: &#39;off&#39;, // Using TS rule isntead which also works with non TS Files -&gt; https://eslint.org/docs/latest/rules/no-use-before-define<br>      &#39;@typescript-eslint/no-use-before-define&#39;: &#39;error&#39;, // https://typescript-eslint.io/rules/no-use-before-define/<br>      &#39;default-param-last&#39;: &#39;off&#39;, // Using TS rule isntead which also works with non TS Files -&gt; https://eslint.org/docs/latest/rules/default-param-last<br>      &#39;@typescript-eslint/default-param-last&#39;: &#39;error&#39;, // https://typescript-eslint.io/rules/default-param-last/<br>      &#39;@typescript-eslint/consistent-type-definitions&#39;: &#39;off&#39;, // While most of the time we want to force type, we sometimes need to enable &quot;interface&quot; for module augmentation -&gt; https://typescript-eslint.io/rules/consistent-type-definitions/<br>      &#39;@stylistic/quotes&#39;: [&#39;error&#39;, &#39;single&#39;, { avoidEscape: true }], // Force single quote, avoid unnecessary template literals why allowing when necessary -&gt; https://eslint.style/rules/default/quotes<br>      &#39;no-restricted-exports&#39;: [<br>        // https://eslint.org/docs/latest/rules/no-restricted-exports<br>        &#39;error&#39;,<br>        {<br>          restrictDefaultExports: {<br>            direct: true,<br>            named: true,<br>            defaultFrom: true,<br>            namedFrom: true,<br>            namespaceFrom: true,<br>          },<br>        },<br>      ],<br>      &#39;@typescript-eslint/naming-convention&#39;: [<br>        // Added back previous configuration from eslint-config-airbnb-typescript -&gt; Also works with non TS files -&gt; https://github.com/iamturns/eslint-config-airbnb-typescript/blob/303e346214847385bee4016367ff3b1b9978e337/lib/shared.js#L41<br>        &#39;error&#39;,<br>        {<br>          selector: &#39;variable&#39;,<br>          format: [&#39;camelCase&#39;, &#39;PascalCase&#39;, &#39;UPPER_CASE&#39;],<br>        },<br>        { selector: &#39;function&#39;, format: [&#39;camelCase&#39;, &#39;PascalCase&#39;] },<br>        { selector: &#39;typeLike&#39;, format: [&#39;PascalCase&#39;] },<br>      ],<br>      &#39;no-restricted-syntax&#39;: [<br>        // Added back previous configuration from eslint-config-airbnb-base -&gt; https://github.com/airbnb/javascript/blob/b912288e4bf7fa46d9254d3cdfa190e9b59f36c0/packages/eslint-config-airbnb-base/rules/style.js#L340<br>        &#39;error&#39;,<br>        {<br>          selector: &#39;ForInStatement&#39;,<br>          message:<br>            &#39;for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.&#39;,<br>        },<br>        {<br>          selector: &#39;ForOfStatement&#39;,<br>          message:<br>            &#39;iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.&#39;,<br>        },<br>        {<br>          selector: &#39;LabeledStatement&#39;,<br>          message:<br>            &#39;Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.&#39;,<br>        },<br>        {<br>          selector: &#39;WithStatement&#39;,<br>          message:<br>            &#39;`with` is disallowed in strict mode because it makes code impossible to predict and optimize.&#39;,<br>        },<br>      ],<br>    },<br>    ignores: [&#39;jest.config.ts&#39;], // Not able to properly setup the root jest.config.ts at the moment<br>  },<br>  {<br>    files: [&#39;**/*.ts&#39;, &#39;**/*.tsx&#39;],<br>    languageOptions: {<br>      parserOptions: {<br>        projectService: {<br>          defaultProject: &#39;tsconfig.base.json&#39;, // tsconfig file to fallback when no `tsconfig.json` is found<br>          allowDefaultProject: [<br>            // Files that are allow to fallback on default project -&gt; https://typescript-eslint.io/blog/announcing-typescript-eslint-v8#project-service<br>            &#39;jest.config.ts&#39;,<br>          ],<br>        },<br>        tsconfigRootDir: __dirname,<br>        ecmaFeatures: {<br>          jsx: true,<br>        },<br>      },<br>    },<br>    rules:<br>      // Rules that are specific to TS files, mainly because they require the parserService to be generated<br>      {<br>        &#39;consistent-return&#39;: &#39;off&#39;, // Disabled because using TS rule instead https://typescript-eslint.io/rules/consistent-return/<br>        &#39;@typescript-eslint/consistent-return&#39;: &#39;error&#39;, // https://typescript-eslint.io/rules/consistent-return/<br>        &#39;@typescript-eslint/no-unnecessary-template-expression&#39;: &#39;error&#39;, // https://typescript-eslint.io/rules/no-unnecessary-template-expression<br>      },<br>  },<br>  {<br>    files: [&#39;**/*.ts&#39;, &#39;**/*.tsx&#39;, &#39;**/*.js&#39;, &#39;**/*.jsx&#39;],<br>    rules: {<br>      &#39;@nx/enforce-module-boundaries&#39;: [<br>        &#39;error&#39;,<br>        {<br>          enforceBuildableLibDependency: true,<br>          allow: [&#39;^.*/eslint(\\.base)?\\.config\\.[cm]?js$&#39;],<br>          depConstraints: [<br>            {<br>              sourceTag: &#39;client&#39;,<br>              onlyDependOnLibsWithTags: [&#39;page&#39;, &#39;page-graphql&#39;, &#39;shared&#39;],<br>            },<br>            {<br>              sourceTag: &#39;server&#39;,<br>              onlyDependOnLibsWithTags: [&#39;module&#39;, &#39;shared&#39;],<br>            },<br>            {<br>              sourceTag: &#39;page&#39;,<br>              onlyDependOnLibsWithTags: [&#39;ui&#39;, &#39;shared&#39;],<br>            },<br>            {<br>              sourceTag: &#39;shared&#39;,<br>              onlyDependOnLibsWithTags: [&#39;shared&#39;],<br>            },<br>            {<br>              sourceTag: &#39;page-graphql&#39;,<br>              onlyDependOnLibsWithTags: [&#39;graphql&#39;, &#39;shared&#39;],<br>            },<br>          ],<br>        },<br>      ],<br>    },<br>  },<br>];</pre><p>As we have a lot of React packages, I’ve created an intermediary file that we import in each of our packages, to avoid duplicating common rules</p><pre>// eslint-react-base-config.js<br><br>const nx = require(&#39;@nx/eslint-plugin&#39;);<br>const reactHooks = require(&#39;eslint-plugin-react-hooks&#39;);<br>const baseConfig = require(&#39;./eslint.config&#39;);<br><br>/**<br> * Contains a set of rules and plugins that **`MUST`** be used in every `React` packages and apps.<br> * It **`MUST NOT`** contain rules or plugins related to a specific package as this is shared to every `React` packages and apps.<br> *<br> * ```<br> * // my-cool-react-package/eslint.config.js<br> * const eslintReactBaseConfig = require(&#39;../../../eslint-react-base-config&#39;)<br> *<br> * modules.exports = [<br> *   // First import the react base config,<br> *   ...eslintReactBaseConfig,<br> *   // Then, override or extends rules specific to your package below<br> *   {<br> *     files [&quot;**\/*.ts&quot;],<br> *     rules: {<br> *       // ...<br> *     }<br> *   }<br> * ]<br> *<br> * ```<br> */<br>module.exports = [<br>  // The order is really important here<br>  ...nx.configs[&#39;flat/react&#39;], // 1st we take nx react config<br>  ...baseConfig, // 2nd we take our own config that might overrides nx react config<br>  {<br>    rules: {<br>      ...reactHooks.configs.recommended.rules, // Must import it here because extending from nx.configs[&quot;flat/react&quot;] -&gt; https://www.npmjs.com/package/eslint-plugin-react-hooks<br>      &#39;react-hooks/exhaustive-deps&#39;: &#39;error&#39;, // Recommended rules is set to warning, but we want to forbid it -&gt; https://www.npmjs.com/package/eslint-plugin-react-hooks<br>      &#39;react/no-array-index-key&#39;: &#39;error&#39;, // Must import it here because extending from nx.configs[&quot;flat/react&quot;] -&gt; https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-array-index-key.md<br>      &#39;import/order&#39;: [<br>        // Must define it here as extending from nx.configs[&quot;flat/react&quot;] -&gt; https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md<br>        &#39;error&#39;,<br>        { groups: [[&#39;builtin&#39;, &#39;external&#39;, &#39;internal&#39;]] }, // Added back previous configuration from eslint-config-airbnb-base -&gt; https://github.com/airbnb/javascript/blob/b912288e4bf7fa46d9254d3cdfa190e9b59f36c0/packages/eslint-config-airbnb-base/rules/imports.js#L149<br>      ],<br>    },<br>  },<br>  {<br>    files: [&#39;**/*.js&#39;, &#39;**/*.jsx&#39;],<br>    rules: {<br>      &#39;import/extensions&#39;: [<br>        // Must import it here because extending from nx.configs[&quot;flat/react&quot;] -&gt; Avoid the need of extensions when importing inside a JS File -&gt; https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/extensions.md<br>        &#39;error&#39;,<br>        &#39;never&#39;,<br>        {<br>          json: &#39;always&#39;, // Our JSON parser NEEDS the .json extension<br>        },<br>      ],<br>    },<br>    settings: {<br>      &#39;import/resolver&#39;: {<br>        // Must import it here because extending from nx.configs[&quot;flat/react&quot;]<br>        node: true, // Make JS file understand correctly the path when importing from a TS file -&gt; https://github.com/import-js/eslint-plugin-import?tab=readme-ov-file#typescript<br>      },<br>    },<br>  },<br>];</pre><pre>// libs/packages/your-cool-package-name/eslint.config.js<br><br>const eslintReactBaseConfig = require(&#39;../../../eslint-react-base-config&#39;);<br><br>module.exports = [<br>  ...eslintReactBaseConfig,<br>  {<br>    files: [<br>      // Must be default exported as we&#39;re mocking internal implementation<br>      &#39;src/__mocks__/svg.ts&#39;,<br>      // Jest config must be default exported to be parsed by Jest CLI<br>      &#39;jest.config.ts&#39;,<br>    ],<br>    rules: {<br>      &#39;no-restricted-exports&#39;: [<br>        // https://eslint.org/docs/latest/rules/no-restricted-exports<br>        &#39;error&#39;,<br>        {<br>          restrictDefaultExports: {<br>            direct: false, // We only want to allow regular default export<br>            named: true,<br>            defaultFrom: true,<br>            namedFrom: true,<br>            namespaceFrom: true,<br>          },<br>        },<br>      ],<br>    },<br>  },<br>];</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca5168976c6a" width="1" height="1" alt=""><hr><p><a href="https://splio.tech/eslint-v8-x-legacy-config-migration-to-v9-with-flat-config-on-a-monorepo-using-nx-ca5168976c6a">ESLint v8.x legacy config migration to v9 with flat config, on a Monorepo using NX</a> was originally published in <a href="https://splio.tech/">Splio Product Engineering &amp; Design</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>