-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[EXPERIMENTAL] Prettier! #1629
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
[EXPERIMENTAL] Prettier! #1629
Conversation
Too magical for my taste. But yeah, nice try. |
Agreed on the magic, but grep shows at least 260 commit messages containing the word "lint". I forget sooo often. |
Nothing stops you from setting this up locally 🍻 |
Yeah, I tried once but didn't get the exit if details correct so that it mostly just didn't work. (should be real simple though, right?) So I elected to just deal with forgetting sometimes. |
require('./bar'), | ||
require('./pie') | ||
]); | ||
Plotly.register([require('./bar'), require('./pie')]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is is possible to configure prettier
to respect vertical formatting?
I see the need to split long lines, but joining short one into a single line doesn't help here.
require('./pie'), | ||
require('./contour'), | ||
require('./scatterternary') | ||
require('./bar'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to configure prettier
to use a 4-space indent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require('./histogram2dcontour'), | ||
require('./pie'), | ||
require('./contour'), | ||
require('./scatterternary'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for comma-ending last elements (neater diffs)
"bundle": "node tasks/bundle.js", | ||
"header": "node tasks/header.js", | ||
"stats": "node tasks/stats.js", | ||
"build": "npm run preprocess && npm run bundle && npm run header && npm run stats", | ||
"cibuild": "npm run preprocess && node tasks/cibundle.js", | ||
"watch": "node tasks/watch.js", | ||
"lint": "eslint --version && eslint .", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is prettier
able to detect unused variables and variables used out of scope?
If not, I think it's better to keep using eslint
for linting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Asking on the gitter channel just in case since I wasn't able to find a better answer, but I think that alone might be enough for me. Seems some people run it through both, but that seems a bit annoying (though not necessarily slow if you prettier + eslint only staged files).
|
||
var borderWidth = coerce('borderwidth'); | ||
var showArrow = coerce('showarrow'); | ||
if (!(visible || clickToShow)) return annOut; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😉 Dammit! Now that I got to train myself not to write a space after if
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The golden rule of conventions: Convention <insert convention you use here>
is aesthetically superior to <insert proposed alteration here>
. 😉
coerce('width'); | ||
coerce('align'); | ||
var borderColor = coerce('bordercolor'), | ||
borderOpacity = Color.opacity(borderColor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(aesthetic comment) 4-space indents make this kind of variable declaration look neater.
ppadplus: ann._ypadplus, | ||
ppadminus: ann._ypadminus, | ||
}); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😉
var toLog = (newType === 'log') && (ax.type === 'linear'), | ||
fromLog = (newType === 'linear') && (ax.type === 'log'); | ||
var toLog = newType === 'log' && ax.type === 'linear', | ||
fromLog = newType === 'linear' && ax.type === 'log'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to disable this kind of change?
Using unnecessary parenthesis to improve readability is a good thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are some controls, but not sure how granular you can get.
if (style > 5) rot = 0; // don't rotate square or circle | ||
d3 | ||
.select(el.parentElement) | ||
.append('path') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is going to be tricky.
I'd be surprised if prettier
respects d3
half-indenting conventions.
👍 to get rid of half-indents.
👎 for not respecting vertical formatting
moduleType: 'component', | ||
name: 'annotations', | ||
moduleType: 'component', | ||
name: 'annotations', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, here prettier
does respect vertical formatting and keeps the empty line.
'#7f7f7f', // middle gray | ||
'#bcbd22', // curry yellow-green | ||
'#17becf' // blue-teal | ||
'#1f77b4', // muted blue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no double-space before inline comment?
'use strict'; | ||
|
||
var tinycolor = require('tinycolor2'); | ||
var isNumeric = require('fast-isnumeric'); | ||
|
||
var color = module.exports = {}; | ||
var color = (module.exports = {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat!
} | ||
if (!container || typeof container !== 'object') return; | ||
|
||
var keys = Object.keys(container), i, j, key, val; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another example of not respecting vertical formatting.
Not surprisingly there are good and bad things about I'd like to keep |
Thanks for the good feedback @n-riesco. I'm inclined to agree. I think I'll close this for now as going maybe a little too far, though I'll hold out hope that it becomes the future of linting. 😄 The main thing that sends me in cold sweats for standard is the requirement of manually reworking hundreds of variable declarations and similar things that the auto-formatter isn't able to fix automatically. |
Just a quick test with prettier. Adds the following features:
lint
withprettier-check
(to assert PRs satisfy prettier formatting)lint-fix
withprettier --write
(to apply formatting)husky
+lint-staged
to automatically apply prettier formatting to staged files when committingExcept for having to read the code (not to be taken for granted without consideration), this would hopefully make prettier zero-overhead without any effort in transitioning (as opposed to standard which will require a lot of manual formatting for what it's unable to fix.)
Note: current failure seems to be regex-based metadata-stripping browserify transform. Would need a couple tweaks to recognize line breaks.