Giter Club home page Giter Club logo

Comments (9)

dignifiedquire avatar dignifiedquire commented on June 15, 2024

Is there a rule for this? And how would this be able to differentiate between needed use for window and false usage?

from aegir.

dryajov avatar dryajov commented on June 15, 2024

Not currently, but I was planning on writing an eslint plugin for it. As for self vs window, self should be preferred everywhere since it's a lot more portable, if window is needed explicitly the rule can be disabled on a line/file level. In general tho, it's probably safe to just check for specific features rather than for the existence of window itself. But again, being able to disable the rule should work in all remaining cases.

from aegir.

dignifiedquire avatar dignifiedquire commented on June 15, 2024

It might be a case where we want to make the rule just a warning rather than error

from aegir.

dryajov avatar dryajov commented on June 15, 2024

I kinda like the idea of ditching window for self across the board. I might be missing something but, IMHO if self is a more portable way of referencing global context then why not rely on it? I'm talking in a more general sense here, since most (all as far as I can tell) IPFS codebase has been ported to using self now.

What would be the reasoning for not preferring it over window, maybe @kumavis, @diasdavid and @haadcode can weigh in on this one. I'd also love to hear thoughts from @Gozala, @nolanlawson, @substack, @nzakas and anyone that might help shedding some light on this.

IMHO, if self is a more portable way of referencing global context in general, then we should promote it everywhere else, and I bet that lots of code could be easily made more portable by just enforcing this one thing.

To give some background, when adding support for WebWorkers in IPFS, it became apparent that self is a more portable global context reference than window, it is available in both WebWorkers/ServiceWorkers as well as in the DOM enabled environments.

Here are the related discussions/PRs:

from aegir.

platinumazure avatar platinumazure commented on June 15, 2024

Saw this come up in ESLint's Gitter chat. Maybe I'm missing something, but maybe no-restricted-globals would work for your use case? Unfortunately you can't customize the error message, but you should be able to use it to generate warnings when someone uses window.

from aegir.

dryajov avatar dryajov commented on June 15, 2024

Here is a proposal for eslint to add this as a rule - eslint/eslint#8229.

from aegir.

dryajov avatar dryajov commented on June 15, 2024

@platinumazure Thanks for bring this up! This would be a great intermediate solution, and perhaps it could be improved/customized to do what I'm proposing. However, the spirit of this rule is to make sure that this sets in as a best practice across the community, for the reasons I mentioned here and in the rule proposal, and for that a clear message suggesting the correct alternative is essential. If no-restricted-globals can be customized to provide such a message that would be ideal, but after a quick glance, it doesn't seem that that's possible.

from aegir.

daviddias avatar daviddias commented on June 15, 2024

@dryajov seems that to move this forward, an example is needed - eslint/eslint#8315 (comment)

from aegir.

victorb avatar victorb commented on June 15, 2024

eslint/eslint#8315 has been merged, and seems we're only missing a addition to our config for this to be done. PRs welcome! 🤙

from aegir.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.