Format JS
Format-js is now available as a separate Atom package for use with Nuclide. However, it is currently experimental. For example, this currently does not handle using relative paths for the automatic requires.
Format-js is a package with a goal of getting rid of worrying about every little formatting detail you might run across while writing Flow or JavaScript code. For more information about the Format-js package visit the Format-js Atom package page.
To install the Format-js package:
- Open the Nuclide Settings tab either by pressing
Cmd+,
(Ctrl-,
on Linux) or by going toPackage | Settings View | Open
. - Select Packages from the list at the left, and search for
nuclide-format-js
. - Click Install.
Currently, Format-js is focused on automatically adding, removing, and formatting, your require
statements.
Auto-Require
Adding require
statements automatically allows you to focus on writing code without
worrying about that overhead. For example, if you try to use a variable that has not been declared
elsewhere, we will try to add it as a require
.
This assumes the
require
added is a valid module. Of course, it might not be. However, something like the Flow typechecker should tell you when you are usingrequire
on an entity that is not a module.
Take the following code example:
If you press Cmd-Shift-I
(Ctrl-Shift-I
on Linux), your code will be analyzed for types that
you are using in your code that may need to be require
d. The possible require
s for your code are then added.
You can then check if these are correct and modify accordingly. For example, maybe instead of
const
, you want var
.
Settings
There are customizable settings for the Format-js package.
- Open the Nuclide Settings tab either by pressing
Cmd+,
(Ctrl-,
on Linux) or by going toPackage | Settings View | Open
. - Select Packages from the list at the left, and search for
nuclide-format-js
. - Click on the Settings button for the Format-js package.
You can also enable or disable keybindings in the Format-js settings.