Open-Assistant icon indicating copy to clipboard operation
Open-Assistant copied to clipboard

Add eslint rules for consistent imports

Open AbdBarho opened this issue 2 years ago • 13 comments

To have consistent imports, add eslint rules to encourage (and perhaps enforce?) a preferred ordering.

The rules in question:

https://eslint.org/docs/latest/rules/sort-imports

Stick with the default eslint sorting rules (link), in case we are not happy with it, we can change it later.

Notes: Should we reformat all files at once?

AbdBarho avatar Dec 28 '22 14:12 AbdBarho

I'm quite new to all of this though I thought that maybe we could have a script that fix the import that can be run before there is a commit. Also I was having a problem installing sort-import so I tried to do it with isort as an alternative

Jac-Zac avatar Dec 28 '22 17:12 Jac-Zac

This is what I have done https://github.com/Jac-Zac/Open-Assistant/tree/sort-imports, could it be good any other suggestions ?

Jac-Zac avatar Dec 28 '22 17:12 Jac-Zac

@Jac-Zac thanks! we welcome all contributions.

For the backend, we already have pre-commit hooks that should guarantee formatting with isort.

However, this issue covers the typescript code for the website, using eslint. Would you like to contribute?

AbdBarho avatar Dec 28 '22 17:12 AbdBarho

This is what I have done https://github.com/Jac-Zac/Open-Assistant/tree/sort-imports, could it be good any other suggestions ?

thanks for the suggestion. As @AbdBarho says, we already have enforcement of consistent imports in python, due to pre-commit. This issue is about the typescript code. We are already running next lint also in pre-commit, which includes (as far as I can tell) eslint, but what's left to do is to define the eslint-rules, because so far we're just using default ones.

yk avatar Dec 28 '22 17:12 yk

Oky I'll try but as I said I'm not sure I can help if I can't do it in a few hours I'll let you now else I'll try to write it

Jac-Zac avatar Dec 28 '22 18:12 Jac-Zac

I hope this is more on the line on what you were asking for https://github.com/Jac-Zac/Open-Assistant/tree/new-eslintrc.cjs

Jac-Zac avatar Dec 28 '22 18:12 Jac-Zac

I have created a config file .eslintrc.cjs and with the default configuration required by following what you gave here and also this. (I lost a bit of time by putting it in the root directory before I realize it should have been in the website directory)

Jac-Zac avatar Dec 28 '22 18:12 Jac-Zac

@Jac-Zac great! could you please replace or extend this file? https://github.com/LAION-AI/Open-Assistant/blob/main/website/.eslintrc.json

AbdBarho avatar Dec 28 '22 18:12 AbdBarho

I keep on getting the error "ESLint couldn't find the config "next/core-web-vitals" to extend from. Please check that the name of the config is correct.". But I get it also if i run the old eslintrc.json thus I suppose that maybe I'm missing something to install. If someone knows way I'm running into the problem or if it is just a problem on my head it would be helpful. However I have replaced the old .eslintrc, with this .eslintrc.json. Does that work for you (sorry If I'm not that helpful or I'm wasting time).

Jac-Zac avatar Dec 28 '22 19:12 Jac-Zac

@Jac-Zac no worries! could you please create a merge request? I can check whats the problem.

AbdBarho avatar Dec 28 '22 19:12 AbdBarho

Also I installled this npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint typescript Thous typescript might need to be installed to make the pre-commit hooks work

Jac-Zac avatar Dec 28 '22 19:12 Jac-Zac

Thous typescript might need to be installed to make the pre-commit hooks work

the pre-commit hook runs bash -c 'cd website && npm install && npm run lint' (in .pre-commit-config.yaml), so anything in package.json will be there

yk avatar Dec 29 '22 10:12 yk

ah sorry I see there's plenty of discussion in the PR. all good :)

yk avatar Dec 29 '22 10:12 yk