-
Notifications
You must be signed in to change notification settings - Fork 1
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
Added eslint-plugin-react to the CLIEngine #88
Conversation
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.
Looking good so far!
Left to-do:
- Add
JSX
language (I think??) - Add at least one test to https://github.com/Unibeautify/beautifier-eslint/tree/master/test
src/index.ts
Outdated
@@ -23,6 +23,11 @@ export const beautifier: Beautifier = { | |||
name: "ESLint", | |||
package: "eslint", | |||
}, | |||
{ | |||
type: DependencyType.Node, | |||
name: "ESLintPluginReact", |
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.
ESLint-plugin-React
(as seen in https://www.npmjs.com/package/eslint-plugin-react ) may be a better name
.
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.
Good approach, but what about on L60, where we assign it to a variable. There I need to call it ESLintPluginReact
and then we would have two different styles.
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.
Yup, change line 60, too, so they are the same 👍 .
@Glavin001 I added JSX like that: Now I got stuck by testing it. I had to rename the .eslintrc.yml to .json because I couldn't get it running in yml. I really tried adapting the react rules but had no luck. I think the problem below is caused by jest or some directory issue where eslint is not looking in the test rather then in the root of the project for a configuration file. https://gist.github.com/muuvmuuv/eae245f991d0c6b6e012a00326ee5598 |
@szeck87 any advice on @muuvmuuv 's problem above in #88 (comment) ? I think you setup most of this beautifier. |
@muuvmuuv I see your Gist with the file changes and test report. You can commit your changes to this PR, so we can see what changes you've done, let Travis CI run the tests, and comment on lines of code 👍 . |
@muuvmuuv you need to include the From there ESLint and/or the React plugin errors due to this message: |
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 core ESLint beautifier should continue to work if the user is not using the React plugin.
package.json
Outdated
@@ -37,7 +37,8 @@ | |||
"@types/jest": "23.3.1", | |||
"@types/node": "10.9.3", | |||
"@types/read-pkg-up": "3.0.1", | |||
"eslint": "5.4.0", | |||
"eslint": "^5.4.0", | |||
"eslint-plugin-react": "^7.11.1", |
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.
@szeck87 pointed out to me on Slack eslint-plugin-react
should also be added as a peerDependency
:
beautifier-eslint/package.json
Lines 33 to 40 in 221ef55
"eslint": "^4.19.1 || ^5.0.0" | |
}, | |
"devDependencies": { | |
"@types/eslint": "4.16.3", | |
"@types/jest": "23.3.1", | |
"@types/node": "10.9.3", | |
"@types/read-pkg-up": "3.0.1", | |
"eslint": "^5.4.0", |
src/index.ts
Outdated
type: DependencyType.Node, | ||
name: "ESLint-plugin-React", | ||
package: "eslint-plugin-react", | ||
}, |
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.
Should be optional
. cc @szeck87 from #87 (comment)
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.
Yep, please add optional: true
src/index.ts
Outdated
@@ -51,6 +57,9 @@ export const beautifier: Beautifier = { | |||
}: BeautifierBeautifyData) { | |||
return new Promise<string>((resolve, reject) => { | |||
const { CLIEngine } = dependencies.get<NodeDependency>("ESLint").package; | |||
const ESLintPluginReact = dependencies.get<NodeDependency>( |
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.
To allow for the React plugin to be optional, we should check beautifierConfig
(or config
after line 63).
Installation instructions from https://www.npmjs.com/package/eslint-plugin-react show:
"extends": [
"eslint:recommended",
"plugin:react/recommended"
]
So we should check for plugin:react/
and if it exists in extends
then get the React plugin dependency (line 60) and add the plugin (line 79).
cc @szeck87 for #87 (comment)
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.
You can try that. If that can't be done, dependencies.get<NodeDependency>("ESLint-plugin-React")
will have an error that you can check for.
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.
@szeck87 Good point! Actually, let's just skip the checking of beautifierConfig
entirely, that sounds like an unnecessary rabbit hole.
We can use the .has
method! https://api.unibeautify.com/classes/_dependencymanager_dependencymanager_.dependencymanager.html#has
Like this:
if (dependencies.has("ESLint-plugin-React")) {
cli.addPlugin("eslint-plugin-react", dependencies.get<NodeDependency>("ESLint-plugin-React").package);
}
🎉
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.
Whoops. @szeck87 pointed out .has
will not work here.
We actually want to use dependency.isInstalled
: https://api.unibeautify.com/classes/_dependencymanager_dependency_.dependency.html#isinstalled
So more like this:
const reactPlugin = dependencies.get<NodeDependency>("ESLint-plugin-React");
if (reactPlugin.isInstalled) {
cli.addPlugin("eslint-plugin-react", reactPlugin.package);
}
Feel free to clean up the above.
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.
When I do this I'm getting : A Promise was found that appears to not have resolve or reject invoked on all code paths (promise-must-complete)
@Glavin001
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.
Yea I noticed that too, might have to comment on the line above the if
statement:
// tslint:disable-next-line:promise-must-complete
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.
Where is this error coming from @muuvmuuv ? Could you push a commit with this?
Maybe you already did push a commit. I currently see Travis CI failing:
npm ERR! Unexpected token } in JSON at position 994
Added "if plugin installed" to react plugin
# Conflicts: # package.json
src/index.ts
Outdated
type: DependencyType.Node, | ||
name: "ESLint-plugin-React", | ||
package: "eslint-plugin-react", | ||
}, |
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.
Yep, please add optional: true
package.json
Outdated
@@ -30,14 +30,16 @@ | |||
"homepage": "https://github.com/Unibeautify/beautifier-eslint#readme", | |||
"peerDependencies": { | |||
"unibeautify": ">= 0.12.1", | |||
"eslint": "^4.19.1 || ^5.0.0" | |||
"eslint": "^4.19.1 || ^5.0.0", | |||
"eslint-plugin-react": "^7.11.1", |
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.
Remove the comma at the end here
@@ -67,6 +76,10 @@ export const beautifier: Beautifier = { | |||
rules: finalOptions, | |||
}; | |||
const cli: CLIEngine = new CLIEngine(cliOptions); | |||
// tslint:disable-next-line:promise-must-complete |
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 may be a bug with https://github.com/Microsoft/tslint-microsoft-contrib/
If you can create a much smaller test case, you could report an issue 👍 .
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.
It looks like any if
is a branch, and doesn't bother looking what it actually does to consider whether the promise completes or not (since we are using return new Promise<string>((resolve, reject) => {
).
Maybe it's safer to remove that block and change the returns at the bottom to return Promise.resolve
.
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.
Let's not make any major changes yet. We can try different approaches in a later PR 👍 .
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.
@Glavin001 would you mind creating a small test case and make an issue there? I think you can way better explain that error case.
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.
@szeck87 had some good comments. Once those are fixed up we can merge 🎉!
src/index.ts
Outdated
@@ -21,11 +21,18 @@ export const beautifier: Beautifier = { | |||
{ | |||
type: DependencyType.Node, | |||
name: "ESLint", | |||
package: "eslint", | |||
package: "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.
Put a comma at the end of package: "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.
Can we enable a linter for this? I really don't know when to put a comma and when I shouldn't …
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.
https://palantir.github.io/tslint/rules/trailing-comma/ should be catching it, but it's not.
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.
Looks like it is set to ignore
for multiline
: https://github.com/Unibeautify/beautifier-eslint/blob/master/tslint.json#L294-L300
@muuvmuuv Could you tweak this and make sure TSLint is telling you to add the comma? :)
src/index.ts
Outdated
type: DependencyType.Node, | ||
name: "ESLint-plugin-React", | ||
package: "eslint-plugin-react", | ||
optional: true |
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.
Put a comma at the end of optional: true
@muuvmuuv just add in those two commas I mentioned and I'll approve. |
@szeck87 @Glavin001 I've now added this ESLint issue we discussed before. Sorry that the file is beautified that much, but that is what Unibeautify is doing when I save that file. |
@muuvmuuv can you rebase again so the CI tests can run? |
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 this is good to go!
Awesome work, @muuvmuuv ! Thanks for contributing! 🎉 |
Published to v0.6.0! 🎉 |
See: #87