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

fix: ESLint config #1025

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

fix: ESLint config #1025

wants to merge 12 commits into from

Conversation

gminetoma
Copy link
Contributor

@gminetoma gminetoma commented Feb 9, 2025

Resolves #982

  • PR title follows Conventional Commits specifications
  • PR assignee has been selected
  • PR label has been selected
  • @NabbeunNabi has been selected for preliminary review

🔧 What Changed

We are now using the correct recommended TSESLint rules (tseslint.configs.eslintRecommended.rules).

Previously, we were using the wrong plugin property: tseslint.configs.recommended. This includes not only the rules but the entire recommended plugin configuration.

Added Vitest ESLint Plugin and Fixed the Following Errors:

  • Styling

    • Ran yarn lint --fix and manually fixed max-statements-per-line.
  • no-console

    • Updated this rule to only affect console.log.
    • console.warn, console.error and console.info can still be used.
    • In the future, this rule should block all console commands once a logger is added.
  • no-underscore-dangle

    • Added ESLint ignore and renamed variables.
  • no-shadow

    • Renamed conflicting variables.
  • consistent-return

    • Removed the rule due inconsistencies across the codebase.
  • no-alert

    • Added eslint-disable-next-line no-alert

Notes:

I didn't remove the require-atomic-updates warning. This needs further investigation—it may just be a false alarm.

@gminetoma gminetoma added code quality vitest Tests related to functional testing with Vitest. labels Feb 9, 2025
@gminetoma gminetoma requested a review from NabbeunNabi February 9, 2025 08:12
@gminetoma gminetoma self-assigned this Feb 9, 2025
@gminetoma gminetoma linked an issue Feb 9, 2025 that may be closed by this pull request
Copy link

netlify bot commented Feb 9, 2025

Deploy Preview for findadoc ready!

Name Link
🔨 Latest commit fbef2f0
🔍 Latest deploy log https://app.netlify.com/sites/findadoc/deploys/67aa288e6d5f50000839d949
😎 Deploy Preview https://deploy-preview-1025--findadoc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

socket-security bot commented Feb 9, 2025

No dependency changes detected. Learn more about Socket for GitHub ↗︎

👍 No dependency changes detected in pull request

@gminetoma gminetoma force-pushed the fix/eslint-config branch 2 times, most recently from e3ebf10 to b8ec835 Compare February 9, 2025 08:16
@gminetoma gminetoma marked this pull request as ready for review February 9, 2025 08:21
Copy link
Contributor

@NabbeunNabi NabbeunNabi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gminetoma Great work.

Left a few comments. A couple questions and then I will passed it off to Phil

@@ -62,7 +62,8 @@ export default withNuxt(
],
'vars-on-top': 'off',
yoda: ['error', 'never', { exceptRange: true }],
'no-console': 'error', // we should use the logger instead
// Change to a logger in the future
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to write a proposal and research what logger can be implemented. Give a few choices as to what you found and the benefits to each. You can use the template in the gitbook. @ermish does that sound good?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or @ermish do you already have one you like?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a specific one to use. It's with Grafana / Prometheus

Comment on lines +51 to +53
if (!data) {
return
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new linting rules want this styling? I like it as long as it's consistent. Also probably more readable for people learning a codebase. 😎

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't change any rules besides the no-console

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gminetoma you actually added a bunch of rules by adding the recommended ones. Many times they don't fit our codebases style and what we agreed upon. I haven't read through the rest but our two choices are either inherit from recommended then override the specific ones or stop using recommended and just list out the rules. Usually there's not that many that are needed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally for this one, I like simple returns and would like to change this rule back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ermish

My intention was to apply the correct recommended rules since ...tseslint.configs.recommended was only being applied in the rules, which was denying all the rules in the block.

I just fixed it, but if this is not what was intended, we can remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't touch this rule. It was being applied 8 months ago when ESLint was working.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't modify any styling rules. This rule comes from here:

image

image

We can override it if you approve.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add an override and use the simpler way 👍

Sorry if I wasn't clear, I meant even though you didn't add any specific rules, this PR still does enable rules that were not being linted before it.

Copy link
Contributor Author

@gminetoma gminetoma Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I make this a rule, or can we leave it up to the developer to decide? What format do you prefer?

if (condition) return
if (condition) {
 return
}

alert('Error getting data! Please contact our support team by clicking the bottom right link on the page!')
console.error('Error getting data! Please contact our support team by clicking the bottom right link on the page!')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This alert would cause a 500 on yarn dev:localserver if the backend wasn't running

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait. This was intentionally an alert because it's saying our whole site has crashed and we want to tell the user. We could replace this with a modal as an alternative, but console won't work here.

We also have a console error in the line before to give more dev details which this is now duplicating

stores/localeStore.ts Outdated Show resolved Hide resolved
stores/moderationSubmissionsStore.ts Outdated Show resolved Hide resolved
utils/handleScroll.ts Show resolved Hide resolved
eslint.config.js Outdated Show resolved Hide resolved
Copy link
Contributor

@NabbeunNabi NabbeunNabi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ermish On to you. I tagged you in a couple of my comments

@NabbeunNabi
Copy link
Contributor

@ermish On to you. I tagged you in a couple of my comments

Actually I'm going to use my judgment to say I want to have return there but not have to explicitly say I defined. So not yet to you

Copy link
Contributor

@NabbeunNabi NabbeunNabi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I changed my mind. Sorry to do that. Could you see if it is possible to update the config to not require explicitly stating undefined. I am fine with there being a return. But adding undefined seems extra, like a semicolon and we don't use those

Copy link
Contributor

@NabbeunNabi NabbeunNabi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok @ermish now it is all yours

Copy link
Contributor

@ermish ermish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Human linting of the PR complete!

eslint.config.js Outdated
},
settings: {
vitest: {
typecheck: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want this feature turned on. It's going to run tsc which would duplicate the typescript Linting and slow things down.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature is for Vitest if type checking is enabled in its config.
Since it's not, I'll remove it.

https://github.com/vitest-dev/eslint-plugin-vitest?tab=readme-ov-file#enabling-with-type-testing
https://vitest.dev/guide/testing-types

import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'

// Convert import.meta.url to __dirname equivalent
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const fileName = fileURLToPath(import.meta.url)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are reserved names and should be kept.

Copy link
Contributor Author

@gminetoma gminetoma Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I keep it or remove it? These names are not available in ES modules.

We have rules that block the usage of "_" for variable naming.
Even if we were running a .cjs script, we shouldn't modify them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're well known names in the JavaScript/node space. The linting is from new rules added in this PR that are throwing the error so we should just override the rule.
I think the rule can be ok if it allows exceptions for any other reserved words/special cases

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this file to the ignore list since it doesn't follow a bunch of our rules.
I also reverted all its changes.

i18n/checkLocaleKeys.js Outdated Show resolved Hide resolved
i18n/checkLocaleKeys.js Outdated Show resolved Hide resolved
i18n/checkLocaleKeys.js Outdated Show resolved Hide resolved
@@ -100,7 +100,7 @@ async function queryProfessionals(searchSpecialty?: Specialty, searchLanguage?:
return professionalsSearchResult
} catch (error) {
console.error(`Error getting professionals: ${JSON.stringify(error)}`)
alert('Error getting data! Please contact our support team by clicking the bottom right link on the page!')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also should keep this one

Copy link
Contributor Author

@gminetoma gminetoma Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm bringing the alerts back. Should I remove the rule or ignore them per line?

Copy link
Contributor

@ermish ermish Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Probably ignore on the lines. We don't want to accidentally check in any other alerts and realistically the ONLY time you should use an alert is when everything is failing

@@ -135,7 +135,7 @@ async function queryFacilities(healthcareProfessionalIds: string[], searchCity?:
return locationFilteredSearchResults
} catch (error) {
console.error(`Error getting facilities: ${JSON.stringify(error)}`)
alert('Error getting data! Please contact our support team by clicking the bottom right link on the page!')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NabbeunNabi We can make a separate issue for moving these alerts to nicer user modal messages

utils/formValidations.ts Show resolved Hide resolved
utils/handleScroll.ts Show resolved Hide resolved
@@ -13,7 +13,7 @@ export function handleServerErrorMessaging(
}
toast.error((t('serverErrorMessages.genericErrorMessage')))
console.error((t('serverErrorMessages.genericErrorMessage')))
console.info(t('serverErrorMessages.errorCodeMessagingNeeded'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this one should be info since we already have the error right before it

The `consistent-return` rule causes inconsistencies across the codebase.
It requires returning values like `return undefined`, which is unnecessary.
Renamed `l` and `o` to `currentLocale`
Some lines are supposed to work this way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality vitest Tests related to functional testing with Vitest.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix: eslint.config.js
3 participants