Conversation
|
@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. |
|
Awesome! Thanks @existentialism |
packages/babel-core/src/util.js
Outdated
| export function shouldIgnore( | ||
| filename: string, | ||
| ignore: Array<RegExp | Function> = [], | ||
| only?: Array<RegExp | Function>, |
There was a problem hiding this comment.
Does prettier offer a flag for trailing function commas? I'd be for it if so.
Makefile
Outdated
| ./node_modules/.bin/eslint packages/ --format=codeframe --fix | ||
|
|
||
| prettify: | ||
| ./node_modules/.bin/prettier --trailing-comma es5 --write "packages/**/src/*.js" |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
That is rough. I feel like I'll misread this every time.
| ); | ||
| if (index >= 0) { | ||
| while (index && node.end === tokens[index - 1].end) --index; | ||
| while (index && node.end === tokens[index - 1].end) |
There was a problem hiding this comment.
Can we combine this with ESLint to force these to be wrapped in a block statement?
|
|
||
| const buildPropertyMethodAssignmentWrapper = template(` | ||
| const buildPropertyMethodAssignmentWrapper = template( | ||
| ` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
If you remove the parenthesis, it displays the same way as you wrote it:
const buildPropertyMethodAssignmentWrapper = template`
(function (FUNCTION_KEY) {
function FUNCTION_ID() {
return FUNCTION_KEY.apply(this, arguments);
}
FUNCTION_ID.toString = function () {
return FUNCTION_KEY.toString();
}
return FUNCTION_ID;
})(FUNCTION)
`;There was a problem hiding this comment.
@vjeux Would there be any interest in handling this like the array in https://prettier.github.io/prettier/#%7B%22content%22%3A%22var%20foo%20%3D%20bar(%5B%5Cn%20%20%7B%5Cn%20%20%20%20foo%3A%204%5Cn%20%20%7D%5Cn%5D)%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3A%22none%22%2C%22bracketSpacing%22%3Atrue%2C%22jsxBracketSameLine%22%3Afalse%2C%22parser%22%3A%22babylon%22%2C%22doc%22%3Afalse%7D%7D
The template literal approach is certainly an option if not.
There was a problem hiding this comment.
Do you mind discussing it in prettier/prettier#786?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Got lost when commas were changed to all. Feeling like we should include --print-width 110?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Oh because it stops wrapping other things we've manually wrapped?
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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?
92094e0 to
e847e4a
Compare
|
Updated with 0.22.0 |
|
Do you want to add to the |
ef8c53b to
c9b003f
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
package.json
Outdated
| }, | ||
| "lint-staged": { | ||
| "packages/*/src/**/*.js": [ | ||
| "prettier --trailing-comma all --write", |
There was a problem hiding this comment.
You can use https://github.com/not-an-aardvark/eslint-plugin-prettier instead here
48ef953 to
3d11fd2
Compare
8b59602 to
74bb8d0
Compare
90e2a1e to
5bf7b29
Compare
5bf7b29 to
0c8a2ec
Compare
|
|
0f6110d to
5d91827
Compare
5d91827 to
549ec70
Compare
| }|null { | ||
| export default function manageOptions( | ||
| opts: {}, | ||
| ): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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), | ||
| ); |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
Like that return above, interesting. Not sure why you'd want parens around this.
|
I'm ok with just landing this and if there are updates, that's cool. |
8245582 to
2fcf33d
Compare
The great hunt for oddities begins!
Same tasks as babel/babylon#390: