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

add eslint-disable-line to prevent restricted globals error #933

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

erinz2020
Copy link
Contributor

@erinz2020 erinz2020 commented Dec 10, 2024

This PR addresses an ESLint issue in service-worker.js by adding a directive (/* eslint-disable no-restricted-globals */) to prevent linting errors related to the use of self, which is required in the Service Worker context.

PR does not fix a numbered issue.

@erinz2020 erinz2020 self-assigned this Dec 10, 2024
@erinz2020 erinz2020 changed the title add eslint-disable line to prevent restricted globals error add eslint-disable-line to prevent restricted globals error Dec 10, 2024
Copy link
Member

@TanyaStere42 TanyaStere42 left a comment

Choose a reason for hiding this comment

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

successful build, addresses issue. need to call this out in the docs as a necessary eslint-disable

@TanyaStere42 TanyaStere42 merged commit b3ed808 into main Dec 10, 2024
1 check passed
@TanyaStere42 TanyaStere42 deleted the fix_eslint_issue_with_global_self branch December 10, 2024 20:16
@TanyaStere42 TanyaStere42 added this to the 10.5.2 milestone Dec 10, 2024
@Rodhlann
Copy link
Contributor

@erinz2020 I think I removed this in my last PR, so apologies if it caused any problems! How did the problem look, so I can be on the lookout in the future?

@TanyaStere42
Copy link
Member

the error message was something like Unexpected use of 'self' no-restricted-globals React, and it was showing up only on the serviceworker.js. Very similar to this: https://stackoverflow.com/questions/44292520/unexpected-use-of-self-no-restricted-globals-react and all the research we did found that it's a big pain in the butt and they way people are working around it is to put in the disable

@erinz2020
Copy link
Contributor Author

erinz2020 commented Dec 12, 2024

hi @Rodhlann yea I tried to add some rules to eslint.config.mjs but for some reason it didn't work, if you happen to know how to fix this please let me know, I've no idea about how this doesn't work

{
    files: ["**/service-worker.js"], 
    languageOptions: {
      globals: {
        ...globals.browser,
        serviceworker: true, 
        caches: "readonly",
        clients: "readonly",
        self: "readonly",
      },
    },
  },

Rodhlann pushed a commit to Rodhlann/Wildbook that referenced this pull request Dec 12, 2024
…_global_self

add eslint-disable-line to prevent restricted globals error
@Rodhlann
Copy link
Contributor

I think our current solution matches what the community was doing, though I'm still confused as to why it wasn't showing up for me.

I will say, it seems that the react-app-rewired package we install in frontend/maven-build.sh seems to follow its own eslint rules, and I wasn't able to figure out how to get that to use our eslint config, nor do I know if it's related to this specific problem.

@erinz2020
Copy link
Contributor Author

I think our current solution matches what the community was doing, though I'm still confused as to why it wasn't showing up for me.

I will say, it seems that the react-app-rewired package we install in frontend/maven-build.sh seems to follow its own eslint rules, and I wasn't able to figure out how to get that to use our eslint config, nor do I know if it's related to this specific problem.

Agreed! I tried to make react-app-rewired follow our eslint rule by indicating our mjs in packge.json, but it didn't work either. so... adding back that line seems the best solution for us, at least for now.

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.

3 participants