Skip to content

Commit 4170b9d

Browse files
committed
improve
1 parent 3a1f473 commit 4170b9d

File tree

7 files changed

+57
-3
lines changed

7 files changed

+57
-3
lines changed

docs/rules/no-unused-props.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ Note: Properties of class types are not checked for usage, as they might be used
167167
}
168168
```
169169

170-
- `checkImportedTypes` ... Controls whether to check properties from imported types. Default is `false`.
171-
- `ignoreTypePatterns` ... Patterns to ignore when checking property types. Default is `[]` (no types are ignored by default). This option can be used to exclude certain types from being checked for unused properties, which is useful for utility or internal types.
172-
- `ignorePropertyPatterns` ... Patterns to ignore when checking for unused props. Default is `[]` (no properties are ignored by default). This option can be used to ignore properties starting with special characters often used for internal or framework-specific identifiers.
170+
- `checkImportedTypes` ... Controls whether to check properties from types defined in external files. Default is `false`, meaning the rule only checks types defined within the component file itself. When set to `true`, the rule will also check properties from imported and extended types.
171+
- `ignoreTypePatterns` ... Regular expression patterns for type names to exclude from checks. Default is `[]` (no exclusions). Most useful when `checkImportedTypes` is `true`, allowing you to exclude specific imported types (like utility types or third-party types) from being checked.
172+
- `ignorePropertyPatterns` ... Regular expression patterns for property names to exclude from unused checks. Default is `[]` (no exclusions). Most useful when `checkImportedTypes` is `true`, allowing you to ignore specific properties from external types that shouldn't trigger warnings.
173173

174174
Examples:
175175

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"options": [
3+
{
4+
"checkImportedTypes": true,
5+
"ignoreTypePatterns": ["BaseProps"],
6+
"ignorePropertyPatterns": ["/^(_|baz)/"]
7+
}
8+
]
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- message: "'base' is an unused Props property."
2+
line: 10
3+
column: 6
4+
suggestions: null
5+
- message: "'bar' in 'my_foo' is an unused property."
6+
line: 10
7+
column: 6
8+
suggestions: null
9+
- message: "'qux' is an unused Props property."
10+
line: 10
11+
column: 6
12+
suggestions: null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script lang="ts">
2+
import type { BaseProps, FooDTO } from './shared-types';
3+
interface Props {
4+
base: BaseProps;
5+
my_foo: FooDTO;
6+
_my_bar: string;
7+
baz: string;
8+
qux: string;
9+
}
10+
let { my_foo }: Props = $props();
11+
console.log(my_foo.foo);
12+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"options": [
3+
{
4+
"checkImportedTypes": true,
5+
"ignoreTypePatterns": ["BaseProps"],
6+
"ignorePropertyPatterns": ["/^(_|baz)/"]
7+
}
8+
]
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script lang="ts">
2+
import type { BaseProps, FooDTO } from './shared-types';
3+
interface Props {
4+
base: BaseProps;
5+
my_foo: FooDTO;
6+
_my_bar: string;
7+
baz: string;
8+
}
9+
let { base, my_foo }: Props = $props();
10+
console.log(base.age, my_foo.foo, my_foo.bar);
11+
</script>

packages/eslint-plugin-svelte/tests/fixtures/rules/no-unused-props/valid/shared-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export interface BaseProps {
22
name: string;
3+
age: number;
34
}
45

56
export interface FooDTO {

0 commit comments

Comments
 (0)