From 2c2f3c475172b3cfe5aefc4e086b771a8a048e0a Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Wed, 14 May 2025 13:42:56 +0000 Subject: [PATCH] docs(linter): improve docs of default-case-last (#11031) --- .../src/rules/eslint/default_case_last.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/oxc_linter/src/rules/eslint/default_case_last.rs b/crates/oxc_linter/src/rules/eslint/default_case_last.rs index a0d430827028c..3b45ee6901f17 100644 --- a/crates/oxc_linter/src/rules/eslint/default_case_last.rs +++ b/crates/oxc_linter/src/rules/eslint/default_case_last.rs @@ -15,15 +15,20 @@ pub struct DefaultCaseLast; declare_oxc_lint!( /// ### What it does + /// /// Enforce default clauses in switch statements to be last /// /// ### Why is this bad? + /// /// A switch statement can optionally have a default clause. /// If present, it’s usually the last clause, but it doesn’t need to be. It is also allowed to put the default clause before all case clauses, or anywhere between. The behavior is mostly the same as if it was the last clause. The default block will be still executed only if there is no match in the case clauses (including those defined after the default), but there is also the ability to “fall through” from the default clause to the following clause in the list. However, such flow is not common and it would be confusing to the readers. /// Even if there is no “fall through” logic, it’s still unexpected to see the default clause before or between the case clauses. By convention, it is expected to be the last clause. /// If a switch statement should have a default clause, it’s considered a best practice to define it as the last clause. /// /// ### Example + /// + /// Examples of **incorrect** code for this rule: + /// /// ```javascript /// switch (foo) { /// default: @@ -46,6 +51,22 @@ declare_oxc_lint!( /// break; /// } /// ``` + /// + /// Examples of **correct** code for this rule: + /// + /// ```javascript + /// switch (foo) { + /// case 1: + /// bar(); + /// break; + /// case 2: + /// qux(); + /// break; + /// default: + /// baz(); + /// break; + /// } + /// ``` DefaultCaseLast, eslint, style