Skip to content

Commit

Permalink
add help message
Browse files Browse the repository at this point in the history
  • Loading branch information
baseballyama committed Dec 29, 2024
1 parent 1297d3a commit a1dfdf6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/oxc_linter/src/rules/eslint/vars_on_top.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{context::LintContext, rule::Rule, AstNode};

fn vars_on_top_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("All 'var' declarations must be at the top of the function scope.")
.with_help("Consider moving this to the top of the functions scope or using let or const to declare this variable.")
.with_label(span)
}

Expand Down
27 changes: 27 additions & 0 deletions crates/oxc_linter/src/snapshots/eslint_vars_on_top.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ snapshot_kind: text
6var second = 0;
· ───────────────
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:7:7]
Expand All @@ -16,6 +17,7 @@ snapshot_kind: text
· ───────────────
8second = 2;
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:4:11]
Expand All @@ -24,6 +26,7 @@ snapshot_kind: text
· ──────────────────
5 │ }
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:2:12]
Expand All @@ -32,6 +35,7 @@ snapshot_kind: text
· ─────────
3alert(i);
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:5:11]
Expand All @@ -40,6 +44,7 @@ snapshot_kind: text
· ───────────────
6 │ }
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:6:15]
Expand All @@ -48,6 +53,7 @@ snapshot_kind: text
· ──────────────
7break;
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:5:11]
Expand All @@ -56,6 +62,7 @@ snapshot_kind: text
· ──────────────
6 │ } catch (e) {
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:7:11]
Expand All @@ -64,6 +71,7 @@ snapshot_kind: text
· ──────────────
8 │ }
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:4:11]
Expand All @@ -72,6 +80,7 @@ snapshot_kind: text
· ──────────────
5 │ }
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:4:11]
Expand All @@ -80,6 +89,7 @@ snapshot_kind: text
· ──────────────
5 │ } while (first == 10);
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:3:12]
Expand All @@ -88,6 +98,7 @@ snapshot_kind: text
· ────────
4item++;
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:5:11]
Expand All @@ -96,6 +107,7 @@ snapshot_kind: text
· ─────────────────
6 │ }
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:5:11]
Expand All @@ -104,65 +116,75 @@ snapshot_kind: text
· ─────────────────
6 │ }
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:1:18]
1 │ 'use strict'; 0; var x; f();
· ──────
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:1:35]
1 │ 'use strict'; var x; 'directive'; var y; f();
· ──────
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:1:33]
1 │ function f() { 'use strict'; 0; var x; f(); }
· ──────
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:1:51]
1 │ function f() { 'use strict'; var x; 'directive'; var y; f(); }
· ──────
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:2:4]
1 │ export function f() {}
2var x;
· ──────
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:3:4]
2 │ export function f() {}
3var y;
· ──────
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:3:4]
2 │ export {foo};
3var test = 1;
· ─────────────
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:2:4]
1 │ export {foo} from 'foo';
2var test = 1;
· ─────────────
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:2:4]
1 │ export * from 'foo';
2var test = 1;
· ─────────────
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:4:12]
Expand All @@ -171,6 +193,7 @@ snapshot_kind: text
· ──────
5 │ }
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:4:12]
Expand All @@ -179,6 +202,7 @@ snapshot_kind: text
· ──────
5 │ }
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:5:12]
Expand All @@ -187,6 +211,7 @@ snapshot_kind: text
· ──────
6 │ }
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:4:16]
Expand All @@ -195,6 +220,7 @@ snapshot_kind: text
· ──────
5 │ }
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

eslint(vars-on-top): All 'var' declarations must be at the top of the function scope.
╭─[vars_on_top.tsx:4:16]
Expand All @@ -203,3 +229,4 @@ snapshot_kind: text
· ──────
5 │ }
╰────
help: Consider moving this to the top of the functions scope or using let or const to declare this variable.

0 comments on commit a1dfdf6

Please sign in to comment.