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

Deprecated: Output an informational message for deprecation when no version provided #16774

Merged
merged 3 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/deprecated/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Master

### Bug Fix

- When there is no `options.version` param provided `deprecated` method warns with more relaxed tone.

## 2.0.4 (2019-01-03)

## 2.0.0 (2018-09-05)
Expand Down
4 changes: 2 additions & 2 deletions packages/deprecated/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ export default function deprecated( feature, options = {} ) {
} = options;

const pluginMessage = plugin ? ` from ${ plugin }` : '';
const versionMessage = version ? `${ pluginMessage } in ${ version }` : '';
const versionMessage = version ? ` and will be removed${ pluginMessage } in version ${ version }` : '';
const useInsteadMessage = alternative ? ` Please use ${ alternative } instead.` : '';
const linkMessage = link ? ` See: ${ link }` : '';
const hintMessage = hint ? ` Note: ${ hint }` : '';
const message = `${ feature } is deprecated and will be removed${ versionMessage }.${ useInsteadMessage }${ linkMessage }${ hintMessage }`;
const message = `${ feature } is deprecated${ versionMessage }.${ useInsteadMessage }${ linkMessage }${ hintMessage }`;

// Skip if already logged.
if ( message in logged ) {
Expand Down
22 changes: 11 additions & 11 deletions packages/deprecated/src/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,61 +19,61 @@ describe( 'deprecated', () => {
deprecated( 'Eating meat' );

expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed.'
'Eating meat is deprecated.'
);
} );

it( 'should show a deprecation warning with a version', () => {
deprecated( 'Eating meat', { version: 'the future' } );
deprecated( 'Eating meat', { version: '2020.01.01' } );

expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed in the future.'
'Eating meat is deprecated and will be removed in version 2020.01.01.'
);
} );

it( 'should show a deprecation warning with an alternative', () => {
deprecated( 'Eating meat', { version: 'the future', alternative: 'vegetables' } );
deprecated( 'Eating meat', { version: '2020.01.01', alternative: 'vegetables' } );

expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed in the future. Please use vegetables instead.'
'Eating meat is deprecated and will be removed in version 2020.01.01. Please use vegetables instead.'
);
} );

it( 'should show a deprecation warning with an alternative specific to a plugin', () => {
deprecated( 'Eating meat', {
version: 'the future',
version: '2020.01.01',
alternative: 'vegetables',
plugin: 'the earth',
} );

expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed from the earth in the future. Please use vegetables instead.'
'Eating meat is deprecated and will be removed from the earth in version 2020.01.01. Please use vegetables instead.'
);
} );

it( 'should show a deprecation warning with a link', () => {
deprecated( 'Eating meat', {
version: 'the future',
version: '2020.01.01',
alternative: 'vegetables',
plugin: 'the earth',
link: 'https://en.wikipedia.org/wiki/Vegetarianism',
} );

expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed from the earth in the future. Please use vegetables instead. See: https://en.wikipedia.org/wiki/Vegetarianism'
'Eating meat is deprecated and will be removed from the earth in version 2020.01.01. Please use vegetables instead. See: https://en.wikipedia.org/wiki/Vegetarianism'
);
} );

it( 'should show a deprecation warning with a hint', () => {
deprecated( 'Eating meat', {
version: 'the future',
version: '2020.01.01',
alternative: 'vegetables',
plugin: 'the earth',
hint: 'You may find it beneficial to transition gradually.',
} );

expect( console ).toHaveWarnedWith(
'Eating meat is deprecated and will be removed from the earth in the future. Please use vegetables instead. Note: You may find it beneficial to transition gradually.'
'Eating meat is deprecated and will be removed from the earth in version 2020.01.01. Please use vegetables instead. Note: You may find it beneficial to transition gradually.'
);
} );

Expand Down