<?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 Ok</title>
    <description>The latest articles on DEV Community by Denis Ok (@okayx6).</description>
    <link>https://dev.to/okayx6</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%2F693727%2F2a9bf3ed-bcc2-46fe-a973-7a41f0644a37.jpeg</url>
      <title>DEV Community: Denis Ok</title>
      <link>https://dev.to/okayx6</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/okayx6"/>
    <language>en</language>
    <item>
      <title>Perfect F# React Dev Setup in F# Fable with VS Code,  Formatting/Linting</title>
      <dc:creator>Denis Ok</dc:creator>
      <pubDate>Wed, 08 Sep 2021 11:38:36 +0000</pubDate>
      <link>https://dev.to/okayx6/perfect-f-react-dev-setup-in-f-fable-with-vs-code-formatting-linting-2co8</link>
      <guid>https://dev.to/okayx6/perfect-f-react-dev-setup-in-f-fable-with-vs-code-formatting-linting-2co8</guid>
      <description>&lt;h2&gt;
  
  
  Why this Post?
&lt;/h2&gt;

&lt;p&gt;I want to help make the switch from &lt;strong&gt;Javascript/Typescript React&lt;/strong&gt; to &lt;strong&gt;&lt;a href="https://fable.io/" rel="noopener noreferrer"&gt;F# Fable&lt;/a&gt;&lt;/strong&gt; as smooth as possible, for those lucky or adventurous enough to do it 😀, and this post presents some of my findings.&lt;/p&gt;

&lt;h3&gt;
  
  
  Life: a Honeymoon with Javascript's Ecosystem
&lt;/h3&gt;

&lt;p&gt;As a matter of fact, many &lt;strong&gt;JS/TS&lt;/strong&gt; jobs in &lt;strong&gt;React/Angular&lt;/strong&gt; came to me. Clearly the dev experience was comfortable to work in a team, especially to enforce clean and tidy code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automatically reorganize imports&lt;/li&gt;
&lt;li&gt;Autoreformatting with &lt;strong&gt;Prettier&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Best practices enforcement with &lt;strong&gt;ESLint&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;and so on... 🤪&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  F# and Fable's Appeal
&lt;/h3&gt;

&lt;p&gt;The thing is, even with &lt;a href="https://lodash.com/" rel="noopener noreferrer"&gt;lodash&lt;/a&gt;, coding mildly complex data processing algorithms in JS/TS can very unwieldly pretty fast, so I often whine &lt;em&gt;this would be so much easier in F#!&lt;/em&gt; and wonders: &lt;em&gt;how is life with Fable nowadays?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A lot of issues can make the transition unpleasant. For example, a few years ago, Fantomas was no always so usable, it lacked robustness for some corner cases, messying your code.&lt;/p&gt;

&lt;p&gt;The fact is: life is pretty great with F# in 2021.&lt;/p&gt;

&lt;h2&gt;
  
  
  VS Code Extensions: the minimum
&lt;/h2&gt;

&lt;p&gt;To be comfortable with front-end dev in F#, you need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=Ionide.Ionide-fsharp" rel="noopener noreferrer"&gt;Ionide&lt;/a&gt; of course, which is bundled with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/fsprojects/fantomas" rel="noopener noreferrer"&gt;Fantomas&lt;/a&gt;: the code formatter&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://fsprojects.github.io/FSharpLint/" rel="noopener noreferrer"&gt;FSharpLint&lt;/a&gt;: the Lint suggestions&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow" rel="noopener noreferrer"&gt;Indent Rainbow&lt;/a&gt;: for &lt;strong&gt;nested list based development&lt;/strong&gt; 😀! Not so needed when doing HTML/JSX tags as you get context from the closing tags surrounding your cursor, but in Fable, it will save you headaches trying to find where to put the closing list bracket &lt;code&gt;]&lt;/code&gt; at the right indentation level!&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fduudg9ra3n30txmybr8v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fduudg9ra3n30txmybr8v.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's tweak Fantomas for an optimized dev experience!&lt;/p&gt;

&lt;h3&gt;
  
  
  EditorConfig for nice Fable formatting
&lt;/h3&gt;

&lt;p&gt;We are going to start with Fantomas' formatting which support the &lt;code&gt;.editorconfig&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;fsharp_single_argument_web_mode&lt;/code&gt; setting is indeed very important to have a formatting adapted to Fable, otherwise the default one is going to be impractical!&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;.editorconfig&lt;/code&gt; file at the root of your folder with this following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[*.fs]
indent_size=2   # I feel 4 is a bit too much for front-end dev
fsharp_single_argument_web_mode=true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Before
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fquj760y5a7lia5m9xasy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fquj760y5a7lia5m9xasy.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  After
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3fftg6u0wescpdmbnvle.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3fftg6u0wescpdmbnvle.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Package Management: NuGet + NPM combined = Femto!
&lt;/h2&gt;

&lt;p&gt;Working with Fable bindings consists in integrating NPM packages (code written in &lt;em&gt;Javascript&lt;/em&gt;), as well as NuGet packages written in F# together.&lt;/p&gt;

&lt;p&gt;Dealing with both package manager can be a burden, so please install &lt;a href="https://github.com/Zaid-Ajaj/Femto" rel="noopener noreferrer"&gt;femto&lt;/a&gt;, a very easy-to-use &amp;amp; magic dotnet CLI tool:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet tool install femto --global
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, if you need to install the Feliz Bulma package&lt;/p&gt;

&lt;p&gt;These lines&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Nuget package
Install-Package Feliz.Bulma

# NPM package
npm install bulma
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will be zipped into this single line!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;femto install Feliz.Bulma
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And voilà!&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl4Jz3a8jO92crUlWM%2Fgiphy.gif%3Fcid%3D790b761172caf4c6b74e077646155c1efd3f85cf1cf3f86d%26rid%3Dgiphy.gif%26ct%3Dg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl4Jz3a8jO92crUlWM%2Fgiphy.gif%3Fcid%3D790b761172caf4c6b74e077646155c1efd3f85cf1cf3f86d%26rid%3Dgiphy.gif%26ct%3Dg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  It's great to code in F# in 2021
&lt;/h2&gt;

&lt;p&gt;F# has come a long way, I still remember when I used to be pretty happy with the tooling even with its imperfections: semantic syntax highlighting, IntelliSense, renaming, auto opening of namespaces/modules...&lt;/p&gt;

&lt;p&gt;I guess it was fine for backend work with highly skilled, hardcore and disciplined seniors and a strict PR review process.&lt;/p&gt;

&lt;p&gt;But having now worked in a team on front-end with heterogenous levels of developers, where we break and restructure our code much more differently and often, I can see that formatting &amp;amp; linting tools give an unexpected great added-value in this context!&lt;/p&gt;

&lt;p&gt;I hope you found practical answers to help you hack comfortably and in harmony!&lt;/p&gt;

</description>
      <category>fsharp</category>
      <category>webdev</category>
      <category>react</category>
      <category>vscode</category>
    </item>
  </channel>
</rss>
