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

Introduce beautify-lint and reformat files automatically #102

Closed
wants to merge 18 commits into from

Conversation

okonet
Copy link
Contributor

@okonet okonet commented Apr 6, 2017

What kind of change does this PR introduce?
refactoring + build related change

Did you add tests for your changes?
N/A

If relevant, did you update the documentation?
N/A

Summary

To ensure code style is consistent with the main webpack repo, I've added the pretest command that will lint it on CI. Also I've added an additional step to lint-staged that will automatically reformat code according to code style rules in a pre-commit hook.

Does this PR introduce a breaking change?
No

@okonet okonet self-assigned this Apr 6, 2017
@evenstensberg
Copy link
Member

Mind fixing conflicts first?

@okonet
Copy link
Contributor Author

okonet commented Apr 6, 2017

@ev1stensberg lol you're too fast :)

@okonet
Copy link
Contributor Author

okonet commented Apr 6, 2017

Unfortunately, I've encountered some inconsistencies between beautify-rewrite and eslint config. Even after I've updated eslint config to the webpack's one to reduce code style inconsistencies I still see some cases where beautify-rewrite formats code differently as eslint --fix does.

Try running npm run lint:style to see those inconsistencies.

cc @sokra

@evenstensberg
Copy link
Member

What is needed to fix the issue @okonet ?

@okonet
Copy link
Contributor Author

okonet commented Apr 7, 2017

@ev1stensberg I guess the issue is with how beautify formats the code in some cases since I'm using same ESLint and jsbeautify configs as in webpack's repo.

@evenstensberg
Copy link
Member

If the eslint and beautify code is the same, shouldn't it be no problem at all? @okonet

@evenstensberg
Copy link
Member

Status on this?

@pksjce
Copy link

pksjce commented Jun 20, 2017

This would really help us to rebase with the main webpack repo's cli. @okonet - Can I help you with this?

@okonet
Copy link
Contributor Author

okonet commented Jun 21, 2017

I'm not sure how I can help. I'd propose we switch both repos to prettier since it shouldn't have those issues AFAIK.

@okonet
Copy link
Contributor Author

okonet commented Jun 21, 2017

webpack/webpack#4757

@DanielaValero
Copy link
Contributor

Hi @okonet @pksjce so, we proceed on this by basing our settings on webpack's one? If so, I'd take over the PR to make the required updates

@DanielaValero
Copy link
Contributor

Hello @okonet @pksjce

I have updated this PR with the next:

  • Updated the outdated dependencies
  • Replaced js-beaufity with prettier
  • Reformat the files with the lintin settings

Would you check if the changes are ok at your end?

package.json Outdated
@@ -68,6 +68,7 @@
"eslint-plugin-node": "^5.1.0",
"eslint-plugin-prettier": "^2.1.2",
"jest": "^20.0.4",
"jest-cli": "^20.0.4",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed if you already have jest as a dependency.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I added it because I ran the tests with npm test and node complained that jest-cli is not in the project

"node/process-exit-as-throw": "error",
"prettier/prettier": ["error", {
"useTabs": true,
"bracketSpacing": false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for not including it? I believe it's much more readable with spaces.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me double check, I was getting crazy errors of compatibility between eslint and prettify, did some tests, this might have squeezed in.

@okonet
Copy link
Contributor Author

okonet commented Jul 4, 2017

Looking at all conflicts I think it would be easier to start over...

@evenstensberg
Copy link
Member

+1 @okonet

@DanielaValero
Copy link
Contributor

DanielaValero commented Jul 4, 2017

Totally! Will create a new branch and cherry-pick the changes. Afterwards will add a single commit with the style fixes. Will close this PR and open a new one

@DanielaValero
Copy link
Contributor

Hi @okonet @pksjce,

I've been playing around and trying to get the automated code beatutifying work with prettier but has been quite complicated.

Issues I've got:

  • Cyclical issues with eslint: Sometimes eslint complains about something, I fix it and prettier complains
  • The error messages that prettier outputs are not really clear, therefore, I've invested much time on figuring out what the issue is. As the nature of this project is more like: work-on-our-free-time, I'd rather invest that time on fixing bugs than figuring out what the lintin issue is
  • The integration with eslint seems quite blurry at the moment, running eslint --fix together with prettier, in some cases has even introduced in the code syntax errors.

At the moment, my conclusion is:

  • Prettier is good for what we are using it, to be run in the code the cli creates
  • Replacing js-beautify by prettier is something we could try again in the future, once the integration with eslint is stronger, and prettier has more development time.

What you guys think?

@okonet
Copy link
Contributor Author

okonet commented Jul 19, 2017

@DanielaValero I'm running prettier with eslint on all my code and never run into issue. I assume you're running into conflicting rules that needs to be disabled. See https://github.com/okonet/eslint-config-okonet/blob/master/index.js for my setup. The important thing is https://github.com/prettier/eslint-config-prettier that disables all styling rules of ESLint.

@DanielaValero
Copy link
Contributor

HI @okonet thanks for the pointer, will try it out. Because #173 touches many files, I could try it out in a separate branch after that one is merged, otherwise will be nightmare to fix merge conflicts once more prs get merged

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

Successfully merging this pull request may close these issues.

None yet

4 participants