Open muuvmuuv opened 6 years ago
Pull Requests welcome!
I think adding official support to beautifier-eslint
for React makes sense.
package.json
dependencieseslint-plugin-react
as a Dependency
to https://github.com/Unibeautify/beautifier-eslint/blob/master/src/index.ts#L21-L25eslint-plugin-react
to CLIEngine
( https://github.com/Unibeautify/beautifier-eslint/blob/master/src/index.ts#L53 ) so ESLint can use the plugin. See https://eslint.org/docs/developer-guide/nodejs-api#cliengineaddplugin JSX
: https://github.com/Unibeautify/beautifier-eslint/blob/master/src/index.ts#L28Let me know if you have any questions!
Applicable resources:
cc @szeck87
@Glavin001 Okay I'll try to do this. btw. I think it would be useful to give an extra parameter to the dependency object to specify which is the core package and which are plugins or something else.
And I thought about another object in the Beautifier interface like "addPlugin" which returns the program containing all plugins. Just to separate those things.
Plugins (like ESLint Plugins) are an implementation detail of the specific beautifier (i.e. ESLint), not of Unibeautify. A Unibeautify Beautifier should be complete with all applicable plugins to support the languages (e.g. JavaScript, JSX) and options.
@Glavin001 should eslint-plugin-react
be a dependency or a peer dependency? I think it should be optional since not everyone will use beautifier-eslint
for JSX.
@szeck87 I think peerDependency
makes sense: https://github.com/npm/npm/issues/3066#issuecomment-154161544
@Glavin001 I thought about something else to make it more pluggable.
beautifier-eslint is using ESLint executor from its node_modules, so it is not possible to load plugins through a projects .eslintrc.json, so beautifier-eslint would need to install them in his node_modules. What if we would use the projects eslint when some plugins are used. So we are noticing the user "We have recognised that you are using eslint plugins in your config. To use them you need to install eslint, so beautifier-eslint can use this executable". This vscode plugin does a similiar thing: https://github.com/Microsoft/vscode-eslint/blob/master/client/src/utils.ts
I will try some things locally and hope to get this working.
The issue is the Unibeautify Beautifier needs to be aware of all of the languages and options it supports. So by adding eslint-plugin-react
there are more languages, such as JSX, and more options, any React specific rules. These need to be known ahead of time.
What if we would use the projects eslint when some plugins are used.
I want to support loading eslint
and other Node Dependencies from:
node_modules/
node_modules
This should be handled by https://github.com/Unibeautify/unibeautify/blob/master/src/DependencyManager/NodeDependency.ts and potentially https://github.com/Unibeautify/vscode
I think Unibeautify's NodeDependency
may still need some work to support all of the above.
I will try some things locally and hope to get this working.
I do not recommend investigating anything experimental like this until we've discussed it fully. I think you're making great progress on https://github.com/Unibeautify/beautifier-eslint/pull/88 and both @szeck87 and I have made comments. Let's get https://github.com/Unibeautify/beautifier-eslint/pull/88 merged and then we can investigate how to make it even better.
🎉 https://github.com/Unibeautify/beautifier-eslint/pull/88 has been merged. 🎆
@Glavin001: I thought about somethings yesterday evening. We could look for the package.json that is next to the file that will be formatted or the projectdir. Then we search for matches with eslint-plugin-*
. If there're any plugins, include them with NodeDependencies and tag an eslint Dependencies as its parent. After that loop them and add them to the CLI.
This would add plugins dynamically to ESLint's Engine, however, the bigger problem is the Beautifier's supported options and languages. Your PR #88 worked well with having eslint-plugin-react
as an optional: true
dependency and checking if it was installed -- similar to checking package.json
as you described above, except it checks for node_modules/
.
Now that I think of it, I do have a problem with #88 in that the eslint-plugin-react
was optional except JSX
language will always be shown as supported by the beautifier, even if eslint-plugin-react
was not loaded. We may have to think about this a little bit more. cc @szeck87 . If the language is JSX and eslint-plugin-react
is not installed, should this throw an error? 🤔
Maybe we will let this open and rethink about NodeDependencies first. There should be a change to make it more dynamic when working with plugins.
Agreed. I'll leave this issue open :).
@Glavin001 You need to update the package version to let npm update the package in e.g. the website. Currently I get Error: Cannot find module 'eslint-plugin-react'
because v0.5.0 has it not set a peerdependeny :)
You're right. We need to publish a new release with a version bumped to 0.6.0
.
Current version 0.5.0
was published maybe 5 months ago 🔥 :
Coming soon 😄 . Thanks, @muuvmuuv !
Published to v0.6.0! 🎉
@Glavin001 may give it a tag 0.6.0
to let GitHub make a downloadable package? I think we should always add minor version updates to a version tag.
Good thinking. I was in a rush earlier. Created a new GitHub Release: https://github.com/Unibeautify/beautifier-eslint/releases/tag/v0.6.0
I'm using VSCode with the current version of Uniebeautify and have ESLint enabled with
prefer_beautifier_config
option. Now I'm working on a react project with gatsby (I'm using this template: https://github.com/haysclark/gatsby-starter-casper) and got the following error (copied form the dev console):I think it is because the beautifier plugin is using its own or the global ESLint installation? I have one installed in my project with the plugin it needs. Maybe this can be fixed when Unibeautify is checking whenever a plugins CI is already installed in 1. project 2. global and then fall back to the local installation.