Comparing version 1.4.0 to 1.5.0
20
index.js
@@ -36,3 +36,3 @@ 'use strict'; | ||
var location; | ||
var getCallToDeprecate; | ||
var locationIndex; | ||
var args = arguments; | ||
@@ -49,11 +49,13 @@ | ||
// Default to the location of the call to the deprecated function | ||
locationIndex = options.locationIndex == null ? 1 : options.locationIndex; | ||
// When the user sets location to false, | ||
// We will use the location of the call to complain() | ||
// To limit the log to only occurring once | ||
if(options.location === false) { | ||
// When the user explictly sets location to false, | ||
// We will get the location of the call to complain() | ||
// is called, instead of the location of the call to the | ||
// deprecated function. | ||
getCallToDeprecate = true; | ||
locationIndex = 0; | ||
} | ||
location = options.location || getLocation(getCallToDeprecate); | ||
location = options.location || getLocation(locationIndex); | ||
@@ -125,5 +127,5 @@ var moduleName = complain.getModuleName(location); | ||
function getLocation(getCallToDeprecate) { | ||
function getLocation(locationIndex) { | ||
var location = ''; | ||
var targetIndex = getCallToDeprecate ? 2 : 3; | ||
var targetIndex = locationIndex + 2; | ||
@@ -130,0 +132,0 @@ /** |
{ | ||
"name": "complain", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Mark methods as deprecated and warn the user when they're called", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -35,2 +35,3 @@ # complain | ||
**`location`**: a string in the format `${filepath}:${line}:${column}` indicating where the deprecated function was called from. Setting this to `false` disables outputting the location and will only log the message once. | ||
**`locationIndex`**: a number indicating the distance (in stack frames) from the call to complain to use as the deprecated location. 0 is the call to complain. By default, it is 1, which is typically the call to the deprecated function. | ||
@@ -37,0 +38,0 @@ ### complain.method() |
@@ -46,2 +46,18 @@ var assert = require('assert'); | ||
it('prints the correct custom location', function() { | ||
function api() { | ||
internal(); | ||
} | ||
function internal() { | ||
complain("test", { locationIndex:2 }) | ||
} | ||
api(); | ||
// IF THIS TEST IS FAILING, CHECK THAT THE LINE MATCHES THE api() CALL ABOVE! | ||
var text = output._text.join(' '); | ||
assert(text.indexOf('test/development.js:55:5') > 0, 'should have api location'); | ||
}); | ||
it('does nothing if silence is turned on', function() { | ||
@@ -48,0 +64,0 @@ complain.silence = true; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23574
333
118