Skip to content

Use prettier#5412

Merged
hzoo merged 2 commits into7.0from
prettify
Jun 27, 2017
Merged

Use prettier#5412
hzoo merged 2 commits into7.0from
prettify

Conversation

@existentialism
Copy link
Copy Markdown
Member

@existentialism existentialism commented Mar 3, 2017

The great hunt for oddities begins!

Same tasks as babel/babylon#390:

  • add to pre-commit hook + travis
  • adjust eslint

@existentialism existentialism added PR: Internal 🏠 A type of pull request used for our changelog categories WIP labels Mar 3, 2017
@mention-bot
Copy link
Copy Markdown

@existentialism, thanks for your PR! By analyzing the history of the files in this pull request, we identified @hzoo, @loganfsmyth and @Alxpy to be potential reviewers.

@xtuc
Copy link
Copy Markdown
Member

xtuc commented Mar 3, 2017

Awesome! Thanks @existentialism

export function shouldIgnore(
filename: string,
ignore: Array<RegExp | Function> = [],
only?: Array<RegExp | Function>,
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.

Does prettier offer a flag for trailing function commas? I'd be for it if so.

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.

Yep, I'll enable

Makefile Outdated
./node_modules/.bin/eslint packages/ --format=codeframe --fix

prettify:
./node_modules/.bin/prettier --trailing-comma es5 --write "packages/**/src/*.js"
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.

Do we need --print-width 110?

_findToken(test: Function, start: number, end: number): number {
if (start >= end) return -1;
const middle = (start + end) >>> 1;
const middle = start + end >>> 1;
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.

That is rough. I feel like I'll misread this every time.

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.

);
if (index >= 0) {
while (index && node.end === tokens[index - 1].end) --index;
while (index && node.end === tokens[index - 1].end)
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.

Can we combine this with ESLint to force these to be wrapped in a block statement?


const buildPropertyMethodAssignmentWrapper = template(`
const buildPropertyMethodAssignmentWrapper = template(
`
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.

Looks like we have a bunch of these too. It's an interesting case since it follows the rules for normal normal expressions, but seems weird when you see it. @vjeux any thoughts on this one?

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.

Ah, looks like maybe prettier/prettier#786?

Copy link
Copy Markdown

@vjeux vjeux Mar 3, 2017

Choose a reason for hiding this comment

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

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.

Do you mind discussing it in prettier/prettier#786?

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.

No problem.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry I haven't pushed this yet. I'm going to revive that PR

Makefile Outdated
./node_modules/.bin/eslint packages/ --format=codeframe --fix

prettify:
./node_modules/.bin/prettier --trailing-comma all --write "packages/**/src/*.js"
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.

Got lost when commas were changed to all. Feeling like we should include --print-width 110?

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.

Yeah, I can run it again with wider to see the results, some of the lines get really crowded the further you move out from 80.

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.

Oh because it stops wrapping other things we've manually wrapped?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@loganfsmyth the way prettier works is that it tries to fit as many things as possible within a single line. Usually, this is what you want for 80 columns. The main reason people extend it further is that sometimes you want to go beyond 80 columns, but prettier is going to do it all the time and makes things less readable in practice.

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.

Yeah that is totally fair, I didn't fully think that through initially. I'm fine with trying out 80 for now, we can always increase it later.

One thing we'll have to consider is that we have a bunch of code snippets inside template literals that are currently formatted for 110 and those won't be reformatted, so those will stick out. If we reduce ESLint to 80 we'll have to go mark all of those. I guess we could just leave the max at 110 for now and rely on prettier for everything else?

@existentialism
Copy link
Copy Markdown
Member Author

Updated with 0.22.0

@loganfsmyth
Copy link
Copy Markdown
Member

Do you want to add

arrow-parens: ["error", "as-needed"],
curly: ["error", "multi-line"],
indent: "off",

to the .eslintrc directly? I think those would be enough to fix the ESLint errors.

@existentialism existentialism force-pushed the prettify branch 4 times, most recently from ef8c53b to c9b003f Compare March 9, 2017 20:20
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 9, 2017

Codecov Report

Merging #5412 into 7.0 will increase coverage by 0.15%.
The diff coverage is 87.27%.

Impacted file tree graph

@@            Coverage Diff             @@
##              7.0    #5412      +/-   ##
==========================================
+ Coverage   85.25%   85.41%   +0.15%     
==========================================
  Files         284      284              
  Lines        9963    10366     +403     
  Branches     2781     3015     +234     
==========================================
+ Hits         8494     8854     +360     
- Misses        969     1015      +46     
+ Partials      500      497       -3
Impacted Files Coverage Δ
...bel-polyfill/src/core-js/modules/es6.array.find.js 0% <ø> (ø) ⬆️
...-polyfill/src/core-js/modules/es6.number.is-nan.js 0% <ø> (ø) ⬆️
...polyfill/src/core-js/modules/es6.number.epsilon.js 0% <ø> (ø) ⬆️
...yfill/src/core-js/modules/es6.typed.int32-array.js 0% <ø> (ø) ⬆️
...yfill/src/core-js/modules/es6.typed.int16-array.js 0% <ø> (ø) ⬆️
...polyfill/src/core-js/modules/es7.object.entries.js 0% <ø> (ø) ⬆️
...yfill/src/core-js/modules/es6.array.copy-within.js 0% <ø> (ø) ⬆️
...ll/src/core-js/modules/es6.string.code-point-at.js 0% <ø> (ø) ⬆️
...polyfill/src/core-js/modules/es7.string.pad-end.js 0% <ø> (ø) ⬆️
...yfill/src/core-js/modules/es6.number.is-integer.js 0% <ø> (ø) ⬆️
... and 343 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5387d9f...2fcf33d. Read the comment docs.

package.json Outdated
},
"lint-staged": {
"packages/*/src/**/*.js": [
"prettier --trailing-comma all --write",
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@existentialism existentialism force-pushed the prettify branch 2 times, most recently from 8b59602 to 74bb8d0 Compare March 28, 2017 01:41
@existentialism existentialism force-pushed the prettify branch 2 times, most recently from 90e2a1e to 5bf7b29 Compare April 4, 2017 21:52
@existentialism
Copy link
Copy Markdown
Member Author

existentialism commented Apr 13, 2017

Updated with 1.0.2
Updated with 1.2.0
Updated with 1.2.2
Updated with 1.3.0
Updated with 1.4.4
Updated with 1.5.0

}|null {
export default function manageOptions(
opts: {},
):
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.

This is an interesting case. I guess it makes sense, but it makes the readability here worse to me at least, but I also don't think there's an obvious alternative.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could define the type in a variable just above and have a reference here, so you don't need to have this weird inline.

);
const presets = result.presets.map(descriptor =>
loadPresetDescriptor(descriptor),
);
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.

I admit, the 80-char limit still feels too small to me :(


const plugins = (config.options.plugins || []).map((plugin, index) => {
const { filepath, value, options } = normalizePair(plugin, loadPlugin, config.dirname);
const { filepath, value, options } = normalizePair(
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.

This is an interesting one where I feel like I'd probably have flattened the const binding names, rather than the function args, so the call itself was still all together. e.g.

const {
  filepath,
  value,
  options,
} = normalizePair(plugin, loadPlugin, config.dirname);

enumerable: true,
get() {
return this.map = map.get();
return (this.map = map.get());
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.

Here's a weird one...

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We add parenthesis around all the assignment in order to call attention to the fact that this expression is mutating a variable.

get() {
if (!this._cachedMap) {
const map = this._cachedMap = new sourceMap.SourceMapGenerator({
const map = (this._cachedMap = new sourceMap.SourceMapGenerator({
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.

Like that return above, interesting. Not sure why you'd want parens around this.

@hzoo
Copy link
Copy Markdown
Member

hzoo commented Jun 16, 2017

I'm ok with just landing this and if there are updates, that's cool.

@existentialism existentialism force-pushed the prettify branch 2 times, most recently from 8245582 to 2fcf33d Compare June 17, 2017 18:55
@hzoo hzoo merged commit 4e50b2d into 7.0 Jun 27, 2017
@existentialism existentialism deleted the prettify branch June 27, 2017 21:14
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 6, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Internal 🏠 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants