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

feat(packages/sui-decorators): Create @Deprecated() decorator #1785

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oriolpuig
Copy link
Contributor

Description

Frontend Tech Community has agreed to create, use, and standardize the @Deprecated() decorator. It will help us to manage the death code and monitor it to keep our code as clean as possible.

New decorator: @Deprecated()

Imagine you are refactoring a code, or disabling a functionality. How sure you are, that your code is not being used? For those cases, if you use the @Deprecated() decorator, you will be able to see a console.warn on your terminal or browser console (it's disabled on production by default).

If you want to monitor the health of your code, this decorator brings you the possibility to integrate yourself into your application and send it to your desired platform.

This decorator has 2 required parameters:

  • key: Used to enable you the possibility of monitoring and know how many times the deprecated code has been called.
  • message: Used to display the message into the terminal or browser console. It's enabled only for non-production environments.

Linting Rules

With this Pull Request, also we will add some linting rules for this decorator to help the DX and make our life easier.

The linting rules are:

  • The @Deprecated() decorator MUST be used only on Classes and Methods.
    • An ESLint error will appear.
    • A quick fix to remove it will appear.
  • The @Deprecated() decorator MUST have a key provided.
    • An ESLint error will appear
    • A quick fix to autocomplete the key will appear with the current method/class name.
  • The @Deprecated() decorator MUST have a message provided.
    • An ESLint error will appear.

Example of usage:

@Deprecated({ key: 'DummyUseCase#execute', message: 'The [DummyUseCase#execute] method is deprecated. Use the [SuperDummyUseCase#execute] instead' })
function execute() {
  if(error) {
    throw new Error('this is not ok')
  }
  return 'this is ok'
}

Related Issue

Example

Client test ✅

image

Server test ✅

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants