revolution icon indicating copy to clipboard operation
revolution copied to clipboard

Enable autoformat code (before commit)

Open Jako opened this issue 6 years ago • 8 comments

Feature request

Summary

The repository code should run through some code formatter like https://prettier.io/

Why is it needed?

  • No need to discuss style in code review

Suggested solution(s)

Add prettier at least to the template build process to make the files in that part formatted. The other part (format the php code) needs some integration in an IDE or in the commit process.

We should also provide the code styles in an Intellij IDEA code style XML scheme.

The code style of a PR should also be checked by Travis on GitHub and invalid styled code should be rejected.

Related issue(s)/PR(s)

Nothing special, but changing the default branch to 3.x would be a great time to introduce this change, since after reformatting our code we will have merge issues with code from other branches.

Jako avatar Jan 26 '19 13:01 Jako

Should have been done a long time ago. The only problem is all the merge conflicts it is going to cause.

OptimusCrime avatar Jan 28 '19 11:01 OptimusCrime

How can we move forward with this? I would really like to see a more standardised code base.

JoshuaLuckers avatar Feb 02 '19 11:02 JoshuaLuckers

Use https://prettier.io/ for our IDE with a common config.

Ibochkarev avatar Feb 02 '19 11:02 Ibochkarev

https://www.npmjs.com/package/grunt-prettier

There is a package milking Grunt. You can use it and write a config to format your code.

Ibochkarev avatar Feb 12 '19 10:02 Ibochkarev

I studied the information on this topic. I have found:

  • prettifer has Pre-commit Hook https://prettier.io/docs/en/precommit.html - this is exactly what we need
  • the configuration file is extensive http://json.schemastore.org/prettierrc

We need to take the first step and begin to embody this innovation.

I suggest:

  • discuss the set of rules for the .prettierrc configuration file.
  • add the given file to the root directory
  • and test

Colleagues, your move!

Ibochkarev avatar Feb 17 '19 19:02 Ibochkarev

Does Prettier provide default rules? Maybe we can use that for a start.

JoshuaLuckers avatar Feb 18 '19 16:02 JoshuaLuckers

There are libraries of this kind, for CSS, for example, https://github.com/csscomb


@Mark-H specified:

Perhaps we should discuss code styles on the forum. When there's consensus (maybe there already is), existing code should be converted and automatically enforced as part of the checks that run for each PR and commit.

That's not just about SCSS, but also JS and PHP should get that.

Ruslan-Aleev avatar Sep 23 '19 09:09 Ruslan-Aleev

Does Prettier provide default rules? Maybe we can use that for a start.

https://prettier.io/docs/en/configuration.html

Ibochkarev avatar Mar 09 '21 06:03 Ibochkarev