File naming convention in ReasonML


#1

I’m wondering if there are already set naming conventions for file naming in ReasonML. Coming from React/JS ecosystem I’m used to naming the files that are components as PascalCase, MyComponent.js, but I often see in the Reason code bases lowercase names app.re, but then would I name my component in this way: mycomponent.re or my_component.re, etc.?


#2

Hmm. This is really your choice. Because a file is mapped directly to a module. I usually named the file the same as module name

mycomponent.re => Mycomponent
my_component.re => My_Component


#3

app.re is the old convention. App.re is the current one.


#4

I’ve been using capitalized files, so MyComponent.re => MyComponent. I see no downsides to it other than the emotional reaction “ewww capitalized file names!” but once you get over that your teammates really appreciate the easy mapping :wink:


#5

In addition to capitalizing filenames to match their module names I’ve also acquired the habit of lowercasing the names of files I don’t use as modules, the entry points. Which is typically only one file, but sometimes I have a bunch of scripts, for example. Like redex-scripts, where I also use snake_case, because I sure as hell ain’t going to have a bunch of PascalCased or camelCased scripts! But anyway, having them lowercased makes it really easy to spot the entry point(s) :slight_smile:


#6

Here are the general guidelines: https://reasonml.github.io/docs/en/project-structure.html#file-casing

Btw the docs site’s search uses Algolia, so you can search either file or case or whatever and it should return the relevant results.


#7

Can filenames contain additional dots in the name? For example MyComponent.react.re? What module name would it map to?


#8

They can’t currently