Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for more file extensions #11

Closed
mbandizzle opened this issue May 7, 2019 · 18 comments
Closed

Add support for more file extensions #11

mbandizzle opened this issue May 7, 2019 · 18 comments

Comments

@mbandizzle
Copy link

It would be great to be able to add additional file extensions to run through the same formatting that .cfc gets now.

@jcberquist
Copy link
Owner

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.

@mbandizzle
Copy link
Author

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.

@bdw429s
Copy link
Contributor

bdw429s commented May 8, 2019

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

@jcberquist
Copy link
Owner

@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

@chapmandu
Copy link

chapmandu commented Jun 28, 2019

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.

@jcberquist
Copy link
Owner

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

@chapmandu
Copy link

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

@chapmandu
Copy link

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

@jcberquist
Copy link
Owner

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

@chapmandu
Copy link

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

@chapmandu
Copy link

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

@jcberquist
Copy link
Owner

Can you share the file you were trying to format?

@jcberquist
Copy link
Owner

Also, are you running this on Linux?

@chapmandu
Copy link

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>

@jcberquist
Copy link
Owner

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

@chapmandu
Copy link

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

@jcberquist
Copy link
Owner

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

@chapmandu
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants