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
redefinition of Promise (W079) #1747
Comments
Hmm, that's because Promise is a built-in global now. This is a good point that we need to fix somehow. Marking as P1. |
Also, I can't see how I can switch off Promise as a built-in global. I've tried setting |
+1 I'm using |
@gabegorelick Promises are already in node unstable so I'm pretty sure they will be in node V0.12, if they ever actually release it... |
bump on this. receiving the same errors. |
Would you write this? var Array = require("my-array-implementation"); ...or pave over any other built-in object? |
Excellent point. Would you suggest rolling with some alternative then, like |
Sure, or BPromise or whatever, something that won't conflict with other code that might expect Promise to be what it is. Fact: the community wanted Promise baked into the language and that's what happened. A side effect is that the word "Promise" isn't really free for all anymore. |
@rwaldron I actually agree with you. I will just rename my references. |
Good call @rwaldron, I agree. |
Great! This is a very progressive resolution :D |
Instead of renaming my references I've found a different solution :
Works fine ! |
@rwaldron I'd disagree with |
In V8 3.28.71.2, Promise, Symbol, and harmony collections (Map/Set/WeakMap/WeakSet) are all enabled by default (with harmony-arrays and a few other features coming soon), so really it's just a matter of time before these are enabled by default unless joyent/strongloop explicitly delete those globals while bootstrapping, which seems unlikely. Promise is part of the ecosystem, but it makes sense to be able to disable es6 globals in configuration, IMO. (if you want to see how other features are coming, http://www.chromestatus.com/features#es6 is a good indicator of when it's coming to V8, and when it's pref'd on by default). For what it's worth, Mozilla isn't even hiding harmony features behind a preference, and a number of these features are enabled by default in Chrome --- so this really is a |
@caitp Not in node v0.10.x and v0.12.x isn't released yet (and probably won't be for next N months) and even when it'll come to this world, I doubt people are going to make a switch right away and I doubt even more that people are going to run in production with |
there is an es6 option, but the Promise, Symbol, Reflect, Map, Set, WeakMap and WeakSet globals are not predefined based on the presence of that flag. Maybe they should be, it's probably a pretty simple CL to put together |
@xaka I added all of the new global api names to the Ecma identifiers list and I'm not taking them out. As of 2.5.4 you may do this: /* global -Promise */
var Promise = require("promise"); Or in {
"undef": true,
"unused": true,
"predef": [ "-Promise" ]
} |
Is there any reason the following would not work on module level ? var Promise = global.Promise || require("promise"); or this on global one var Promise = Promise || require("promise"); That would free the module from concerns it should not have but in any case if a native implementation is actually broken, I don't see why we should not be able to overwrite it locally or even globally, as done before to patch engines here and there. |
Promise isn't in Node.js yet, so we have to disable it in order for the JSHint tests pass. Ref jshint/jshint#1747
A recent change to JSHint included the ECMAScript 6 global identifiers in JSHint's collection of "predefined" variables. This disallowed the definition of those global values even in contexts that did not implement them. The intent of this change was to help users avoid bugs when migrating to the new version of the language. Re-using an existing warning mechanism caused confusion among many users [1][2][3] for two reasons: 1. The generated warning messages were somewhat misleading (i.e. the warning "Redefinition of 'Promise'." is inaccurate in ES5 environments) 2. The method of disabling the warnings did not accurately communicate the intent of the developer (i.e. setting `predef: -Promise` does not prompt the user to consider the user to consider if creating their own global variable named `Promise` is appropriate) A dedicated warning message more clearly describes the best practice that motivates this particular constraint on global variable names. An explicit option makes it less likely that users will disable this warning without understanding the motivation. Intoduce a new option, `futurehostile`, and dedicated warning message to better communicate the intent of restricting usage of future-reserved identifiers. [1] jshintGH-1747 redefinition of Promise (W079) [2] jshintGH-1995 ES6 globals are activated even though esnext=false [3] jshintGH-2171 Remove Set from the ECMAScript5 reserved words
A recent change to JSHint included the ECMAScript 6 global identifiers in JSHint's collection of "predefined" variables. This disallowed the definition of those global values even in contexts that did not implement them. The intent of this change was to help users avoid bugs when migrating to the new version of the language. Re-using an existing warning mechanism caused confusion among many users [1][2][3] for two reasons: 1. The generated warning messages were somewhat misleading (i.e. the warning "Redefinition of 'Promise'." is inaccurate in ES5 environments) 2. The method of disabling the warnings did not accurately communicate the intent of the developer (i.e. setting `predef: -Promise` does not prompt the user to consider the user to consider if creating their own global variable named `Promise` is appropriate) A dedicated warning message more clearly describes the best practice that motivates this particular constraint on global variable names. An explicit option makes it less likely that users will disable this warning without understanding the motivation. Intoduce a new option, `futurehostile`, and dedicated warning message to better communicate the intent of restricting usage of future-reserved identifiers. [1] jshintGH-1747 redefinition of Promise (W079) [2] jshintGH-1995 ES6 globals are activated even though esnext=false [3] jshintGH-2171 Remove Set from the ECMAScript5 reserved words
I don't know how that's more understandable, but anyway... ;)
|
Even with Promise in v8/io.js, its deathly slow, and _unlike_
should be a warning
should not be, IMO. I've gone the globals route, ATM. |
@domenic - would love your input here. Is overriding Example: var Promise = require('bluebird'); |
This is self contradictory. |
No, it is future hostile. |
@domenic - Thanks!
Sorry for the confusion. I've updated my question for clarity. I meant, "is redefining the The examples provided by @petkaantonov in bluebird redefine the Sounds like the answer is "no". |
@domenic why future hostile? Promises were explicitly designed by spec to support alternate co-existing implementations... why not call the promise implementation being used in a particular node module Is this going to somehow confuse the v8 optimizer? I wouldn't think so. Or is it because you hope that all other promise implementations are going to die and only the one shipping in the js runtime will remain? |
For the same reason it is future hostile to overwrite |
I dunno. |
treating them as interchangeable is a good way to break the web, please don't do that u_u use one or the other, explicitly |
|
Ah, well, this is just going in circles, but any serious attempt to convince the world that all existing code that has Drawing analogies between Promise and js builtin types that have existed for decades needs a bit more backup than simply asserting they are analogous. |
There is no way for JSHint to know what runtime the code it's analyzing will run in. JSHint isn't going to break anyone's production code. If you want to pave over the Identifer bindings of built-in objects, just do it, and tell JSHint to shut up |
This is perfectly fine --- but try not to treat native implementations and third party implementations as interchangeable, unless you have good reason to be sure that the third party implementation is as spec-compliant as possible, or is at least trying to be, so that there's a bit more room for the spec to grow if it needs to without breaking applications |
That is horrible, don't do that ever |
…Promise'." error introduced in #86 jshint/jshint#1747
I've got a similar issue: "use strict";
var module = module || {
exports : {}
};
function Matchers(){
// code...
}
// code...
module.exports = Matchers; Jshint throws the error:
two questions:
|
@andrew-luhring beside the empty block within the constructor, this would pass: "use strict";
var module;
if (!module) {
module = {
exports: {}
};
}
function Matchers() {
// put something here
}
module.exports = Matchers; what's the difference? actually there's no concrete difference with what you wrote, it's just a more prolix and maybe clear way to do the same ( I would have used your version as well, give JSHint a spin ;-) ) Cheers |
I'm probably missing something, but is there a way to suppress this error? I am using
but none of them seem to override the error. The error only occurs with Update: After some futzing, I got it to work with |
Hi @joegoldbeck. While I'm glad you found a workaround that solved your
This is a safer approach, so please consider using it instead. |
Hi @jugglinmike thanks for the response! I'd much prefer to use a supported configuration. The one you suggest isn't working for me for some reason. I've stripped my .jshintrc so that it only contains those lines and I still get the W079 warning. I am using JSHint v2.9.4 on WebStorm. |
I'd like to point out that to this day, as of April 2017, the Bluebird docs still recommend this usage in Node:
and every single piece of documentation uses names like That is why I would expect everyone to follow the usage recommended in the Bluebird documentation unless it it changed to reflect the recommendation expressed here. See: http://bluebirdjs.com/docs/getting-started.html Also, it seems that Bluebird doesn't agree that redefining the |
I just switched from 2.4.4 to 2.5.1
But now all my requires are messed up because:
var Promise = require('bluebird')
Will warn about:
Redefinition of Promise (W079)
Is there anyway I can fix this ? I'm using bluebird all over the place.
The text was updated successfully, but these errors were encountered: