Skip to content
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

Upgrade eslint, apply lint fixes, add lint github action #2667

Closed
wants to merge 24 commits into from

Conversation

ff137
Copy link
Contributor

@ff137 ff137 commented Sep 3, 2023

Upgraded eslint + config + prettier dependencies with the following:

npm install --save-dev eslint@latest prettier@latest eslint-config-prettier@latest eslint-plugin-import@latest eslint-config-airbnb@latest

Fixed linting errors where possible and added ignores otherwise

Added lint job to github actions

@ff137
Copy link
Contributor Author

ff137 commented Sep 3, 2023

Running the lint script with npm run lint yields the following errors.
Some can be fixed automatically, but I'll go through these until linting passes.

$ npm run lint

> opendota-core@21.0.2 lint
> eslint . --ext .js,.jsx --ignore-path .gitignore


/root/dev/ff137/core/dev/cassandraRandom.js
  13:74  error  Parsing error: Unexpected token .

/root/dev/ff137/core/dev/cassandraTest.js
  11:58  error  Unary operator '++' used          no-plusplus
  13:22  error  Unexpected `await` inside a loop  no-await-in-loop

/root/dev/ff137/core/index.js
  15:5  error  Strings must use doublequote  quotes

...

✖ 45 problems (45 errors, 0 warnings)
  9 errors and 0 warnings potentially fixable with the `--fix` option.

@ff137
Copy link
Contributor Author

ff137 commented Sep 3, 2023

Quite a few of those errors (such as Parsing error: Unexpected token .) are due to linter not knowing the javascript version being used. To fix that, I added the following to the .eslintrc.json:

  "parserOptions": {
    "ecmaVersion": 2023
  },

Now there are 181 problems ... 104 of which are automatically fixable.

Edit: 2021 seems to be version that supports node16 fully - later version only somewhat. But 2021 reports same number of errors

@ff137
Copy link
Contributor Author

ff137 commented Sep 3, 2023

Ok, with the help of Cursor (VS Code with ChatGPT), I was able to fix most of the linting errors that remained.

Some nice improvements include replacing await in a loop with executing all promises concurrently. The other changes are fairly trivial.

There's a few cases where I couldn't figure out how to replace the await in a loop.
In svc/cassandraDelete.js and dev/cassandraRandom.js, there is a while(true) loop that contains await commands. No idea how to unravel that, so I'm leaving it as is.

@ff137 ff137 changed the title ⬆️ Upgrade eslint related dependencies to latest ⬆️ Upgrade eslint dependencies & 🎨 apply lint fixes Sep 3, 2023
@ff137
Copy link
Contributor Author

ff137 commented Sep 3, 2023

So, my renaming of variables (from snake_case to camelCase) broke something in keyManagement/tests, so rolling back those changes

I notice that test are actually quite sparse in this repo (no tests for routes), so with this refactoring it may be worthwhile if I include some more tests to make sure I didn't break anything else with the linting changes.

I guess I can only get around to that soonTM, so I'll leave PR as draft for time being

@ff137 ff137 changed the title ⬆️ Upgrade eslint dependencies & 🎨 apply lint fixes Upgrade eslint, apply lint fixes, add lint github action Sep 3, 2023
@howardchung
Copy link
Member

I'm going to revisit eslint later--I think typescript helps us catch most of the important kinds of errors

@howardchung howardchung closed this Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants