-
Notifications
You must be signed in to change notification settings - Fork 508
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
VS Code does not automatically 'play nicely' with tsdx #354
Comments
What changes did you need to make for this to work? I believe personally I just had to add the below to
|
That does help to enable Prettier, but I mostly want to get ESLint to work (which also enables Prettier). And I haven't been able to get that to work. In another project, without TSDX, I use: {
"eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",
"javascriptreact",
{
"language": "html",
"autoFix": true
},
{
"autoFix": true,
"language": "typescript"
},
]
} But that does not work here, since ESlint cannot find any configuration file (nor have I been able to find it manually):
Am I missing something that should be obvious? |
docs welcome for this for sure |
In the meantime. Can anyone tell me how I could get the ESLint configurations? I'd like to have an |
@Vinno97 It's in the docs: https://github.com/jaredpalmer/tsdx#npm-run-lint-or-yarn-lint |
Oh my apologies, I must have missed that. Thanks. |
I resolved this by using |
This is broken for all ESLint extensions, not just for VSCode, as the config is missing. The solution is to do what |
CRA just adds "eslintConfig": {
"extends": "react-app"
}, |
That is also an ESLint config. |
I mean that if you use |
I don't think that's going to be an issue as unlike CRA, tsdx allows overriding the config by default. It's also a fairly simple config with only three extends and a rule config (workaround for making React optional). |
I'm not following; the issue is that
The way |
I've implemented something similar to (and inspired by) My solution was to create an ESLint config package hiding the "magic" and just run ESLint through my CLI - which is going to read the config file. My CLI handles creating the file if it's not there, support flags from But I don't know if /cc @jaredpalmer @sw-yx |
Here's eslint-config-react-app for reference. CRA uses a monorepo and multiple packages, but an alternative that allows keeping one package would be local paths, so something like this in
|
Yarn 2 is already stable and doesn't support I want to see how far I can get with always writing in the config but merging in older configs for back compatibility. |
This comment has been minimized.
This comment has been minimized.
BEWARE -- you might be over complicating/overthinking things with your vscode setup! I certainly did. I wasted MANY hours messing around with config files, plugins, npm packages, etc., before coming to realize that everything I wanted was pretty much provided by tsdx from the start. Before I go on, let me make clear the two goals that I wanted to achieve with my tsdx-vscode setup:
That's it. I don't need super-fancy configuration, I just want the ability to set basic things like single vs double quotes, tab size, etc. I also don't mind being subject to "opinionated" rules sets, I mainly want consistency across my code base. With that said, I eventually realized that tsdx (very nearly) gives me those two goals right out of the box via the "prettier" section in {
"prettier": {
"printWidth": 80,
"semi": true,
"singleQuote": true,
"trailingComma": "es5",
"tabWidth": 2,
"htmlWhitespaceSensitivity": "ignore"
},
} Note: I added the last two rules here. In order to fulfill the first goal above, all you need is to do is the following:
In order to fulfill the second goal, you just need to make the linting script called by husky "fix" your code by adding "--fix" within ...,
"husky": {
"hooks": {
"pre-commit": "tsdx lint --fix"
}
},
... And, voila, my two goals are met. If I now change e.g. "tabWidth": 3 in my prettier block, then my files will readjust automatically upon formatOnSave, etc. tl;dr The reason I wasted so much time previously is because in my hasty read of the tsdx readme I inferred that in order to tweak your formatting rules you needed to create an eslint config file and then make that the single source of truth for your formatting rules. However, I was unable to get vscode to recognize such an eslint config file as the source of truth for my formatting rules (despite, as I said, many hours of trying different combinations of extensions, plugins, packages and configurations). Once I realized that you don't need to use this eslint config file to set rules (i.e. all I needed was already there in the "prettier" block in In summary: to avoid the sort of rabbit holes I went down, I would suggest making the following alteration to the tsdx readme (my suggested edits in bold):
|
Not sure what the exact issues you faced with using |
Current Behavior
VS Code does not detect or use Eslint and Prettier in the workspace (out of the box).
Expected behavior
The first paragraph of the README seems to suggest VSCode will automatically work nicely with TSDX's environment. Leading me to believe it was plug-and-play.
Suggested solution(s)
Maybe create an (opinionated) settings file in the
.vscode
folder of the workspace? Or at least dedicate a section in the README to the required configurations in VS Code.Additional context
This "bug" might be out of the intended scope of the project, but the README led me to believe it would work this way.
Your environment
The text was updated successfully, but these errors were encountered: