Skip to content
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

Add opt-in prettier #15106

Closed
wants to merge 7 commits into from
Closed

Conversation

mattapperson
Copy link
Contributor

I added prettier in this PR in line with the discussion in #14810.

Maybe this won't be accepted and that is OK, I just wanted to have something "real" to discuss and accept/alter/reject vs speaking in abstract

Notes:

  • This is opt-in, the .prettierignore file lists all main kibana directories and then each plugin separately. This way each plugin can be moved one at a time to using prettier.
  • I used a lint-staged plugin to ensure that going forward, any prettier opted-in plugins/sections of kibana stay formatted to prettier without getting in the way of those that are not.
  • Once you remove a line from the .prettierignore file, you will want to add it to the eslitignore file to prevent the old system and eslint rules from preventing you from committing

Copy link
Contributor

@kimjoar kimjoar left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for creating this PR, @mattapperson.

I like this setup with the ignore file. I wish Prettier could run multiple ignore files at the same time, then we could just have it run for both .gitignore and for .prettierignore at it would simplify this file a bit, but looks like it only supports a single file: https://prettier.io/docs/en/cli.html#ignore-path

I also added a note about the current precommit setup in Kibana, so we don't end up with two setups.

I definitely think this will help us gradually move towards Prettier 🎉 👏

package.json Outdated
@@ -54,6 +51,7 @@
"build": "grunt build",
"release": "grunt release",
"start": "sh ./bin/kibana --dev",
"prettier": "./node_modules/prettier/bin/prettier.js \"./**/*.js\" --write",
Copy link
Contributor

Choose a reason for hiding this comment

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

When you have prettier in the deps, npm already makes the bin available, so this could just be:

"prettier": "prettier --write './**/*.js'"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct me if I’m wrong, but if someone has another version installed globally, won’t it use the global version first if you do that?

Copy link
Contributor

Choose a reason for hiding this comment

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

It will use the local first, then the global if no local exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gtk thanks!

package.json Outdated
@@ -21,6 +14,10 @@
"bugs": {
"url": "http://github.com/elastic/kibana/issues"
},
"pre-commit": ["pre-commit"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Kibana already has a precommit setup that's triggered a bit further down in this file:

"precommit": "node scripts/precommit_hook",

It ends up running this file: https://github.com/elastic/kibana/blob/master/src/dev/run_precommit_hook.js

I think we should probably add this prettier setup there so we don't have multiple precommit setups (That might mean that we should create a scripts file for running Prettier instead, see https://github.com/elastic/kibana/tree/master/scripts). Let me know if you want to zoom or something about this setup. We've also gradually moved more towards having scripts in the ./scripts folder (though not sure it's needed here)

cc @spalger, who knows all about this setup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This I did intentionally so as we finish the migration the mass of stuff needed for eslint could be removed in favor of something simpler and also the generally accepted community recommended setup for prettier. However if this is not desired here I’m happy to change that attack plan. @spalger ?

package.json Outdated
@@ -215,6 +214,8 @@
"yauzl": "2.7.0"
},
"devDependencies": {
"lint-staged": "5.0.0",
"prettier": "1.8.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

Btw, if you use npm install --save-dev prettier the dep will be added to the "correct" location in devDependencies (when npm install X or yarn add X runs on the file, it will sort the deps alphabetically, so if we add a dep to the top here we'll likely have to re-commit this later when npm or yarn has moved them around)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bah! I thought yarn did this even if you pasted in once you installed it. NPM used to right? Idk oh well yea that needs to be correctly sorted.

package.json Outdated
],
"description":
"Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elasticsearch.",
"keywords": ["kibana", "elasticsearch", "logstash", "analytics", "visualizations", "dashboards", "dashboarding"],
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: revert these changes ^?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

heh yea sorry, this was prettier running on the file before I added it to the ignore list lol

.prettierrc Outdated
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"semi": true
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just go with the defaults here? (#14810 (comment))

However, I'm +1 on having the .prettierrc though, even if it just becomes

{
}

for now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah cool, yea I missed that comment.

package.json Outdated
@@ -21,6 +21,15 @@
"bugs": {
"url": "http://github.com/elastic/kibana/issues"
},
"pre-commit": [
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this config for? We already use husky to call npm run precommit, do we need both of these?

package.json Outdated
@@ -53,6 +62,7 @@
"checkLicenses": "grunt licenses",
"build": "grunt build",
"release": "grunt release",
"prettier": "prettier \"./**/*.js\" --write",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer that this was node scripts/prettier rather than an npm script, See #11095

@mattapperson
Copy link
Contributor Author

@spalger updated with your assistance :)

process.argv.push('./**/*.js');
}

if (!flags.write) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this allow --no-write to work here? Might have to check for the flags.noWrite, or === false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@spalger I don't see the need to support that. This command is just to let a team convert their entire project in one PR vs how editor plugins work converting 1 file at a time.

Copy link
Contributor

@kimjoar kimjoar left a comment

Choose a reason for hiding this comment

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

I had a couple nitpicks, but other than those I think we should get this is in.

Prettier 1.9.0 just got released, so would be great to update that dep first.

"lint-staged": {
"*.js": [
"prettier --list-different",
"git add"
Copy link
Contributor

@kimjoar kimjoar Dec 5, 2017

Choose a reason for hiding this comment

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

Can we remove this git add? I don't like tooling doing git stuff for me.

@@ -67,6 +74,7 @@
"uiFramework:createComponent": "yo ./ui_framework/generator-kui/app/component.js",
"uiFramework:documentComponent": "yo ./ui_framework/generator-kui/app/documentation.js"
},

Copy link
Contributor

Choose a reason for hiding this comment

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

remove this line

@spalger
Copy link
Contributor

spalger commented Dec 28, 2017

I've been using prettier eslint plugin with much success lately. Do you think we could just go that route so we're adding a new tool but rather extending a tool we're already using? If we do then we could just add the prettier/prettier rule to a subset of files via eslint overrides.

@kimjoar
Copy link
Contributor

kimjoar commented Feb 5, 2018

Closed by #16514

@kimjoar kimjoar closed this Feb 5, 2018
@mattapperson mattapperson deleted the add-prettier branch August 7, 2018 13:18
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