Skip to content

[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

Closed
wants to merge 1 commit into from
Closed

[EXPERIMENTAL] Prettier! #1629

wants to merge 1 commit into from

Conversation

rreusser
Copy link
Contributor

@rreusser rreusser commented Apr 26, 2017

Just a quick test with prettier. Adds the following features:

  • replace lint with prettier-check (to assert PRs satisfy prettier formatting)
  • replace lint-fix with prettier --write (to apply formatting)
  • husky + lint-staged to automatically apply prettier formatting to staged files when committing

Except 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.

@rreusser rreusser mentioned this pull request Apr 26, 2017
@etpinard
Copy link
Contributor

husky + lint-staged to automatically apply prettier formatting to staged files when committing

Too magical for my taste. But yeah, nice try.

@rreusser
Copy link
Contributor Author

Agreed on the magic, but grep shows at least 260 commit messages containing the word "lint". I forget sooo often.

@etpinard
Copy link
Contributor

I forget sooo often.

Nothing stops you from setting this up locally 🍻

@rreusser
Copy link
Contributor Author

rreusser commented Apr 27, 2017

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')]);
Copy link
Contributor

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'),
Copy link
Contributor

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?

Copy link
Contributor Author

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'),
Copy link
Contributor

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 .",
Copy link
Contributor

@n-riesco n-riesco Apr 27, 2017

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.

Copy link
Contributor Author

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;
Copy link
Contributor

@n-riesco n-riesco Apr 27, 2017

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!

Copy link
Contributor Author

@rreusser rreusser Apr 27, 2017

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);
Copy link
Contributor

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 {
Copy link
Contributor

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';
Copy link
Contributor

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.

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 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')
Copy link
Contributor

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',

Copy link
Contributor

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
Copy link
Contributor

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 = {});
Copy link
Contributor

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;
Copy link
Contributor

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.

@n-riesco
Copy link
Contributor

Not surprisingly there are good and bad things about prettier's changes.

I'd like to keep eslint for linting though. I find very useful that it reports possible errors (e.g. unused variables and variables scopes).

@rreusser
Copy link
Contributor Author

rreusser commented Apr 27, 2017

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.

@rreusser rreusser closed this Apr 27, 2017
@etpinard etpinard deleted the prettier branch May 16, 2017 19:23
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

3 participants