Comparing version 0.8.0 to 0.9.0
(function() { | ||
var Emitter, grim, _; | ||
var Deprecation, Emitter, grim, _; | ||
@@ -8,27 +8,24 @@ _ = require('underscore-plus'); | ||
global.__grimlog__ = {}; | ||
Deprecation = require('./deprecation'); | ||
global.__grimDeprecations__ = []; | ||
grim = { | ||
getLog: function() { | ||
return global.__grimlog__; | ||
getDeprecations: function() { | ||
return _.clone(global.__grimDeprecations__); | ||
}, | ||
clearLog: function() { | ||
return global.__grimlog__ = {}; | ||
clearDeprecations: function() { | ||
return global.__grimDeprecations__ = []; | ||
}, | ||
logDeprecationWarnings: function() { | ||
var metadata, method, warnings, _i, _len, _ref, _ref1, _results; | ||
warnings = []; | ||
_ref = grim.getLog(); | ||
for (method in _ref) { | ||
metadata = _ref[method]; | ||
warnings.push([method, metadata]); | ||
} | ||
warnings.sort(function(a, b) { | ||
return b[1].count - a[1].count; | ||
logDeprecations: function() { | ||
var deprecation, deprecations, _i, _len, _results; | ||
deprecations = grim.getDeprecations(); | ||
deprecations.sort(function(a, b) { | ||
return b.getCallCount() - a.getCallCount(); | ||
}); | ||
console.warn("\nCalls to deprecated functions\n-----------------------------"); | ||
_results = []; | ||
for (_i = 0, _len = warnings.length; _i < _len; _i++) { | ||
_ref1 = warnings[_i], method = _ref1[0], metadata = _ref1[1]; | ||
_results.push(console.warn("(" + metadata.count + ") " + method + " : " + metadata.message, metadata)); | ||
for (_i = 0, _len = deprecations.length; _i < _len; _i++) { | ||
deprecation = deprecations[_i]; | ||
_results.push(console.warn("(" + (deprecation.getCallCount()) + ") " + (deprecation.getOriginName()) + " : " + (deprecation.getMessage()), deprecation)); | ||
} | ||
@@ -38,29 +35,12 @@ return _results; | ||
deprecate: function(message) { | ||
var all, count, e, metadata, method, stackLines, trace, x, _base, _ref; | ||
try { | ||
throw new Error("Deprecated Method"); | ||
} catch (_error) { | ||
e = _error; | ||
stackLines = e.stack.split("\n"); | ||
_ref = stackLines[2].match(/^\s*at\s*(\S+)/), all = _ref[0], method = _ref[1]; | ||
var deprecation, methodName, stack; | ||
stack = Deprecation.generateStack().slice(1); | ||
methodName = Deprecation.getFunctionNameFromCallsite(stack[0]); | ||
if (!(deprecation = global.__grimDeprecations__.find(function(d) { | ||
return d.getOriginName() === methodName; | ||
}))) { | ||
deprecation = new Deprecation(message); | ||
global.__grimDeprecations__.push(deprecation); | ||
} | ||
metadata = (_base = grim.getLog())[method] != null ? _base[method] : _base[method] = { | ||
message: message, | ||
count: 0, | ||
stackTraces: [] | ||
}; | ||
metadata.count++; | ||
x = _.find(metadata.stackTraces, function(_arg) { | ||
var count, trace; | ||
trace = _arg[0], count = _arg[1]; | ||
return trace === e.stack; | ||
}); | ||
if (x) { | ||
trace = x[0], count = x[1]; | ||
} | ||
if (trace == null) { | ||
trace = e.stack; | ||
count = 0; | ||
} | ||
metadata.stackTraces.push([trace, count++]); | ||
deprecation.addStack(stack); | ||
return grim.emit("updated"); | ||
@@ -67,0 +47,0 @@ } |
{ | ||
"name": "grim", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"description": "Log usage of deprecated methods", | ||
@@ -5,0 +5,0 @@ "main": "./lib/grim", |
@@ -1,3 +0,3 @@ | ||
# grim | ||
# Grim [![Build Status](https://magnum.travis-ci.com/atom/grim.svg?token=wKV9hrS79m2qMyqpNvUo&branch=master)](https://travis-ci.org/atom/grim) | ||
Log usage of deprecated methods |
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
7566
5
150