nandorojo / solito

🧍‍♂️ React Native + Next.js, unified.
https://solito.dev
MIT License
3.54k stars 180 forks source link

Some problems with Eslint and Typescript #40

Closed yuriazevedo11 closed 2 years ago

yuriazevedo11 commented 2 years ago

Hey @nandorojo, huge fan of your work here

I've created a repo using create-solito-app yesterday, but I'm having some issues. Maybe I'm missing something, but I don't have much knowledge on monorepos

Eslint

With Eslint, next/ has its own .eslintrc.js. How can I extend with my own config there? I do have my own Eslint npm package. One side note, running the nextjs app was not working until I added this:

module.exports = {
  extends: 'next',
  root: true,
  rules: {
    '@next/next/no-html-link-for-pages': ['error', 'apps/next/pages/'],
  },
};

Maybe this should be in the template?

Typescript

And with Typescript, my intellisense is a mess on Vscode. Some auto imports simply just not work.

Example: I just deleted MotiLink import from this template file, but Typescript can't find MotiLink to import Screen Shot 2022-04-08 at 10 48 35

This was only one example, but I'm having this same problem with some other packages, depending from where I try to import them.

Currently, I've just added some devDependencies on root, like husky, lint-staged and commitlint for example.

Can you help me out?

nandorojo commented 2 years ago

hey! you mentioned a number of different questions here. i’ll try to answer later today

nandorojo commented 2 years ago

as for the autocomplete, i'm looking into how next/link etc does this. it's kinda complicated typescript stuff so i'll have to play with it, hopefully i can figure out a simple solution. typescript really doesn't document this well

nandorojo commented 2 years ago

With Eslint, next/ has its own .eslintrc.js. How can I extend with my own config there?

Doesn't this work?

{ "extends": ["next", "your-config-here"] }
yuriazevedo11 commented 2 years ago

About the Eslint, I'm having some conflicts between my config and 'next', I'll take a deeper look

What about @next/next/no-html-link-for-pages rule? Nextjs app wasn't running before this rule was added

About the Typescript autocomplete, let me know if you find out something 👍

nandorojo commented 2 years ago

What isn’t working without that rule? Building? Can you please clearly outline reproducible steps?

yuriazevedo11 commented 2 years ago

yarn web wasn't working for me without this rule

yuriazevedo11 commented 2 years ago

I did a clean install, removing node_modules. Seems to be working without this rule now

nandorojo commented 2 years ago

worked fine for me without the rule in a fresh app

yuriazevedo11 commented 2 years ago

Yeah, I guess Eslint was my bad

I'm just missing now the Typescript autocomplete, can you reproduce this problem?

nandorojo commented 2 years ago

yes, and i think i found the solution

nandorojo commented 2 years ago

can you try upgrading solito to 0.0.25 and see if that fixes it?

yuriazevedo11 commented 2 years ago

It worked 🚀

Still having this problem tho, but I guess is not a big deal: Screen Shot 2022-04-08 at 17 00 13

There's still some problems for me:

This one is pretty bad, I'd like to autocomplete the screens import here Screen Shot 2022-04-08 at 17 03 48

This one is not that bad, because the imports of screens will be in packages/app/navigation/native Screen Shot 2022-04-08 at 17 04 26

But inside packages/app/navigation/native, the autocomplete only shows apps/next/pages, not the packages/app/features

Screen Shot 2022-04-08 at 17 09 08

Do you have any clue how to fix these? Specially screenshot 2 and 4

nandorojo commented 2 years ago

yeah, to fix those, you’d need to install solito in apps/next too. this is a constraint of typescript monorepos. i’ve written about it here:

https://github.com/nandorojo/ts-monorepo-autoimport-guide

generally this shouldn’t matter, since almost all of your code should be written in the app folder. but you can solve it with the guide i linked to there

yuriazevedo11 commented 2 years ago

Thanks! Nice guide :)

What about screenshots 2 and 4? I really do miss these autocomplete imports from packages/app/*

nandorojo commented 2 years ago

i don’t get screenshot 2. you’re writing export default of a variable that doesn’t exist. if you’re trying to re-export a screen, that’s the wrong syntax

nandorojo commented 2 years ago

for 4, don’t use the same name when exporting in next?

also, in general, use named exports, not default ones

yuriazevedo11 commented 2 years ago

Sugestion for 4 works 🚀 . And I do use named exports only, but next/pages need export default

About screenshot 2, I can work around it. I just wanted autocomplete for the screen I'll need to re-export in next/pages, but it does not work

Thank you so much for your help, keep up the good work :D

nandorojo commented 2 years ago

Hey I think I solved the ESLint issue in this commit btw! https://github.com/nandorojo/solito/commit/610be58de58a81911a8ce8a7c227c070be16c258

I updated the root lint file and deleted the linter file in apps/next (though you don't have to do that).