Git Product home page Git Product logo

commandbox-cfformat's Introduction

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/

If the --verbose flag is specified when running a check, the diff between source files and the formatted versions of those files that fail the check will be printed to the console.

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
}

Checking Tag structure

The cfformat tag-check command is a utilty command that will check a file or directory of files for tags that are unbalanced or incorrectly structured. When it finds such tags, it will report on the the files and line numbers for you.

cfformat tag-check ./views/

If the --verbose flag is specified when running a check, the diff between source files and the formatted versions of those files that fail the check will be printed to the console.

Syntect

Behind the scenes, cfformat makes use of the cftokens project, which is based on the syntect library along with syntax files from Sublime Text's Packages. 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.

commandbox-cfformat's People

Contributors

jcberquist avatar elpete avatar euans avatar jordanclark avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.