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

Fixed obsessive deprecate warnings, added special util for modules and methods deprecation #313

Merged
merged 11 commits into from
Aug 20, 2015

Conversation

SwinX
Copy link
Contributor

@SwinX SwinX commented Aug 13, 2015

Resolves #303
Resolves #304
Resolves #305
Resolves #312

@SwinX SwinX self-assigned this Aug 13, 2015
@SwinX SwinX added the review label Aug 13, 2015
@SwinX
Copy link
Contributor Author

SwinX commented Aug 13, 2015

@blond посмотри пожалуйста

}
};

exports.deprecateModule = function (module, removeVer, replacement) {
Copy link
Contributor

Choose a reason for hiding this comment

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

параметры лучше передать объектом, тогда в месте использования будет намного легче читать:

deprecate({module: 'test-logger', since: 'v1.0.0', replacedWith: 'mock-enb package'});

ну и соответственно у тебя будет экспортиться одна функция, а method или module будет решаться по свойству

@blond
Copy link
Member

blond commented Aug 14, 2015

@SwinX отребейзь, пожалуйста, от мастера.

@SwinX
Copy link
Contributor Author

SwinX commented Aug 14, 2015

Ремарка себе - на винде стек нужно чистить по-другому, конструкция путей отличается.

@SwinX
Copy link
Contributor Author

SwinX commented Aug 17, 2015

Поправил замечания, добавил очередь для сообщений, которые могут появиться до инициализации модуля (пример - устаревший dir-glob. Сообщение о том, что он устарел кидается на его require и могло попадать в лог до всего остального)

/cc @blond @j0tunn

var delayedMessages = [];
var isInitialized = false;

exports.initialize = function (mustShowWarnings) {
Copy link
Member

Choose a reason for hiding this comment

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

Я бы сделал вместо аргумента опцией opts.showWarnings.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, это вообще распространенная практика - любые bool-аргументы делать опциями, тогда код читается лучше

@j0tunn
Copy link
Contributor

j0tunn commented Aug 17, 2015

@SwinX Не нужно сквошить коммиты пока идет ревью - так трудно понять что ты поправил, и приходится просматривать весь PR снова.
Пусть висят fixup-коммиты, перед вливанием сосквошишь

var module = message.module;
var since = message.since;
var replaceMethod = replaceMethod;
var replaceModule = replaceModule;
Copy link
Contributor

Choose a reason for hiding this comment

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

а это что за шаманство?

@j0tunn
Copy link
Contributor

j0tunn commented Aug 17, 2015

Предлагаю посмотреть на какие-нибудь существующие модули, например вот: https://github.com/dougwilson/nodejs-depd


if (replaceModule) {
return message + colorize.yellow(replaceModule);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

вот эти два if меняются на одну строчку:

return message + colorize.yellow(replaceMethod || replaceModule);

Copy link
Contributor

Choose a reason for hiding this comment

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

var msg = replaceMethod && replaceModule
        ? ...
        : colorize.yellow(replaceMethod || replaceModule);

return 'Please use ' + msg;

@blond
Copy link
Member

blond commented Aug 17, 2015

Предлагаю посмотреть на какие-нибудь существующие модули, например вот: https://github.com/dougwilson/nodejs-depd

@j0tunn, а смысл, если логирование нам нужно своё?

var deprecatePath = path.normalize(path.join(__dirname, '../../../lib/utils/deprecate.js'));

before(function () {
logStub = new sinon.stub(Logger.prototype, 'logWarningAction');
Copy link
Contributor

Choose a reason for hiding this comment

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

лучше запользовать sandbox и стабать сразу весь Logger.prototype:

beforeEach(function () {
    sandbox.stub(Logger.prototype);
});

afterEach(function () {
    sandbox.restore();
});

Ну и если запользовать chai.should(), то в тестах можно писать

Logger.prototype.logWarningAction.shoud.be.called;

чуть длиннее получается, зато в тесте сразу видно, что будет вызвано в коде

@SwinX
Copy link
Contributor Author

SwinX commented Aug 20, 2015

Сделал правки, переписал тесты.
/cc @blond @j0tunn

}

function buildRemoveVersionSentence(since) {
return since && since.length ?
Copy link
Contributor

Choose a reason for hiding this comment

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

зачем проверка since.length?

console.log('`dir-glob` is deprecated!!!');
console.log('It will be removed in v1.0.0!!!');
console.log('Use `glob` package!!!');
require('../utils/deprecate')({module: 'dir-glob', since: 'v1.0.0', replaceModule: 'glob'});
Copy link
Member

Choose a reason for hiding this comment

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

Лучше не экономить на переменной. По мне читается сложновато.

@SwinX
Copy link
Contributor Author

SwinX commented Aug 20, 2015

/cc @blond @j0tunn

@blond
Copy link
Member

blond commented Aug 20, 2015

👍

@j0tunn
Copy link
Contributor

j0tunn commented Aug 20, 2015

🆗

blond added a commit that referenced this pull request Aug 20, 2015
Fixed obsessive deprecate warnings, added special util for modules and methods deprecation
@blond blond merged commit 81105e8 into master Aug 20, 2015
@blond blond removed the review label Aug 20, 2015
@blond blond deleted the issue-312 branch August 20, 2015 14:31
@blond blond mentioned this pull request Aug 20, 2015
@blond blond added this to the 0.17.2 milestone Aug 20, 2015
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