Git Product home page Git Product logo

Comments (18)

jcberquist avatar jcberquist commented on July 21, 2024

I am not sure I understand this request. If you are thinking of non-CFML files there are plenty of formatters already out there (such as prettier). If you are thinking of .cfm files that is a different sort of challenge than .cfc files since they potentially combine HTML, JavaScript and CSS with CFML mixed throughout.

from commandbox-cfformat.

mbandizzle avatar mbandizzle commented on July 21, 2024

It was .cfms I was thinking of. I tested an old cfc that had a mixture of coldfusion tags and html and felt like it did a good job (maybe I need to look at it more closely) and it had me wishing I could do the same to some cfms that could really benefit from consistent formatting.

from commandbox-cfformat.

bdw429s avatar bdw429s commented on July 21, 2024

@jcberquist Outputting HTML, CSS, or JS isn't unique to CFMs. How would CFFormat handle this CFC?

<cfcomponent output="true">
	<cffunction name="foo" output="true">
		<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
		<style>
			##body {
				color: red;
			}
		</style>
		<cfoutput>
			<span id="body">This is a <b>test</b></span>
		</cfoutput>
	</cffunction>
</cfcomponent>

from commandbox-cfformat.

jcberquist avatar jcberquist commented on July 21, 2024

@mbandizzle: Thank you for the clarification. I am glad you were happy with the results for .cfc files with HTML in them. I am aware that .cfc files can have HTML et al. in them :), and I did spend a little bit of time trying to ensure that cfformat could do something sane with embedded HTML. That said, I expect that the more complicated the HTML/CFML mix gets, the less true that will be. (For instance, I don't try to format CSS or JavaScript).

The reason I drew the distinction with .cfm files is that many/most tag components are not going to have any HTML in them, and of those that do many would have uncomplicated structures. Whereas I would expect most .cfm files to have a mix, and it can get very complicated 😀

cc: @bdw429s

from commandbox-cfformat.

chapmandu avatar chapmandu commented on July 21, 2024

It would be handy to have an optional flag to attempt to format .cfm files. Most "non-view" cfm files I use as includes and would benefit greatly from this fantastic plugin.

UPDATE: cfformat works nicely on .cfm files renamed with a .cfc extension. This feature would be very useful.

from commandbox-cfformat.

jcberquist avatar jcberquist commented on July 21, 2024

@chapmandu: based on what you said, I assume your .cfm files were "pure" CFML? I can probably allow this to run on .cfm files as well (though not by default), though results would definitely not be guarunteed 😄- it would be run at your own risk. I would expect it to do fine in files that only contained CFML.

from commandbox-cfformat.

chapmandu avatar chapmandu commented on July 21, 2024

I would be happy to run cfm files at my own risk, one can easily unstage if it goes terribly wrong.

I have a workaround script that renames cfm to cfc, applies cfformat then reverts names..

from commandbox-cfformat.

chapmandu avatar chapmandu commented on July 21, 2024

Just a polite bump.. I'd really like to be able to watch or format a directory containing cfm files..

You can see here how useful it would be:

https://github.com/cfwheels/cfwheels/tree/master/wheels/controller

from commandbox-cfformat.

jcberquist avatar jcberquist commented on July 21, 2024

@chapmandu I have added the ability to format cfm files in v0.14.0 - you can use the new --cfm flag to get cfformat to watch and format directories of cfm files. I recommend caution :) and it is probably not something I will spend a lot of time on trying to support. That said, I hope it helps you out.

from commandbox-cfformat.

chapmandu avatar chapmandu commented on July 21, 2024

I appreciate the update. It's safe to say I won't be formatting any view files. 👍

from commandbox-cfformat.

chapmandu avatar chapmandu commented on July 21, 2024

It appears this update has some problems. Trying to format a .cfm file throws the exception below:

box cfformat run /code/file.cfm --overwrite --cfm
ERROR (5.0.1+00137)                                                                                                                                                                                                                                                                     cannot cast [ELEMENTS] string to a number value                                                                                             

/modules/commandbox-cfformat/models/CFFormat.cfc: line 175
173:         var bom = '';
174: 
175:         if (arrayLen(tokens.elements)) {
176:             if (
177:                 isArray(tokens.elements[1]) &&
called from /modules/commandbox-cfformat/models/CFFormat.cfc: line 80
called from /modules/commandbox-cfformat/commands/cfformat/run.cfc: line 62
called from /modules/commandbox-cfformat/commands/cfformat/run.cfc: line 48
called from /system/services/CommandService.cfc: line 343
called from /system/services/CommandService.cfc: line 158
called from /system/Shell.cfc: line 768
called from /system/Bootstrap.cfm: line 119

from commandbox-cfformat.

jcberquist avatar jcberquist commented on July 21, 2024

Can you share the file you were trying to format?

from commandbox-cfformat.

jcberquist avatar jcberquist commented on July 21, 2024

Also, are you running this on Linux?

from commandbox-cfformat.

chapmandu avatar chapmandu commented on July 21, 2024

Yes, Linux Ubuntu 20.04

File contents below using command: box cfformat run /home/adam/code/helpers/json.cfm --overwrite --cfm

<cfscript>
public any function deserialiseIfJSON(required string string, any default = false) {
	if (isJSON(arguments.string)) {
		return deserializeJSON(arguments.string);
	}
	return arguments.default;
}
</cfscript>

from commandbox-cfformat.

jcberquist avatar jcberquist commented on July 21, 2024

Thanks! I will take a look. Can you format any files - or do they all break on this version?

from commandbox-cfformat.

chapmandu avatar chapmandu commented on July 21, 2024

cfcs are fine, but any cfm file seems to throw this same exception. I've tried several different cfm files.

from commandbox-cfformat.

jcberquist avatar jcberquist commented on July 21, 2024

@chapmandu it looks to me like I may have uploaded the incorrect linux binary with the v0.14.0 release. I have replaced the file. Perhaps I will need to make another release to fix this, but for now, could you try going to ~/.CommandBox/cfml/modules/commandbox-cfformat/bin/ folder when CommandBox is not running and delete the v0.14.0 folder there? When you next start CommandBox, it should download the correct binary.

from commandbox-cfformat.

chapmandu avatar chapmandu commented on July 21, 2024

That did the trick.. Thanks! Working nicely.

I also discovered that I don't need the --cfm flag if I pass a cfm file path to the command.

from commandbox-cfformat.

Related Issues (20)

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.