FORGEBOX Enterprise 🚀 - Take your ColdFusion (CFML) Development to Modern Times! Learn More...

cfformat

v0.13.6 Public

commandbox-cfformat

A CommandBox module for formatting CFML components. When installed, it registers a cfformat namespace in CommandBox. The base command is cfformat run and is called with a path directly to a component, or a path to a directory. When a directory is passed, that directory is crawled for component files, and every component found is formatted.

cfformat run ./models/MyComponent.cfc
cfformat run ./models/

Important: commandbox-cfformat switched from a single cfformat command to a cfformat namespace in v0.13.0. If you have scripts making use of cfformat, they will need to be updated.

If it is passed a component path it will, by default, print the formatted component text to the console. You can redirect this output to a new file if you wish. Alternatively you can use the --overwrite flag to overwrite the component in place instead of printing to the console.

When passed a directory, cfformat run always overwrites component files in place, and so it will ask for confirmation before proceeding. Here you can use the --overwrite flag to skip this confirmation check.

Note: cfformat run is aliased to fmt, so the following syntax can be used as well:

fmt ./models/MyComponent.cfc
fmt ./models/

Checking Formatting

The cfformat check command can be used to determine whether files are formatted according to the currently defined settings. It will report on the status of the file(s) and return an appropriate exit code, without actually formatting them.

cfformat check ./models/

Watching Directories

cfformat watch can also be called with a directory path. It uses CommandBox's built in support for file watching to watch that directory for component changes, and will perform formatting passes on those files.

cfformat watch ./

Settings

Settings are managed via the cfformat settings namespace. To see the settings used for formatting, use the cfformat settings show command. It dumps the settings that would be used for formatting to the console:

cfformat settings show
# or
cfformat settings show /some/path
# or
cfformat settings show path/to/my.cfc /path/to/.cfformat.json

The following order is used to resolve the settings used for formatting:

  1. Base settings
  2. A .cfformat.json file in your home directory
  3. A .cfformat.json file found in the directory where formatting will be performed, or a parent directory thereof. Parent directories will be searched for a .cfformat.json file recursively until one is found or the root directory is reached. If a folder contains a .git directory that will also halt the search.
  4. A path to a settings file passed into the command

These settings will be merged together starting with the base settings and then merging each level on top.

If you want to place a settings file in a directory other than your home directory (for number 2 above) you can set the cfformat.settings config setting to a different path:

config set cfformat.settings=/path/to/.cfformat.json

Specifying a settings file to use inline when running cfformat is done as follows:

cfformat run path/to/my.cfc /path/to/.cfformat.json

For more information on the settings used and what they do please see the reference. You can also print reference information to the console using the cfformat settings info command. It can be passed either a full setting name, or just a prefix:

cfformat settings info array.padding
cfformat settings info array

There is also a settings wizard which can be used to create a .cfformat.json file. It walks through all of the settings, showing what each one does, and allowing you to select your preferences (the default for each setting will be preselected). Afterward it will prompt you for a location to save your new settings file.

cfformat settings wizard

Ignoring Code Sections

Use the special comments // cfformat-ignore-start and // cfformat-ignore-end (or the equivalent block comment or tag comment syntax) to have cfformat return the contained code as is without formatting it:

// cfformat-ignore-start
test = [1,2,3,4,5,6,7,8];
// cfformat-ignore-end

Note: When doing this it is important to keep your start and end comment flags at the same level of the file. In other words, the following will not work:

// cfformat-ignore-start
if (true) {
    ...
    // cfformat-ignore-end
}

Syntect

Behind the scenes, cfformat makes use of the syntect library along with syntax files from Sublime Text's Packages repository to create an executable that uses the CFML syntax for Sublime Text to generate syntax scopes for component files. cfformat attempts to download this executable from GitHub when installed, or when it is updated (if necessary). If it is unable to download the executable, it should print a message to the console prompting you to download from GitHub, and indicating where to put it. If you have Rust installed, you can also build the executable yourself by running the build.cfc task runner in the root of this repository:

task run build.cfc

Here are all the versions for this package. Please note that you can leverage CommandBox package versioning to install any package you like. Please refer to our managing package version guide for more information.

Version Created Last Update Published By Stable Actions
Current
0.13.6 Feb 14 2020 03:43 PM Feb 14 2020 03:43 PM
Version History
0.13.5 Feb 01 2020 01:01 PM Feb 01 2020 01:01 PM
0.13.4 Jan 30 2020 10:44 PM Jan 30 2020 10:44 PM
0.13.3 Jan 27 2020 09:56 PM Jan 27 2020 09:56 PM
0.13.2 Jan 25 2020 09:47 PM Jan 25 2020 09:47 PM
0.13.1 Jan 14 2020 11:31 PM Jan 14 2020 11:31 PM
0.13.0 Jan 13 2020 12:25 PM Jan 13 2020 12:25 PM
0.12.15 Dec 20 2019 12:58 PM Dec 20 2019 12:58 PM
0.12.14 Dec 18 2019 12:21 PM Dec 18 2019 12:21 PM
0.12.13 Nov 08 2019 02:04 PM Nov 08 2019 02:04 PM
0.12.12 Oct 21 2019 03:52 PM Oct 21 2019 03:52 PM
0.12.11 Oct 11 2019 02:16 PM Oct 11 2019 02:16 PM
0.12.10 Oct 04 2019 10:55 AM Oct 04 2019 10:55 AM
0.12.9 Oct 03 2019 08:14 PM Oct 03 2019 08:14 PM
0.12.8 Oct 03 2019 08:00 PM Oct 03 2019 08:00 PM
0.12.7 Sep 27 2019 02:31 PM Sep 27 2019 02:31 PM
0.12.6 Sep 11 2019 12:00 PM Sep 11 2019 12:00 PM
0.12.5 Sep 11 2019 11:47 AM Sep 11 2019 11:47 AM
0.12.4 Sep 11 2019 11:36 AM Sep 11 2019 11:36 AM
0.12.3 Sep 10 2019 12:14 PM Sep 10 2019 12:14 PM
0.12.2 Sep 05 2019 04:17 PM Sep 05 2019 04:17 PM
0.12.1 Sep 03 2019 11:11 PM Sep 03 2019 11:11 PM
0.12.0 Aug 29 2019 11:16 AM Aug 29 2019 11:16 AM
0.11.3 Aug 22 2019 11:51 AM Aug 22 2019 11:51 AM
0.11.2 Aug 21 2019 10:30 AM Aug 21 2019 10:30 AM
0.11.0 Aug 20 2019 01:48 PM Aug 20 2019 01:48 PM
0.10.2 Aug 01 2019 02:32 PM Aug 01 2019 02:32 PM
0.10.1 Jul 26 2019 10:52 AM Jul 26 2019 10:52 AM
0.10.0 Jul 18 2019 03:14 PM Jul 18 2019 03:14 PM
0.9.0 Jun 23 2019 04:04 PM Jun 23 2019 04:04 PM
0.8.0 May 31 2019 01:56 PM May 31 2019 01:56 PM
0.7.0 May 06 2019 05:52 PM May 06 2019 05:52 PM
0.6.0 Apr 25 2019 10:52 AM Apr 25 2019 10:52 AM
0.5.0 Feb 21 2019 07:22 PM Feb 21 2019 07:22 PM
0.4.0 Feb 17 2019 02:34 PM Feb 17 2019 02:34 PM
0.3.1 Feb 07 2019 10:43 PM Feb 07 2019 10:43 PM

 

$ box install commandbox-cfformat

No collaborators yet.
     
  • Feb 07 2019 10:43 PM
  • Feb 14 2020 03:43 PM
  • 1,474
  • 0
  • 3,653