Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(require-template, check-template-names): add support for more template checks #1276

Merged
merged 3 commits into from
Jul 30, 2024
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
3 changes: 2 additions & 1 deletion .README/rules/check-template-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Checks that any `@template` names are actually used in the connected
`@typedef` or type alias.

Currently checks `TSTypeAliasDeclaration` such as:
Currently checks `ClassDeclaration`, `FunctionDeclaration`,
`TSInterfaceDeclaration` or `TSTypeAliasDeclaration` such as:

```ts
/**
Expand Down
3 changes: 2 additions & 1 deletion .README/rules/require-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
Checks to see that `@template` tags are present for any detected type
parameters.

Currently checks `TSTypeAliasDeclaration` such as:
Currently checks `ClassDeclaration`, `FunctionDeclaration`,
`TSInterfaceDeclaration` or `TSTypeAliasDeclaration` such as:

```ts
export type Pairs<D, V> = [D, V | undefined];
Expand Down
171 changes: 170 additions & 1 deletion docs/rules/check-template-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
Checks that any `@template` names are actually used in the connected
`@typedef` or type alias.

Currently checks `TSTypeAliasDeclaration` such as:
Currently checks `ClassDeclaration`, `FunctionDeclaration`,
`TSInterfaceDeclaration` or `TSTypeAliasDeclaration` such as:

```ts
/**
Expand Down Expand Up @@ -95,6 +96,100 @@ export type Extras<D, U> = [D, U | undefined];
* @property {V} foo
*/
// Message: @template D not in use

/**
* @template D
* @template V
*/
interface GenericIdentityFn<Type> {
(arg: Type): Type;
}
// Message: @template D not in use

/**
* @template D
* @template V
*/
export interface GenericIdentityFn<Type> {
(arg: Type): Type;
}
// Message: @template D not in use

/**
* @template D
* @template V
*/
export default interface GenericIdentityFn<Type> {
(arg: Type): Type;
}
// Message: @template D not in use

/**
* @template D
* @template V
*/
function identity<Type>(arg: Type): Type {
return arg;
}
// Message: @template D not in use

/**
* @template D
* @template V
*/
export function identity<Type>(arg: Type): Type {
return arg;
}
// Message: @template D not in use

/**
* @template D
* @template V
*/
export default function identity<Type>(arg: Type): Type {
return arg;
}
// Message: @template D not in use

/**
* @template D
* @template V
*/
class GenericNumber<NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}
// Message: @template D not in use

/**
* @template D
* @template V
*/
export class GenericNumber<NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}
// Message: @template D not in use

/**
* @template D
* @template V
*/
export default class GenericNumber<NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}
// Message: @template D not in use

/**
* @template D
* @template V
*/
export default class <NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}
// Message: @template D not in use
````


Expand Down Expand Up @@ -146,5 +241,79 @@ export type Extras<D, U, V> = [D, U, V | undefined];
* @property {D} foo
* @property {V} bar
*/

/**
* @template Type
*/
interface GenericIdentityFn<Type> {
(arg: Type): Type;
}

/**
* @template Type
*/
export interface GenericIdentityFn<Type> {
(arg: Type): Type;
}

/**
* @template Type
*/
export default interface GenericIdentityFn<Type> {
(arg: Type): Type;
}

/**
* @template Type
*/
function identity<Type>(arg: Type): Type {
return arg;
}

/**
* @template Type
*/
export function identity<Type>(arg: Type): Type {
return arg;
}

/**
* @template Type
*/
export default function identity<Type>(arg: Type): Type {
return arg;
}

/**
* @template NumType
*/
class GenericNumber<NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}

/**
* @template NumType
*/
export class GenericNumber<NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}

/**
* @template NumType
*/
export default class GenericNumber<NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}

/**
* @template NumType
*/
export default class <NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}
````

161 changes: 160 additions & 1 deletion docs/rules/require-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
Checks to see that `@template` tags are present for any detected type
parameters.

Currently checks `TSTypeAliasDeclaration` such as:
Currently checks `ClassDeclaration`, `FunctionDeclaration`,
`TSInterfaceDeclaration` or `TSTypeAliasDeclaration` such as:

```ts
export type Pairs<D, V> = [D, V | undefined];
Expand Down Expand Up @@ -114,6 +115,90 @@ export type Pairs<D, V> = [D, V | undefined];
* @property {X} bar
*/
// Message: Missing @template D

/**
*
*/
interface GenericIdentityFn<Type> {
(arg: Type): Type;
}
// Message: Missing @template Type

/**
*
*/
export interface GenericIdentityFn<Type> {
(arg: Type): Type;
}
// Message: Missing @template Type

/**
*
*/
export default interface GenericIdentityFn<Type> {
(arg: Type): Type;
}
// Message: Missing @template Type

/**
*
*/
function identity<Type>(arg: Type): Type {
return arg;
}
// Message: Missing @template Type

/**
*
*/
export function identity<Type>(arg: Type): Type {
return arg;
}
// Message: Missing @template Type

/**
*
*/
export default function identity<Type>(arg: Type): Type {
return arg;
}
// Message: Missing @template Type

/**
*
*/
class GenericNumber<NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}
// Message: Missing @template NumType

/**
*
*/
export class GenericNumber<NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}
// Message: Missing @template NumType

/**
*
*/
export default class GenericNumber<NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}
// Message: Missing @template NumType

/**
*
*/
export default class <NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}
// Message: Missing @template NumType
````


Expand Down Expand Up @@ -164,5 +249,79 @@ export type Extras<D, U, V> = [D, U, V | undefined];
* @property {D} foo
* @property {V} bar
*/

/**
* @template Type
*/
interface GenericIdentityFn<Type> {
(arg: Type): Type;
}

/**
* @template Type
*/
export interface GenericIdentityFn<Type> {
(arg: Type): Type;
}

/**
* @template Type
*/
export default interface GenericIdentityFn<Type> {
(arg: Type): Type;
}

/**
* @template Type
*/
function identity<Type>(arg: Type): Type {
return arg;
}

/**
* @template Type
*/
export function identity<Type>(arg: Type): Type {
return arg;
}

/**
* @template Type
*/
export default function identity<Type>(arg: Type): Type {
return arg;
}

/**
* @template NumType
*/
class GenericNumber<NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}

/**
* @template NumType
*/
export class GenericNumber<NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}

/**
* @template NumType
*/
export default class GenericNumber<NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}

/**
* @template NumType
*/
export default class <NumType> {
zeroValue: NumType;
add: (x: NumType, y: NumType) => NumType;
}
````

Loading
Loading