Skip to content

prefer-math-min-max: Reduce false positives in TypeScript #2527

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

Merged
merged 3 commits into from
Jan 18, 2025

Conversation

axetroy
Copy link
Contributor

@axetroy axetroy commented Jan 17, 2025

Close #2509

This PR prioritizes reducing false positives by checking types.

Note that you need to specify the type explicitly

function foo(a, b: string) { // <------- Since the string type is explicitly specified here, this rule will not produce false positives.
  return a > b ? a : b;
}

var a: string; // <------- Since the string type is explicitly specified here, this rule will not produce false positives.
var b: string; // <------- Since the string type is explicitly specified here, this rule will not produce false positives.

var value = a > b ? a : b;

@axetroy axetroy changed the title prefer-math-min-max: priority support for typescript prefer-math-min-max: minimize false positives in TypeScript Jan 17, 2025
@axetroy
Copy link
Contributor Author

axetroy commented Jan 17, 2025

/cc @fisker

Comment on lines 111 to 116
/**
* Capture the following statement
* ```js
* function foo(a: number) {}
* ```
*/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* Capture the following statement
* ```js
* function foo(a: number) {}
* ```
*/
/**
Capture the following statement:
```js
function foo(a: number) {}
```
*/

Applies tool the comments

Copy link
Contributor Author

@axetroy axetroy Jan 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sindresorhus Updated.

BTW. should we write an eslint plugin to validate jsdoc since it is not the default jsdoc style?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@axetroy I think we can just add this rule to this package for now (PR welcome): https://github.com/gajus/eslint-plugin-jsdoc/blob/main/docs/rules/require-asterisk-prefix.md#readme I plan to add it to XO eventually.

@sindresorhus sindresorhus changed the title prefer-math-min-max: minimize false positives in TypeScript prefer-math-min-max: Reduce false positives in TypeScript Jan 18, 2025
@sindresorhus sindresorhus merged commit 1cbc561 into sindresorhus:main Jan 18, 2025
17 checks passed
@axetroy axetroy deleted the fix_2509 branch January 18, 2025 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

prefer-math-min-max: ignore bigint variable
3 participants