Skip to content

Formatting/prettier#6081

Merged
sokra merged 4 commits intomasterfrom
formating/prettier
Feb 25, 2018
Merged

Formatting/prettier#6081
sokra merged 4 commits intomasterfrom
formating/prettier

Conversation

@TheLarkInn
Copy link
Copy Markdown
Member

What kind of change does this PR introduce?
Refactor

Did you add tests for your changes?
N/A

If relevant, link to documentation update:
N/A

Summary
Replace beautify with prettier

Does this PR introduce a breaking change?
Shouldn't

Other information
Should be vigilant with tests, inline eslint disable line can break but I think I got them all.

@quantizor
Copy link
Copy Markdown
Contributor

66202913

Comment thread bin/config-optimist.js Outdated
.boolean("cache").describe("cache", "Enable in memory caching").default("cache", true)
.boolean("watch").alias("watch", "w").describe("watch", "Watch the filesystem for changes")
.boolean("watch-stdin").alias("watch-stdin", "stdin").describe("Exit the process when stdin is closed")
.boolean("help")
Copy link
Copy Markdown

@kwelch kwelch Dec 6, 2017

Choose a reason for hiding this comment

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

Honestly, I prefer the old in this scenario. Mainly how the grouping helped readability.

@SpaceK33z SpaceK33z changed the title Formating/prettier Formatting/prettier Dec 6, 2017
@TheLarkInn
Copy link
Copy Markdown
Member Author

//TODO: Update all hashes in stats as it looks like formatted code causes slight different hashes for builds (expected results)

@webpack-bot
Copy link
Copy Markdown
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

@TheLarkInn
Copy link
Copy Markdown
Member Author

Getting there. Will look at this later.

const footer =
self.sourceMapComment.replace(
/\[url\]/g,
`data:application/json;charset=utf-8;base64,${new Buffer.alloc((JSON.stringify(sourceMap), "utf8").toString("base64")}`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was this caused by prettier?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes

@sokra
Copy link
Copy Markdown
Member

sokra commented Dec 7, 2017

Could you remove chore(prettier): migrate to prettier from this branch?

It's doesn't make sense to update the files yet. We can only do that once all other PRs are merged and next is merged in to master. Elsewise it would result in broken PRs/many conflicts.

@TheLarkInn
Copy link
Copy Markdown
Member Author

Yup that's fine. I'll stash away and keep updating branch as we go.

@TheLarkInn
Copy link
Copy Markdown
Member Author

Done 👍

Comment thread .editorconfig
indent_style = space
indent_size = 2

[.prettierrc]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

since they are all the same it could be:

[{*.json,*.yml,.prettierrc}]
indent_style = space
indent_size = 2

Copy link
Copy Markdown
Contributor

@ooflorent ooflorent Dec 14, 2017

Choose a reason for hiding this comment

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

Using .prettierrc.js or .prettierrc.json would be better. Nowadays, many projects supports/requires an extension (prettier, eslint, babel, …)

Comment thread .eslintrc.js Outdated
"parserOptions": { "ecmaVersion": 2017 },
"rules": {
"quotes": ["error", "double"],
"prettier/prettier": "warn",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

More rules can go away because, Prettier is taking care of them


no-extra-semi
semi
brace-style
eol-last
no-empty
no-multiple-empty-lines
no-multi-spaces
no-trailing-spaces
key-spacing
object-curly-spacing
indent

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

and that...

Comment thread package.json
"mocha": "^3.2.0",
"mocha-lcov-reporter": "^1.0.0",
"nsp": "^2.6.1",
"prettier": "^1.8.2",
Copy link
Copy Markdown

@lipis lipis Dec 7, 2017

Choose a reason for hiding this comment

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

1.9.2 (updated)

Comment thread package.json
"lint": "eslint lib bin hot buildin \"test/*.js\" \"test/**/webpack.config.js\" \"test/binCases/**/test.js\" \"examples/**/webpack.config.js\"",
"lint-files": "npm run lint",
"lint": "eslint lib bin hot buildin \"test/*.test.js\" \"test/**/webpack.config.js\" \"test/binCases/**/test.js\" \"examples/**/webpack.config.js\"",
"fix": "npm run lint -- --fix",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since Prettier supports Markdown, JSON, CSS and more, we could add one more rule to fix those as well

"fix:non-js": "prettier --ignore-path .gitignore --write \"**/*.{json,css,md}\"",

and it would be a good idea to add .prettierignore file to exclude the files/paths that we don't want to touch.

@MoOx
Copy link
Copy Markdown
Contributor

MoOx commented Dec 7, 2017

I would recommend husky + lint-staged to automatically format on commit. Transparent for everyone, automatic. What else?

@alexander-akait
Copy link
Copy Markdown
Member

alexander-akait commented Dec 7, 2017

@MoOx sometimes in prettier have regression(s) in new version and it is broke code or remove some comments, it is not good practice IMHO.

@MoOx
Copy link
Copy Markdown
Contributor

MoOx commented Dec 7, 2017

From my experience I never got blocking issue. The same can happen anytimes your format by hand.
Formatting by hand pollute the git history and make blame harder to use.

You can still disable prettier in a file if you got trouble. Anyway, CI should prevent a bad (auto)commited changes.

@lipis
Copy link
Copy Markdown

lipis commented Dec 7, 2017

husky + lint-staged, formats only the files that are changed and not the whole thing so it's pretty safe, and whenever there is a new version and there are bunch of changes it should happen in a separate commit.

Here is a bare minimum for ESLint, Prettier, Husky stuff: https://github.com/lipis/prettier-setup/blob/master/package.json

Comment thread .prettierrc Outdated
@@ -0,0 +1,5 @@
{
"printWidth": 160,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why such a high print width? Any more than 100 can lead to too much code printed on one line in some cases.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I concur. This is a mistake that a lot of people do trying to use prettier for the first time. The line width is not a maximum before you warn like for eslint but how most lines are going to look like. I highly recommend 80 to 100 (maximum).

Copy link
Copy Markdown

@btnwtn btnwtn Dec 7, 2017

Choose a reason for hiding this comment

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

100 is plenty for tab based styling. 👍

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

160 was chosen to avoid too many changes in the code base due to prettier adoption. This may be decreased later.

@cloud-walker
Copy link
Copy Markdown

Just an opinion maybe: we dont use eslint-plugin-prettier at our company, we just prettify things with prettier + lint-staged + husky and lint things with eslint.

@lipis
Copy link
Copy Markdown

lipis commented Dec 7, 2017

@cloud-walker by using the plugin you can just do eslint --fix .

moduleFilenames = ModuleFilenameHelpers.replaceDuplicates(moduleFilenames, (filename, i, n) => {
for(let j = 0; j < n; j++)
filename += "*";
for (let j = 0; j < n; j++) filename += "*";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

for (let j = 0; j < n; filename += "*", j++);

:trollface:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Couldn't you just return filename + "*".repeat(n); ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

repeat didn't exist when this code was written... ;)

@sokra
Copy link
Copy Markdown
Member

sokra commented Dec 8, 2017

I would recommend husky + lint-staged to automatically format on commit. Transparent for everyone, automatic. What else?

It doesn't work great for partial staged files/commits. I do that a lot... If you can improve lint-staged in a way that it really modify the staged files and not the working copy that would be great.

@lipis
Copy link
Copy Markdown

lipis commented Dec 16, 2017

Will that make it to v4.0?

@sokra sokra changed the base branch from next to master February 13, 2018 12:00
@sokra sokra removed the PR: next label Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.