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

cfformat

v0.12.6 Public

commandbox-cfformat

This module registers a cfformat command in CommandBox that can be used to format CFML components. It 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 ./models/MyComponent.cfc
cfformat ./models/

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 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.

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

cfformat ./models/ --check

cfformat can also be called with a directory path and the --watch flag. When this is done, cfformat will use 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

To see the settings used for formatting, use the --settings flag. When that is present the cfformat command will just dump the settings it will use to format to the console, and not perform any formatting:

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

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 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 settingInfo argument. settingInfo can be passed either a full setting name, or just a prefix:

cfformat settingInfo=array.padding
cfformat settingInfo=array

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.12.6 Sep 11 2019 12:00 PM Sep 11 2019 12:00 PM
Version History
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

 

No collaborators yet.
     
  • Feb 07 2019 10:43 PM
  • Sep 11 2019 12:00 PM
  • 880
  • 0
  • 274