no unused variables supporting ts overload
MODIFY
crates/rome_js_analyze/src/semantic_analyzers/js/no_unused_variables.rs
crates/rome_js_analyze/src/semantic_analyzers/js/no_unused_variables.rs
@@ -76,6 +76,15 @@ declare_rule! {
/// };
/// foo();
/// ```
+ ///
+ /// ```ts
+ /// function used_overloaded(): number;
+ /// function used_overloaded(s: string): string;
+ /// function used_overloaded(s?: string) {
+ /// return s;
+ /// }
+ /// used_overloaded();
+ /// ```
pub(crate) NoUnusedVariables {
version: "0.9.0",
name: "noUnusedVariables",
@@ -96,7 +105,8 @@ fn is_typescript_unused_ok(binding: &JsIdentifierBinding) -> Option<()> {
JsSyntaxKind::TS_METHOD_SIGNATURE_CLASS_MEMBER
| JsSyntaxKind::TS_CALL_SIGNATURE_TYPE_MEMBER
| JsSyntaxKind::TS_METHOD_SIGNATURE_TYPE_MEMBER
- | JsSyntaxKind::TS_FUNCTION_TYPE => Some(()),
+ | JsSyntaxKind::TS_FUNCTION_TYPE
+ | JsSyntaxKind::TS_DECLARE_FUNCTION_DECLARATION => Some(()),
_ => None,
}
}
@@ -115,6 +125,7 @@ fn is_typescript_unused_ok(binding: &JsIdentifierBinding) -> Option<()> {
}
}
JsSyntaxKind::TS_INDEX_SIGNATURE_PARAMETER => Some(()),
+ JsSyntaxKind::TS_DECLARE_FUNCTION_DECLARATION => Some(()),
_ => None,
}
}

MODIFY
crates/rome_js_analyze/tests/specs/js/noUnusedVariables/noUnusedVariables.ts
crates/rome_js_analyze/tests/specs/js/noUnusedVariables/noUnusedVariables.ts
@@ -7,6 +7,12 @@ class D {
}
console.log(new D());
+function unused_overloaded(): number;
+function unused_overloaded(s: string): string;
+function unused_overloaded(s?: string) {
+ return s;
+}
+
// Valid
interface A {
@@ -35,3 +41,10 @@ function f(fn: (title: string) => boolean) {
f();
export type Command = (...args: any[]) => unknown;
+
+function used_overloaded(): number;
+function used_overloaded(s: string): string;
+function used_overloaded(s?: string) {
+ return s;
+}
+used_overloaded();

MODIFY
crates/rome_js_semantic/src/tests/assertions.rs
crates/rome_js_semantic/src/tests/assertions.rs
@@ -101,11 +101,7 @@ use std::collections::{BTreeMap, HashMap};
/// if(true) ;/*NOEVENT*/;
/// ```
pub fn assert(code: &str, test_name: &str) {
- let r = rome_js_parser::parse(
- code,
- 0,
- SourceType::js_module().with_variant(rome_js_syntax::LanguageVariant::Jsx),
- );
+ let r = rome_js_parser::parse(code, 0, SourceType::tsx());
if r.has_errors() {
let files = SimpleFile::new(test_name.to_string(), code.into());

MODIFY
crates/rome_js_semantic/src/tests/references.rs
crates/rome_js_semantic/src/tests/references.rs
@@ -171,6 +171,13 @@ function f({a/*#A*/} = {a: [b/*READ B2*/,c/*READ C*/,d/*READ D*/]}, b/*#B2*/) {
console.log(a/*READ A*/, b/*READ B3*/);
}
f()",
+ ok_function_overloading,
+ "function overloaded/*#A*/(): number;
+ function overloaded/*#B*/(s: string): string;
+ function overloaded/*#C*/(s?: string) {
+ return s;
+ }
+ overloaded/*READ C*/();",
}
// Imports

MODIFY
website/src/docs/lint/rules/noUnusedVariables.md
website/src/docs/lint/rules/noUnusedVariables.md
@@ -144,3 +144,12 @@ function foo() {
foo();
```
+```ts
+function used_overloaded(): number;
+function used_overloaded(s: string): string;
+function used_overloaded(s?: string) {
+ return s;
+}
+used_overloaded();
+```
+

no unused variables supporting ts overload (#3135)