{"id":2803,"date":"2025-02-24T12:16:04","date_gmt":"2025-02-24T17:16:04","guid":{"rendered":"https:\/\/csimmons.dev\/blog\/?p=2803"},"modified":"2025-08-07T23:36:28","modified_gmt":"2025-08-08T03:36:28","slug":"cleaner-code-with-cfml-formatter-vscode-extension-cfformat-commandbox-module","status":"publish","type":"post","link":"https:\/\/csimmons.dev\/blog\/2025\/02\/cleaner-code-with-cfml-formatter-vscode-extension-cfformat-commandbox-module\/","title":{"rendered":"Cleaner code with CFML Formatter (VSCode extension) + cfformat (CommandBox module)"},"content":{"rendered":"<p>I don&#8217;t work on a lot of non-CFML development but I had a couple of PHP projects and a JavaScript project I was working on last month. In an effort to tidy up my code in those projects I started using <a href=\"https:\/\/prettier.io\/\" target=\"_blank\" rel=\"noopener\">Prettier<\/a>. I even wrote <a href=\"https:\/\/csimmons.dev\/blog\/2025\/02\/prettier-with-a-sample-prettierrc-and-explanation-of-options\/\">a post on Prettier<\/a> and how I would be including it in future projects. Well, this weekend I was working on a CFML project and came across Mark Drew&#8217;s incredible <strong>CFML formatter<\/strong> extension for Visual Studio Code. Per the documentation:<\/p>\n<blockquote><p>CFML formatter is a Visual Studio Code extension that provides formatting for CFML files using Lucee Server and CFFormat<\/p><\/blockquote>\n<p><a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=markdrew.cfml-formatter\" target=\"_blank\" rel=\"noopener\">CFML formatter<\/a> and <a href=\"https:\/\/www.forgebox.io\/view\/commandbox-cfformat\" target=\"_blank\" rel=\"noopener\">cfformat<\/a> are two great tools you can use to:<\/p>\n<ol>\n<li>Set and implement coding standards for yourself and\/or your team.<\/li>\n<li>Format code in real time as you work in Visual Studio Code.<\/li>\n<li>Scan, review, and even format code issues manually or in an automated manner by watching directories.<\/li>\n<\/ol>\n<h2>Installation<\/h2>\n<h3>CFML formatter<\/h3>\n<p>Install the <strong>CFML formatter<\/strong> VSCode extension from the Extensions view in Visual Studio Code.<\/p>\n<h3>cfformat<\/h3>\n<p>Install the <strong>cfformat<\/strong> CommandBox module by launching CommandBox and running the following command.<\/p>\n<p><code>box install commandbox-cfformat<\/code><\/p>\n<h2>A few things you can do with CFML formatter<\/h2>\n<h3>Format code on save<\/h3>\n<p>This will format your code using <strong>CFML formatter<\/strong> every time you save a file in Visual Studio Code (you can define the rules using a <strong>.cfformat.json<\/strong> file which you can also share with your team!).<\/p>\n<p>To configure <strong>Format code on save<\/strong>:<\/p>\n<ul>\n<li>Open Settings by pressing <code>Cmd+,<\/code> for Mac (or <code>CTRL+,<\/code> for Windows\/Linux).<\/li>\n<li>Type <strong>format<\/strong> in the search box and enable the option <strong>Format On Save<\/strong>.<\/li>\n<\/ul>\n<figure id=\"attachment_2809\" aria-describedby=\"caption-attachment-2809\" style=\"width: 738px\" class=\"wp-caption alignnone\"><img width=\"748\" height=\"242\" data-public-id=\"format-on-save\/format-on-save.png\" loading=\"lazy\" decoding=\"async\" class=\"wp-post-2803 wp-image-2809 \" src=\"https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_748,h_242,c_scale\/f_auto,q_auto\/v1740416138\/format-on-save\/format-on-save.png?_i=AA\" alt=\"Format on save in VSCode\" data-format=\"png\" data-transformations=\"f_auto,q_auto\" data-version=\"1740416138\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_300,h_97,c_scale\/f_auto,q_auto\/v1740416138\/format-on-save\/format-on-save.png?_i=AA 300w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_1024,h_332,c_scale\/f_auto,q_auto\/v1740416138\/format-on-save\/format-on-save.png?_i=AA 1024w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_768,h_249,c_scale\/f_auto,q_auto\/v1740416138\/format-on-save\/format-on-save.png?_i=AA 768w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_1536,h_498,c_scale\/f_auto,q_auto\/v1740416138\/format-on-save\/format-on-save.png?_i=AA 1536w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_2048,h_664,c_scale\/f_auto,q_auto\/v1740416138\/format-on-save\/format-on-save.png?_i=AA 2048w\" sizes=\"auto, (max-width: 748px) 100vw, 748px\" \/><figcaption id=\"caption-attachment-2809\" class=\"wp-caption-text\">Format on save in VSCode<\/figcaption><\/figure>\n<h3>Format code using right click<\/h3>\n<p>This will format your code using <strong>CFML formatter<\/strong> when you right click in the Visual Studio Code editor and choose <strong>Format Document<\/strong><\/p>\n<h3>More info on CFML formatter<\/h3>\n<p>You should also check out <strong>CFRules<\/strong>.<\/p>\n<p>Read the full <strong>CFML formatter<\/strong> documentation at <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=markdrew.cfml-formatter\">Visual Studio Marketplace<\/a>.<\/p>\n<h2>A few things you can do with cfformat<\/h2>\n<h3>Run a wizard<\/h3>\n<p><code>cfformat settings wizard<\/code><\/p>\n<p>The wizard will:<\/p>\n<ol>\n<li>Walk you through all settings.<\/li>\n<li>Display the options AND what those options will do to an example of code.<\/li>\n<li>Indicate the default setting.<\/li>\n<li>Generate a <strong>.cfformat.json<\/strong> file for you based on your choices.<\/li>\n<\/ol>\n<p>This wizard option is incredible!<\/p>\n<h3>View existing settings<\/h3>\n<p><code>cfformat settings show<\/code><\/p>\n<figure id=\"attachment_2806\" aria-describedby=\"caption-attachment-2806\" style=\"width: 740px\" class=\"wp-caption alignnone\"><img width=\"750\" height=\"615\" data-public-id=\"cfformat-settings-show\/cfformat-settings-show.png\" loading=\"lazy\" decoding=\"async\" class=\"wp-post-2803 wp-image-2806\" src=\"https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_750,h_615,c_scale\/f_auto,q_auto\/v1740416121\/cfformat-settings-show\/cfformat-settings-show.png?_i=AA\" alt=\"cfformat settings show command in CommandBox\" data-format=\"png\" data-transformations=\"f_auto,q_auto\" data-version=\"1740416121\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_300,h_246,c_scale\/f_auto,q_auto\/v1740416121\/cfformat-settings-show\/cfformat-settings-show.png?_i=AA 300w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_1024,h_839,c_scale\/f_auto,q_auto\/v1740416121\/cfformat-settings-show\/cfformat-settings-show.png?_i=AA 1024w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_768,h_629,c_scale\/f_auto,q_auto\/v1740416121\/cfformat-settings-show\/cfformat-settings-show.png?_i=AA 768w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/f_auto,q_auto\/v1740416121\/cfformat-settings-show\/cfformat-settings-show.png?_i=AA 1200w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><figcaption id=\"caption-attachment-2806\" class=\"wp-caption-text\">cfformat settings show command in CommandBox<\/figcaption><\/figure>\n<p>These settings can be stored in a <strong>.cfformat.json<\/strong> file in your Visual Studio Code project. They will then govern <strong>Format code on save<\/strong> and the <strong>Format Document<\/strong> on right click action.<\/p>\n<p>Read the full settings reference at: <a href=\"https:\/\/github.com\/jcberquist\/commandbox-cfformat\/blob\/master\/reference.md\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/jcberquist\/commandbox-cfformat\/blob\/master\/reference.md<\/a>.<\/p>\n<h3>Learn more about a setting<\/h3>\n<p><code>cfformat settings info tab_indent<\/code><\/p>\n<figure id=\"attachment_2805\" aria-describedby=\"caption-attachment-2805\" style=\"width: 740px\" class=\"wp-caption alignnone\"><img width=\"750\" height=\"425\" data-public-id=\"cfformat-settings-info\/cfformat-settings-info.png\" loading=\"lazy\" decoding=\"async\" class=\"wp-post-2803 wp-image-2805\" src=\"https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_750,h_425,c_scale\/f_auto,q_auto\/v1740416111\/cfformat-settings-info\/cfformat-settings-info.png?_i=AA\" alt=\"cfformat settings show info command in CommandBox\" data-crop=\"1.76\" data-format=\"png\" data-transformations=\"f_auto,q_auto\" data-version=\"1740416111\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_300,h_170,c_scale\/f_auto,q_auto\/v1740416111\/cfformat-settings-info\/cfformat-settings-info.png?_i=AA 300w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_1024,h_579,c_scale\/f_auto,q_auto\/v1740416111\/cfformat-settings-info\/cfformat-settings-info.png?_i=AA 1024w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_768,h_435,c_scale\/f_auto,q_auto\/v1740416111\/cfformat-settings-info\/cfformat-settings-info.png?_i=AA 768w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/f_auto,q_auto\/v1740416111\/cfformat-settings-info\/cfformat-settings-info.png?_i=AA 1200w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><figcaption id=\"caption-attachment-2805\" class=\"wp-caption-text\">cfformat settings show info command in CommandBox<\/figcaption><\/figure>\n<h3>Checking Tag structure<\/h3>\n<p>This option looks for:<\/p>\n<blockquote><p>tags that are unbalanced or incorrectly structured<\/p><\/blockquote>\n<p>Check a file:<\/p>\n<p><code>cfformat tag-check about.cfm<\/code><\/p>\n<figure id=\"attachment_2808\" aria-describedby=\"caption-attachment-2808\" style=\"width: 740px\" class=\"wp-caption alignnone\"><img width=\"750\" height=\"60\" loading=\"lazy\" decoding=\"async\" class=\"wp-post-2803 wp-image-2808\" src=\"data:image\/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI3NTAiIGhlaWdodD0iNjAiPjxyZWN0IHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiPjxhbmltYXRlIGF0dHJpYnV0ZU5hbWU9ImZpbGwiIHZhbHVlcz0icmdiYSgxNTMsMTUzLDE1MywwLjUpO3JnYmEoMTUzLDE1MywxNTMsMC4xKTtyZ2JhKDE1MywxNTMsMTUzLDAuNSkiIGR1cj0iMnMiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiAvPjwvcmVjdD48L3N2Zz4=\" alt=\"cfformat tag-check file command in CommandBox\" data-public-id=\"cfformat-tag-check-file\/cfformat-tag-check-file.png\" data-crop=\"12.5\" data-format=\"png\" data-transformations=\"f_auto,q_auto\" data-version=\"1740416146\" data-seo=\"1\" data-size=\"750 60\" data-srcset=\"https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_300,h_24,c_scale\/f_auto,q_auto\/v1740416146\/cfformat-tag-check-file\/cfformat-tag-check-file.png?_i=AA 300w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_1024,h_80,c_scale\/f_auto,q_auto\/v1740416146\/cfformat-tag-check-file\/cfformat-tag-check-file.png?_i=AA 1024w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_768,h_60,c_scale\/f_auto,q_auto\/v1740416146\/cfformat-tag-check-file\/cfformat-tag-check-file.png?_i=AA 768w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/f_auto,q_auto\/v1740416146\/cfformat-tag-check-file\/cfformat-tag-check-file.png?_i=AA 1200w\" data-sizes=\"auto, (max-width: 750px) 100vw, 750px\" data-delivery=\"upload\" onload=\";window.CLDBind?CLDBind(this):null;\" data-cloudinary=\"lazy\" \/><figcaption id=\"caption-attachment-2808\" class=\"wp-caption-text\">cfformat tag-check file command in CommandBox<\/figcaption><\/figure>\n<p>Check a directory:<\/p>\n<p><code>cfformat tag-check<\/code><\/p>\n<figure id=\"attachment_2807\" aria-describedby=\"caption-attachment-2807\" style=\"width: 740px\" class=\"wp-caption alignnone\"><img width=\"750\" height=\"495\" loading=\"lazy\" decoding=\"async\" class=\"wp-post-2803 wp-image-2807\" src=\"data:image\/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI3NTAiIGhlaWdodD0iNDk1Ij48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIj48YW5pbWF0ZSBhdHRyaWJ1dGVOYW1lPSJmaWxsIiB2YWx1ZXM9InJnYmEoMTUzLDE1MywxNTMsMC41KTtyZ2JhKDE1MywxNTMsMTUzLDAuMSk7cmdiYSgxNTMsMTUzLDE1MywwLjUpIiBkdXI9IjJzIiByZXBlYXRDb3VudD0iaW5kZWZpbml0ZSIgLz48L3JlY3Q+PC9zdmc+\" alt=\"cfformat tag-check command in CommandBox\" data-public-id=\"cfformat-tag-check-dir\/cfformat-tag-check-dir.png\" data-format=\"png\" data-transformations=\"f_auto,q_auto\" data-version=\"1740416130\" data-seo=\"1\" data-size=\"750 495\" data-srcset=\"https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_300,h_198,c_scale\/f_auto,q_auto\/v1740416130\/cfformat-tag-check-dir\/cfformat-tag-check-dir.png?_i=AA 300w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_1024,h_674,c_scale\/f_auto,q_auto\/v1740416130\/cfformat-tag-check-dir\/cfformat-tag-check-dir.png?_i=AA 1024w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/w_768,h_506,c_scale\/f_auto,q_auto\/v1740416130\/cfformat-tag-check-dir\/cfformat-tag-check-dir.png?_i=AA 768w, https:\/\/res.cloudinary.com\/ccsimmons\/images\/f_auto,q_auto\/v1740416130\/cfformat-tag-check-dir\/cfformat-tag-check-dir.png?_i=AA 1200w\" data-sizes=\"auto, (max-width: 750px) 100vw, 750px\" data-delivery=\"upload\" onload=\";window.CLDBind?CLDBind(this):null;\" data-cloudinary=\"lazy\" \/><figcaption id=\"caption-attachment-2807\" class=\"wp-caption-text\">cfformat tag-check command in CommandBox<\/figcaption><\/figure>\n<p>Not only will <code>cfformat tag-check<\/code> locate cfml tag issues it will also locate html tag issues as shown above!<\/p>\n<h3>More info on cfformat<\/h3>\n<p>Check out some other really cool stuff like <strong>Watching Directories<\/strong> and <strong>Ignoring Code Sections<\/strong>.<\/p>\n<p>Read the full <strong>cfformat<\/strong> documentation at <a href=\"https:\/\/www.forgebox.io\/view\/commandbox-cfformat\">FORGEBOX<\/a>.<\/p>\n<h3>In Summary<\/h3>\n<p>My workflow is going to be:<\/p>\n<ol>\n<li>Generate a <strong>.cfformat.json<\/strong> file in my CFML project using the <strong>cfformat<\/strong> CommandBox module<\/li>\n<li>Let <strong>CFML formatter<\/strong> format my code on save in Visual Studio Code (governed by the <strong>.cfformat.json<\/strong> file)<\/li>\n<li>Periodically I will manually run <code>cfformat tag-check<\/code> on my project using the <strong>cfformat<\/strong> CommandBox module.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>I don&#8217;t work on a lot of non-CFML development but I had a couple of PHP projects and a JavaScript project I was working on last month. In an effort to tidy up my code in those projects I started using Prettier. I even wrote a post on Prettier and how I would be including &#8230; <a title=\"Cleaner code with CFML Formatter (VSCode extension) + cfformat (CommandBox module)\" class=\"read-more\" href=\"https:\/\/csimmons.dev\/blog\/2025\/02\/cleaner-code-with-cfml-formatter-vscode-extension-cfformat-commandbox-module\/\" aria-label=\"Read more about Cleaner code with CFML Formatter (VSCode extension) + cfformat (CommandBox module)\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_cloudinary_featured_overwrite":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[68],"tags":[48,52,12,43,74,53],"class_list":["post-2803","post","type-post","status-publish","format-standard","hentry","category-developer","tag-coldfusion","tag-commandbox","tag-developer","tag-lucee","tag-prettier","tag-vscode"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pbVg43-Jd","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/posts\/2803","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/comments?post=2803"}],"version-history":[{"count":0,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/posts\/2803\/revisions"}],"wp:attachment":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/media?parent=2803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/categories?post=2803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/tags?post=2803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}