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

Evaluate code auto-formatting #17288

Closed
enomado opened this issue Aug 20, 2019 · 6 comments
Closed

Evaluate code auto-formatting #17288

enomado opened this issue Aug 20, 2019 · 6 comments

Comments

@enomado
Copy link
Contributor

enomado commented Aug 20, 2019

  • Fast typing
  • Much simpler diffs
  • It gives some freedom on line breaks so matrix, for example, shouldn't be formatted inline. But there is ingoring also exists
@Mugen87
Copy link
Collaborator

Mugen87 commented Aug 20, 2019

I'm not sure I understand your issue. What do you expect here from the three.js project?

@donmccurdy
Copy link
Collaborator

The project already has an eslint config, so eslint --fix should already work. But I don't know that we would want to require it for every PR, or apply it to the existing codebase wholesale. It's just there for those who find automation makes it easier to follow the styleguide.

@enomado
Copy link
Contributor Author

enomado commented Aug 20, 2019

I notice #11552 and #15545 and search issue where I can read discussion about using some auto-formatting tools like prettier to do format-on-save in editor.

Looks like I find Mr.doob's Code Style™. Is there any config for this style?

@donmccurdy, does this tool actually fix/add/remove trailing commas, spaces? Like here https://prettier.io/playground/

@gkjohnson
Copy link
Collaborator

Is there any config for this style?

The ESLint config for this project is defined in the package.json:

https://github.com/mrdoob/three.js/blob/dev/package.json#L27-L44

does this tool actually fix/add/remove trailing commas, spaces?

Running eslint --fix can auto-fix all those issues. There are also code editor plugins that afford inline linter error highlighting and probably allow for auto-format on save, too (though I don't use that myself).

@donmccurdy
Copy link
Collaborator

For example:

// Before
function doTheThing(arg){
	var foo = '2389' + arg;
	console.log(foo);
}
doTheThing('_yeah');

// After `eslint --fix sample.js`
function doTheThing( arg ) {

	var foo = '2389' + arg;
	console.log( foo );

}
doTheThing( '_yeah' );

As @gkjohnson mentions, you can set up your editor to do this automatically, but threejs doesn't require any particular editor.

@enomado
Copy link
Contributor Author

enomado commented Aug 20, 2019

Even didn't know about this eslint feature.
Current VS Code config looks like:

"editor.formatOnSave": false
"eslint.autoFixOnSave": true

Thanks.

@mrdoob mrdoob closed this as completed Aug 21, 2019
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

5 participants