yeoman / generator

Rails-inspired generator system that provides scaffolding for your apps
http://yeoman.io
BSD 2-Clause "Simplified" License
1.21k stars 299 forks source link

Yeoman generator is not using indent_size from .editorconfig #285

Closed addyosmani closed 4 years ago

addyosmani commented 11 years ago

"The Yeoman generator is not using indent_size from .editorconfig and doesn't give the abbility to set it."

from https://github.com/yeoman/yeoman/issues/1082

SBoudrias commented 11 years ago

On BBB-generator, we parse the code we output in a "beautifier" to update indent to the desired length. We plan on extending this eventually to give full style guide choices.

https://github.com/backbone-boilerplate/generator-bbb/blob/master/base/bbb-generator.js#L133-L150

Maybe that's something Yeoman generator could think on adding in the default stack ? (Because really, I wouldn't use a generator who don't support my style guide)

jdespatis commented 11 years ago

@SBoudrias ++1 for your proposal

The fact is I actively use several beautifiers to clean content after the yeoman engine templates the content (it leaves a lot of linefeeds on <% if (...) %> conditions for example)

I guess the current PR https://github.com/yeoman/generator/pull/280, is a first try to implement this. Maybe the solution is just to harden this PR, and this feature would be available, what do you think of it @SBoudrias ?

addyosmani commented 11 years ago

That's a very interesting proposal @SBoudrias. So far we've been favoring editorconfig + code style comments during reviews but maybe trying out a beautifier path could save us time. Wdyt about this, @passy @sindresorhus @stephenplusplus?

passy commented 11 years ago

@SBoudrias How has your experience with js-beautifier been so far? I tried esformatter again a few days back and was kind of disappointed.

I generally like this idea a lot.

SBoudrias commented 11 years ago

On my side, js-beautifier been quite OK since 1.4 (plus it bundle an HTML and a CSS beautifier).

It supports a lot of options, but I'm not sure about the extent of the support for more complete style guide.

Although, just normalizing the whitespace is already a huge improvement on how well your generator can be used. Maybe Yeoman could implement a helper functions to normalize the output - I'd be glad to send a PR with this and linking with the .editorconfig.

zakdances commented 10 years ago

I've changed the .editorconfig files at both the module level in .nvm and in generated project folders and still my indentation preferences get ignored. What part of yeoman reads .editorconfig files? I don't see any reference to them in my generated Gruntfiles. How are the preferences implimented?

SBoudrias commented 10 years ago

Not implemented yet - and I don't think there's plan to have this as a part of the core soon.

New file utility landed though, so you could work a filter reading .editotfilters and applying style preference on file write. Feel free to develop a module to include or send us a PR!

zakdances commented 10 years ago

@SBoudrias Understood, thanks for clearing that up. In the meantime, it'd be great if there was a grunt-contrib-indent, grunt-contrib-format, or grunt-contrib-beautify that could used for this purpose. Something like grunt-prettify but works with multiple languages (JavaScript, CoffeeScript, etc.) I've already tried grunt-indent but it's not actually syntax-aware, it just indents or deindents the code as one block.

As it stands, I'm having to compile any coffeescript files to JS, then back to correctly-formatted coffeescript with grunt-js2coffee every time I use a generator. :( Is this the best solution for now, or is there some other way I'm unaware of?

SBoudrias commented 10 years ago

Well, this can be manually implemented in a generator. For example, we did it in Generator-BBB, and we have a WIP branch using the new file utility to simplify this process (and accessory generate coffee files on demand).

So, I'd recommend you to send a PR to your favorite generator implementing this. It shouldn't be to hard to copy what we did over Generator-BBB.

jednano commented 10 years ago

Language-agnostic code beautification is a lot harder than it sounds. I'm current working on a project based off of EditorConfig called ECLint. It's actually supposed to do more than just linting. You can read the project readme for more info. Expect an EditorConfig Grunt plugin (and Gulp.js) down the line, but it's going to be a while out.

As for JavaScript, CodePainter will do the trick, making good use of the Esprima parser. With AST, it has information about indent levels. Also, there's a guy just told me he's making a grunt plugin for it.

jednano commented 10 years ago

BTW, it'd be a LOT easier for such an indentation replacement tool to work if the leading indentation were in tabs and spaces afterwards for alignment. This way, single tabs could be either left alone or replaced with however many spaces you desire for indentation.

I'm still a tab lover, myself, and I have very specific reasons for it. It's the only way you can distinguish between what is indentation and what is alignment. It's also the only way people can adjust their IDE to be however they decide is most readable without actually changing the indent characters in the document.

The idea is tabs for indentation and spaces for code alignment!

ghost commented 10 years ago

Has this issued been resolved? I was directed here from http://stackoverflow.com/questions/24733247/yeoman-ember-generator-how-to-get-4-spaces-per-indent-in-generated-codes/ where I asked to change 2 spaces of generated codes to 4 spaces.

SBoudrias commented 10 years ago

Not yet, there's architecture in place to allow it. We just need someone to actually make it happen.

rainboxx commented 10 years ago

@SBoudrias Is there already a PR you proposed in #139 around or still waiting for the one to make it happen? Thanks.

SBoudrias commented 10 years ago

No PR currently, waiting for 0.18 to be release as we're working on a new file system.

AndreLion commented 9 years ago

Let's make things clear:

So far, generator can NOT customize tab/space and size for text indent before building a scaffold, right?

SBoudrias commented 9 years ago

@AndreLion check https://github.com/yeoman/generator/issues/699

github-actions[bot] commented 4 years ago

This issue is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 5 days