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

Yeoman generator is not using indent_size from .editorconfig #285

Closed
addyosmani opened this issue Jun 12, 2013 · 18 comments
Closed

Yeoman generator is not using indent_size from .editorconfig #285

addyosmani opened this issue Jun 12, 2013 · 18 comments

Comments

@addyosmani
Copy link
Member

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

from yeoman/yeoman#1082

@SBoudrias
Copy link
Member

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
Copy link
Contributor

@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 #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
Copy link
Member Author

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
Copy link
Member

passy commented Jul 5, 2013

@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
Copy link
Member

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
Copy link

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
Copy link
Member

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
Copy link

@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
Copy link
Member

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
Copy link

jednano commented Jan 9, 2014

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
Copy link

jednano commented Jan 9, 2014

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
Copy link

ghost commented Jul 14, 2014

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
Copy link
Member

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

@rainboxx
Copy link

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

@SBoudrias
Copy link
Member

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

@AndreLion
Copy link

Let's make things clear:

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

@SBoudrias
Copy link
Member

@AndreLion check #699

@github-actions
Copy link
Contributor

github-actions bot commented Jan 2, 2020

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

@github-actions github-actions bot added the stale label Jan 2, 2020
@github-actions github-actions bot closed this as completed Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants