Skip to content
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
23 changes: 18 additions & 5 deletions crates/oxc_linter/src/rules/react/no_is_mounted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::{
};

fn no_is_mounted_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Do not use isMounted")
.with_help("isMounted is on its way to being officially deprecated. You can use a _isMounted property to track the mounted status yourself.")
OxcDiagnostic::warn("Do not use `isMounted`")
.with_help("`isMounted` is on its way to being officially deprecated. You can use an `_isMounted` property to track the mounted status yourself.")
.with_label(span)
}

Expand All @@ -21,16 +21,17 @@ pub struct NoIsMounted;
declare_oxc_lint!(
/// ### What it does
///
/// This rule prevents using isMounted in classes
/// This rule prevents using `isMounted` in classes.
///
/// ### Why is this bad?
///
/// isMounted is an anti-pattern, is not available when using classes,
/// and it is on its way to being officially deprecated.///
/// `isMounted` is an anti-pattern, is not available when using classes,
/// and it is on its way to being officially deprecated.
///
/// ### Examples
///
/// Examples of **incorrect** code for this rule:
///
/// ```jsx
/// class Hello extends React.Component {
/// someMethod() {
Expand Down Expand Up @@ -102,6 +103,18 @@ fn test() {
",
None,
),
(
"
class Hello extends React.Component {
notIsMounted() {}
render() {
this.notIsMounted();
return <div>Hello</div>;
}
};
",
None,
),
];

let fail = vec![
Expand Down
12 changes: 6 additions & 6 deletions crates/oxc_linter/src/snapshots/react_no_is_mounted.snap
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
---
source: crates/oxc_linter/src/tester.rs
---
⚠ eslint-plugin-react(no-is-mounted): Do not use isMounted
⚠ eslint-plugin-react(no-is-mounted): Do not use `isMounted`
╭─[no_is_mounted.tsx:4:24]
3 │ componentDidUpdate: function() {
4 │ if (!this.isMounted()) {
· ────────────────
5 │ return;
╰────
help: isMounted is on its way to being officially deprecated. You can use a _isMounted property to track the mounted status yourself.
help: `isMounted` is on its way to being officially deprecated. You can use an `_isMounted` property to track the mounted status yourself.

⚠ eslint-plugin-react(no-is-mounted): Do not use isMounted
⚠ eslint-plugin-react(no-is-mounted): Do not use `isMounted`
╭─[no_is_mounted.tsx:4:24]
3 │ someMethod: function() {
4 │ if (!this.isMounted()) {
· ────────────────
5 │ return;
╰────
help: isMounted is on its way to being officially deprecated. You can use a _isMounted property to track the mounted status yourself.
help: `isMounted` is on its way to being officially deprecated. You can use an `_isMounted` property to track the mounted status yourself.

⚠ eslint-plugin-react(no-is-mounted): Do not use isMounted
⚠ eslint-plugin-react(no-is-mounted): Do not use `isMounted`
╭─[no_is_mounted.tsx:4:24]
3 │ someMethod() {
4 │ if (!this.isMounted()) {
· ────────────────
5 │ return;
╰────
help: isMounted is on its way to being officially deprecated. You can use a _isMounted property to track the mounted status yourself.
help: `isMounted` is on its way to being officially deprecated. You can use an `_isMounted` property to track the mounted status yourself.
Loading