<?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: Denis Raslov</title>
    <description>The latest articles on DEV Community by Denis Raslov (@denisraslov).</description>
    <link>https://dev.to/denisraslov</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%2F383804%2F919fa7af-98ca-4686-a92e-d440d1998f26.jpg</url>
      <title>DEV Community: Denis Raslov</title>
      <link>https://dev.to/denisraslov</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/denisraslov"/>
    <language>en</language>
    <item>
      <title>📁 FoldersLint: Directory structure linter for JavaScript projects</title>
      <dc:creator>Denis Raslov</dc:creator>
      <pubDate>Mon, 18 May 2020 18:38:50 +0000</pubDate>
      <link>https://dev.to/denisraslov/folderslint-directory-structure-linter-for-javascript-projects-bjl</link>
      <guid>https://dev.to/denisraslov/folderslint-directory-structure-linter-for-javascript-projects-bjl</guid>
      <description>&lt;h3&gt;
  
  
  Problem
&lt;/h3&gt;

&lt;p&gt;A living front-end project is changing constantly over the time. And it's difficult to control different aspects of its consistency sometimes. Even though you can have a proper code review process, some things still could be missed. Because reviews are being done by people, and people can miss things.&lt;/p&gt;

&lt;p&gt;Of course, some aspects of control over consistency are usually automated. There are linters for JavaScript, TypeScript, CSS code (&lt;strong&gt;eslint&lt;/strong&gt;, &lt;strong&gt;tslint&lt;/strong&gt;, &lt;strong&gt;stylelint&lt;/strong&gt;), a linter for documentation's markdown and even a linter for commits comments. For those who are not aware, these are tools that analyze your code (or markdown, strings, other sources) to find problems and mismatches with patterns you specify in their configuration.&lt;/p&gt;

&lt;p&gt;But there are still things which could go out of control. One of these things is a &lt;strong&gt;directory structure of the project&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--75_gw3Vl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ry2beuz0dix8subd4gk1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--75_gw3Vl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ry2beuz0dix8subd4gk1.png" alt="messy project structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If a project is large enough, then it has enormous count of directories and files. Consistency in this aspect is also very important thing. Clearly defined structure helps to raise clarity of the project and reduce its complexity. It makes developers always know where to put files and where find them. It's necessary to avoid chaos in such projects.&lt;/p&gt;

&lt;p&gt;Of course, the very first step for fixing this problem seems to be clear. Define needed directory structure, put it in the documentation, present it for the team and try to follow it. It can make things better. Some developers will follow it. Still some of developers can be not aware of the rule, some can understand it not correctly, some do tasks in limited time and just care more about completing their tasks, not the directory structure. In the end, it will hardly be the solution solving 100% of the problem.&lt;/p&gt;

&lt;h3&gt;
  
  
  Automate what can be automated
&lt;/h3&gt;

&lt;p&gt;The idea here is why can't we automate this control? Linting of code is automated and this works perfectly fine. No one can forget about it or skip it, because it's being run before every commit and it won't let you do the commit if there are some problems. So, let's lint project directory structure the same way!&lt;/p&gt;

&lt;p&gt;That's why &lt;strong&gt;FoldersLint&lt;/strong&gt; was created. Basically, it lets you configure directory structure rules in a configuration file and check if existed or new files fit these rules.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic usage of FoldersLint
&lt;/h3&gt;

&lt;p&gt;A config for &lt;strong&gt;FoldersLint&lt;/strong&gt; looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;src&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// optional&lt;/span&gt;
   &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;rules&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
     &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;components/*&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pages/components/*/utils&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hooks&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
     &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;legacy/**&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
   &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;code&gt;root&lt;/code&gt; is a directory the structure of which should be checked.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rules&lt;/code&gt; is an array of rules which define permitted directory paths. You can use either the exact path of a directory or specific patters &lt;code&gt;*&lt;/code&gt; and &lt;code&gt;**&lt;/code&gt; to reach some flexibility.&lt;/p&gt;

&lt;p&gt;When a config is created, all you need to lint your project structure is run the tool via terminal (a directory path parameter is optional):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; folderslint [directoryPath]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It will check all needed folders and show errors if some of them are not compatible with the rules list:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IkUP-I8E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0k0g8j85jfi55ys6hul8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IkUP-I8E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0k0g8j85jfi55ys6hul8.png" alt="FoldersLint in action"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PROFIT!&lt;/p&gt;

&lt;h3&gt;
  
  
  Linting staged files
&lt;/h3&gt;

&lt;p&gt;If your project has not ideal directory structure, the migration on the right one probably should be done not at a single time, but iteratively. So, running the lint on the whole project won't be really useful in such case.&lt;/p&gt;

&lt;p&gt;However, there is another approach that can help here. You can also lint only the files that were changed in a commit. It can be done with the tool named &lt;a href="https://github.com/okonet/lint-staged"&gt;lint-staged&lt;/a&gt; in a couple with any linter, so with &lt;strong&gt;FoldersLint&lt;/strong&gt; as well.&lt;/p&gt;

&lt;p&gt;Using this approach you will be confident that all the new files are created taking the rules into account. Already existed files will also be moving to right directories while they are being changing. Like this, step by step you will be going to the consistent directory structure.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;You can find FoldersLint and more of its documentation on &lt;a href="https://github.com/denisraslov/folderslint"&gt;GitHub&lt;/a&gt; and &lt;a href="https://www.npmjs.com/package/folderslint"&gt;NPM&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Feel free to discuss this tool, report issues and propose new ideas! ✌️&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The cover photo is by &lt;a href="https://unsplash.com/@viktortalashuk?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Viktor Talashuk&lt;/a&gt; and taken from &lt;a href="https://unsplash.com/?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>opensource</category>
      <category>node</category>
    </item>
  </channel>
</rss>
