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

[ESLINT] eslint-deprecation plugin implementation (#6914) #8198

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Cedgo1997
Copy link

@Cedgo1997 Cedgo1997 commented Dec 3, 2024

Summary

This PR provides:

This PR doesn't contain:

  • Fixes to deprecated code marked inside the code with @deprecated decorator.
  • Fixes to deprecated methods or implementation that may modify the software behavior.

Implementation:

  • eslint-plugin-deprecation v2.0.0 (v3.0.0 is not compatible)
    image

  • .eslintrc.js updated with new rule and plugin added to handle deprecation warns:

image
image
image

Replaced/updated code

Replaced Deprecated Aliases:

  • toBeCalled -> toHaveBeenCalled
  • toBeCalledTimes -> toHaveBeenCalledTimes
  • toBeCalledWith -> toHaveBeenCalledWith

Replaced css style declarations:

  • clip -> clipPath
  • webkitUserSelect -> userSelect

Replaced deprecated type declarations:

  • HTMLTableHeaderCellElement -> HTMLTableCellElement

Others replacements:

  • Replaced createStore with legacy_createStore as adviced.
  • Replaced ClientRect with DomRect, ClientRect inherits from DOMRect, which is perfectly compatible, but less specific.
  • Using JSX imported from React instead of global JSX.
  • Added new ReactChild type declaration in src/components/common.js to handle ReactChild deprecation alternative (Type was extracted by original declaration from react).

image

Pending deprecate code (Recommended to open a new issue):

  • color prop from _breadcrumb_content.tsx.
  • useColorStopsState reported as deprecated.
  • The document.execCommand is reported as deprecated, however, there isn't a known alternative to it.
  • hasDragDrop from popover.tsx.
  • Goal from elastic_charts mark as deprecated by plugin but alternative may require further analysis.
  • EuiFilterSelectItem and EuiFilterSelectItemClass are reported as deprecated.
  • PlayFunctionContext from '@storybook/csf' is marked as deprecated.
  • name prop from button_group.tsx.

QA

Remove or strikethrough items that do not apply to your PR.

General checklist

  • Browser QA
    - [ ] Checked in both light and dark modes
    - [ ] Checked in mobile
    - [ ] Checked in Chrome, Safari, Edge, and Firefox
    - [ ] Checked for accessibility including keyboard-only and screenreader modes
  • Docs site QA
  • Code quality checklist
  • Release checklist
    • A changelog entry exists and is marked appropriately.
    • If applicable, added the breaking change issue label (and filled out the breaking change checklist)
  • Designer checklist
    • If applicable, file an issue to update EUI's Figma library with any corresponding UI changes. (This is an internal repo, if you are external to Elastic, ask a maintainer to submit this request)

… alternatives.

- Self declarated deprecated occurrences were not replaced.
- Hooks, components, context and sections of the code that can be potentially harmfull if changed were not replaced, but marked as pending on PR.
@Cedgo1997 Cedgo1997 requested a review from a team as a code owner December 3, 2024 00:56
Copy link

cla-checker-service bot commented Dec 3, 2024

💚 CLA has been signed

Copy link

github-actions bot commented Dec 3, 2024

👋 Since this is a community submitted pull request, a Buildkite build has not been started automatically. Would an Elastic organization member please verify the contents of this pull request and kick off a build manually?

@Cedgo1997
Copy link
Author

Hello!
I've just created this PR aiming to solve this issue (and many more). I just sign the Contributor Agreement, is there any other thing I need to do before expecting a review?
Thanks in advance!

@weronikaolejniczak
Copy link
Contributor

@Cedgo1997 thank you so much for your contribution and for signing the CLA! There is nothing that you have to do more! I'll review your PR soon 💚

@@ -12,7 +12,7 @@ import type { WrapperProps } from '@docusaurus/types';

type Props = WrapperProps<typeof MDXContentType>;

const MDXContent = (props: Props): JSX.Element => (
const MDXContent = (props: Props): React.JSX.Element => (
Copy link
Contributor

@weronikaolejniczak weronikaolejniczak Jan 27, 2025

Choose a reason for hiding this comment

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

@Cedgo1997 how about we import JSX from react as it's done in other files for consistency?

Same in:

  • packages/website/src/pages/index.tsx
  • packages/docusaurus-theme/src/theme/PaginatorNavLink/index.tsx
  • packages/docusaurus-theme/src/theme/TOCCollapsible/CollapseButton/index.tsx

@@ -63,6 +63,7 @@ export {
wcagContrastMin,
} from './color';
export type { HSV } from './color';
// eslint-disable-next-line deprecation/deprecation
Copy link
Contributor

Choose a reason for hiding this comment

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

@Cedgo1997 because we've set the rule to warn and not error, maybe we can remove this disable comment? That way, it will show up in the list and we will know to address it meaningfully?

Same in: packages/eui/src/services/color_picker/index.ts

@@ -1,4 +1,4 @@
import { applyMiddleware, createStore, compose } from 'redux';
Copy link
Contributor

Choose a reason for hiding this comment

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

@Cedgo1997 following the same logic as with the ESLint disable comments, maybe it'd be better to leave createStore warning as is to highlight the need to migrate to Redux Toolkit (that is strongly recommended by the Redux team)?

Copy link
Contributor

Choose a reason for hiding this comment

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

@Cedgo1997 the changes on this PR are purely for development purposes (code quality). They do not contain any bug fixes, functionalities. Consumers don't have to be informed about them through changelog. So we can remove this file and add to the PR skip-changelog label to unblock the CI checks.

Comment on lines +249 to +264
/**
* Replace deprecated type from React as its marked as
* not relevant by eslint deprecation plugin.
* @example
* ```ts
* export function processStringToChildren(
* input: string,
* values: RenderableValues,
* i18nMappingFunc?: (token: string) => string
* ): string | ReactChild[]
* ```
*/
export type ReactChild =
| string
| number
| ReactElement<any, string | JSXElementConstructor<any>>;
Copy link
Contributor

@weronikaolejniczak weronikaolejniczak Jan 27, 2025

Choose a reason for hiding this comment

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

@Cedgo1997 The deprecation note says:

This type is not relevant when using React. Inline the type instead to make the intent clear.

children are commonly typed as ReactNode which is a bit broader type including boolean and null but we can pass anything to children. If there are any type errors because of the change, I'd inline ReactElement | string | number in all the places where previously ReactChild has been used, as suggested by the deprecation note.

// used to preserve spaces and line breaks
textElement.style.whiteSpace = 'pre';
// do not inherit user-select (it may be `none`)
textElement.style.webkitUserSelect = 'text';
textElement.style.userSelect = 'text';
Copy link
Contributor

Choose a reason for hiding this comment

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

@Cedgo1997 userSelect is already defined below on the line 26. We can just remove the whole line.

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.

[ESLint] Add a deprecation plugin to warn on deprecated code
2 participants