SUI-Components / sui

Monorepo for SUI (Simple User Interface) packages.
169 stars 33 forks source link

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

Closed oriolpuig closed 1 month ago

oriolpuig commented 2 months ago

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:

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:

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'
}

Example of visualisation on your Browser Console

image

Example

Client test ✅

image

Server test ✅

image