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

Consider adding ESLint #2

Open
hutch120 opened this issue Apr 21, 2023 · 1 comment
Open

Consider adding ESLint #2

hutch120 opened this issue Apr 21, 2023 · 1 comment

Comments

@hutch120
Copy link

hutch120 commented Apr 21, 2023

@themaximal1st This is awesome! Let me be the first to say here, thanks for sharing.

I enjoyed reading though the code, one thing I'd highly recommend is adding ESLint. It is super easy to add and will pickup on a ton of best practices, cleaner code and obvious errors. Here are a few examples.

Here is a sample of the eslint output for the api.js file:

\InfinityArcade\src\client\api.js
    3:65  error    Expected '===' and instead saw '=='  eqeqeq
   12:3   error    Expected 'this' to be used by class async method 'fetch' class-methods-use-this
   13:5   warning  Unexpected console statement no-console
   59:12  error    Redundant use of `await` on a return value no-return-await
   76:5   error    iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations  no-restricted-syntax
   76:31  error    'yieldStreamResponse' was used before it was defined no-use-before-define
  100:20  error    Unexpected `await` inside a loop no-await-in-loop
  131:55  error    'chat_id' is not defined  no-undef

Here is how to add ESLint

Run npm init @eslint/config and pick the options. For this project I'd pick:

  • To check syntax, find problems, and enforce code style
  • CommonJS (require/exports)
  • None of these
  • No
  • Node
  • Use a popular style guide
  • AirBnB
  • Javascript

For VSCode syntax highlighting install the ESLint extension.

Add this to the package.json file then you can run npm run lint to check and fix all your files in one go.

"scripts": {
  "lint": "eslint --fix --ext .js,.jsx .",
  ...
}

If you really love some coding style, like camelcase, then you can easily adjust this in the .eslintrc.js file by adding a rule like this:

module.exports = {
  rules: {
    camelcase: 'off'
  },
  ...
};

Finally, if you want VSCode to try and fix issues when the file is saved, add this to the VSCode settings file.

{
    "editor.formatOnSave": false,
    "editor.codeActionsOnSave": {
        "source.fixAll": true
    }
}

References

@themaximalist
Copy link
Owner

Thanks I'll look into getting this added!

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

No branches or pull requests

2 participants