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
12 changes: 6 additions & 6 deletions crates/oxc_linter/src/rules/eslint/valid_typeof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ use crate::{

fn not_string(help: Option<&'static str>, span: Span) -> OxcDiagnostic {
let mut d =
OxcDiagnostic::warn("Typeof comparisons should be to string literals.").with_label(span);
OxcDiagnostic::warn("`typeof` comparisons should be to string literals.").with_label(span);
if let Some(x) = help {
d = d.with_help(x);
}
d
}

fn invalid_value(help: Option<&'static str>, span: Span) -> OxcDiagnostic {
let mut d = OxcDiagnostic::warn("Invalid typeof comparison value.").with_label(span);
let mut d = OxcDiagnostic::warn("Invalid `typeof` comparison value.").with_label(span);
if let Some(x) = help {
d = d.with_help(x);
}
Expand Down Expand Up @@ -93,6 +93,10 @@ declare_oxc_lint!(
);

impl Rule for ValidTypeof {
fn from_configuration(value: serde_json::Value) -> Result<Self, serde_json::error::Error> {
serde_json::from_value::<DefaultRuleConfig<Self>>(value).map(DefaultRuleConfig::into_inner)
}

fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
// match on `typeof` unary expression for better performance
let _unary_expr = match node.kind() {
Expand Down Expand Up @@ -157,10 +161,6 @@ impl Rule for ValidTypeof {
ctx.diagnostic(not_string(None, sibling.span()));
}
}

fn from_configuration(value: serde_json::Value) -> Result<Self, serde_json::error::Error> {
serde_json::from_value::<DefaultRuleConfig<Self>>(value).map(DefaultRuleConfig::into_inner)
}
}

const VALID_TYPES: [&str; 8] =
Expand Down
42 changes: 21 additions & 21 deletions crates/oxc_linter/src/snapshots/eslint_valid_typeof.snap
Original file line number Diff line number Diff line change
@@ -1,131 +1,131 @@
---
source: crates/oxc_linter/src/tester.rs
---
⚠ eslint(valid-typeof): Invalid typeof comparison value.
⚠ eslint(valid-typeof): Invalid `typeof` comparison value.
╭─[valid_typeof.tsx:1:16]
1 │ typeof foo === 'strnig'
· ────────
╰────

⚠ eslint(valid-typeof): Invalid typeof comparison value.
⚠ eslint(valid-typeof): Invalid `typeof` comparison value.
╭─[valid_typeof.tsx:1:1]
1 │ 'strnig' === typeof foo
· ────────
╰────

⚠ eslint(valid-typeof): Invalid typeof comparison value.
⚠ eslint(valid-typeof): Invalid `typeof` comparison value.
╭─[valid_typeof.tsx:1:20]
1 │ if (typeof bar === 'umdefined') {}
· ───────────
╰────

⚠ eslint(valid-typeof): Invalid typeof comparison value.
⚠ eslint(valid-typeof): Invalid `typeof` comparison value.
╭─[valid_typeof.tsx:1:16]
1 │ typeof foo !== 'strnig'
· ────────
╰────

⚠ eslint(valid-typeof): Invalid typeof comparison value.
⚠ eslint(valid-typeof): Invalid `typeof` comparison value.
╭─[valid_typeof.tsx:1:1]
1 │ 'strnig' !== typeof foo
· ────────
╰────

⚠ eslint(valid-typeof): Invalid typeof comparison value.
⚠ eslint(valid-typeof): Invalid `typeof` comparison value.
╭─[valid_typeof.tsx:1:20]
1 │ if (typeof bar !== 'umdefined') {}
· ───────────
╰────

⚠ eslint(valid-typeof): Invalid typeof comparison value.
⚠ eslint(valid-typeof): Invalid `typeof` comparison value.
╭─[valid_typeof.tsx:1:15]
1 │ typeof foo != 'strnig'
· ────────
╰────

⚠ eslint(valid-typeof): Invalid typeof comparison value.
⚠ eslint(valid-typeof): Invalid `typeof` comparison value.
╭─[valid_typeof.tsx:1:1]
1 │ 'strnig' != typeof foo
· ────────
╰────

⚠ eslint(valid-typeof): Invalid typeof comparison value.
⚠ eslint(valid-typeof): Invalid `typeof` comparison value.
╭─[valid_typeof.tsx:1:19]
1 │ if (typeof bar != 'umdefined') {}
· ───────────
╰────

⚠ eslint(valid-typeof): Invalid typeof comparison value.
⚠ eslint(valid-typeof): Invalid `typeof` comparison value.
╭─[valid_typeof.tsx:1:15]
1 │ typeof foo == 'strnig'
· ────────
╰────

⚠ eslint(valid-typeof): Invalid typeof comparison value.
⚠ eslint(valid-typeof): Invalid `typeof` comparison value.
╭─[valid_typeof.tsx:1:1]
1 │ 'strnig' == typeof foo
· ────────
╰────

⚠ eslint(valid-typeof): Invalid typeof comparison value.
⚠ eslint(valid-typeof): Invalid `typeof` comparison value.
╭─[valid_typeof.tsx:1:19]
1 │ if (typeof bar == 'umdefined') {}
· ───────────
╰────

⚠ eslint(valid-typeof): Invalid typeof comparison value.
⚠ eslint(valid-typeof): Invalid `typeof` comparison value.
╭─[valid_typeof.tsx:1:20]
1 │ if (typeof bar === `umdefined`) {}
· ───────────
╰────

⚠ eslint(valid-typeof): Invalid typeof comparison value.
⚠ eslint(valid-typeof): Invalid `typeof` comparison value.
╭─[valid_typeof.tsx:1:15]
1 │ typeof foo == 'invalid string'
· ────────────────
╰────

⚠ eslint(valid-typeof): Invalid typeof comparison value.
⚠ eslint(valid-typeof): Invalid `typeof` comparison value.
╭─[valid_typeof.tsx:1:20]
1 │ if (typeof bar !== undefined) {}
· ─────────
╰────
help: Use `"undefined"` instead of `undefined`.

⚠ eslint(valid-typeof): Typeof comparisons should be to string literals.
⚠ eslint(valid-typeof): `typeof` comparisons should be to string literals.
╭─[valid_typeof.tsx:1:15]
1 │ typeof foo == Object
· ──────
╰────

⚠ eslint(valid-typeof): Typeof comparisons should be to string literals.
⚠ eslint(valid-typeof): `typeof` comparisons should be to string literals.
╭─[valid_typeof.tsx:1:16]
1 │ typeof foo === undefined
· ─────────
╰────
help: Use `"undefined"` instead of `undefined`.

⚠ eslint(valid-typeof): Typeof comparisons should be to string literals.
⚠ eslint(valid-typeof): `typeof` comparisons should be to string literals.
╭─[valid_typeof.tsx:1:1]
1 │ undefined === typeof foo
· ─────────
╰────
help: Use `"undefined"` instead of `undefined`.

⚠ eslint(valid-typeof): Typeof comparisons should be to string literals.
⚠ eslint(valid-typeof): `typeof` comparisons should be to string literals.
╭─[valid_typeof.tsx:1:1]
1 │ undefined == typeof foo
· ─────────
╰────
help: Use `"undefined"` instead of `undefined`.

⚠ eslint(valid-typeof): Typeof comparisons should be to string literals.
⚠ eslint(valid-typeof): `typeof` comparisons should be to string literals.
╭─[valid_typeof.tsx:1:16]
1 │ typeof foo === `undefined${foo}`
· ─────────────────
╰────

⚠ eslint(valid-typeof): Typeof comparisons should be to string literals.
⚠ eslint(valid-typeof): `typeof` comparisons should be to string literals.
╭─[valid_typeof.tsx:1:16]
1 │ typeof foo === `${string}`
· ───────────
Expand Down
Loading