Skip to content

Commit

Permalink
Disallow the use of the void return type
Browse files Browse the repository at this point in the history
  • Loading branch information
remcohaszing committed Sep 29, 2023
1 parent 26ec0b9 commit 2d88bfb
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 7 deletions.
4 changes: 4 additions & 0 deletions core/suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,10 @@ module.exports = {
selector:
'CallExpression[callee.property.name="toString"][callee.optional=false][arguments.length=0][optional=false]',
message: 'Use String() instead.'
},
{
selector: '[returnType.type="TSTypeAnnotation"]>TSTypeAnnotation>TSVoidKeyword',
message: 'Use undefined for non-returning functions of unknown for callbacks'
}
],

Expand Down
2 changes: 1 addition & 1 deletion examples/typescript-lib/src/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function addSync(x: number, y: number): number {
* @param y The value to add to x.
* @param cb The callback that will be called with the sum of x and y.
*/
export function addAsync(x: number, y: number, cb: Callback<number>): void {
export function addAsync(x: number, y: number, cb: Callback<number>): undefined {
cb(null, x + y)
}

Expand Down
2 changes: 1 addition & 1 deletion examples/typescript-lib/src/substract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function substractSync(x: number, y: number): number {
* @param y The value to substract from x.
* @param cb The callback that will be called with the difference between x and y.
*/
export function substractAsync(x: number, y: number, cb: Callback<number>): void {
export function substractAsync(x: number, y: number, cb: Callback<number>): undefined {
addAsync(x, -y, (error, result) => {
if (error) {
cb(error)
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript-lib/src/types.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type Callback<T> = (error: Error | null, sum?: T) => void
export type Callback<T> = (error: Error | null, sum?: T) => unknown
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class ErrorHandler extends Component<ErrorHandlerProps, State> {
*
* @param error The error that was thrown
*/
componentDidCatch(error: Error): void {
componentDidCatch(error: Error): undefined {
this.setState({ error })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface ItemFormProps {
/**
* Called when the form is submitted
*/
onSubmit: (item: Item) => void
onSubmit: (item: Item) => unknown
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class ErrorHandler extends Component<ErrorHandlerProps, State> {
* @param error The error that was thrown
* @param errorInfo The React error information
*/
componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
componentDidCatch(error: Error, errorInfo: ErrorInfo): undefined {
this.setState({ error, errorInfo })
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ItemFormProps {
/**
* Called when the form is submitted
*/
onSubmit: (item: Item) => void
onSubmit: (item: Item) => unknown
}

/**
Expand Down

0 comments on commit 2d88bfb

Please sign in to comment.