Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(eslint-plugin): [restrict-plus-operands] add allowAny option#901

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

lonyele
Copy link
Contributor

Fixes#386

I addedallowAny option to the rule as described in the issue. Please take a look.

@typescript-eslint
Copy link
Contributor

Thanks for the PR,@lonyele!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently onhttps://opencollective.com/typescript-eslint

@codecov
Copy link

codecovbot commentedAug 24, 2019
edited
Loading

Codecov Report

Merging#901 intomaster willincrease coverage by<.01%.
The diff coverage is100%.

@@            Coverage Diff             @@##           master     #901      +/-   ##==========================================+ Coverage   94.13%   94.13%   +<.01%==========================================  Files         115      115                Lines        5011     5013       +2       Branches     1399     1400       +1     ==========================================+ Hits         4717     4719       +2  Misses        166      166                Partials      128      128
Impacted FilesCoverage Δ
.../eslint-plugin/src/rules/restrict-plus-operands.ts97.36% <100%> (+0.14%)⬆️

@bradzacherbradzacher added the enhancement: plugin rule optionNew rule option for an existing eslint-plugin rule labelAug 24, 2019
@@ -88,6 +106,10 @@ export default util.createRule({
const leftType = getNodeType(node.left);
const rightType = getNodeType(node.right);

if (option.allowAny && (leftType === 'any' || rightType === 'any')) {
Copy link
Member

Choose a reason for hiding this comment

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

this is not quite correct.
This shouldn't override all validation in the rule, it should only allowany as a valid type.

I.e.
any + boolean shouldn't be allowed - becauseboolean isn't a valid type for this rule without the option.
Howeverany + (string | number | bigint) should be allowed, as those 3 are all valid types.

},
{
code: `
export const f = (a: boolean, b: any) => a + b;
Copy link
Member

Choose a reason for hiding this comment

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

as mentioned - this should be invalid


```ts
const x = (a: any, b: string) => a + b;
const y = (a: boolean, b: any) => a + b;
Copy link
Member

Choose a reason for hiding this comment

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

ditto - see comment in rule

Comment on lines +37 to +38
If the rule is too strict then making this option `true`
can be a help. Though It is not recommended since lint errors are potentially a real runtime errors in many cases.
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion for stronger/clearer wording for this:


This option is not recommended, as it greatly reduces the type safety in your code.
It is provided as a stopgap to make it easier to migrate codebases onto the rule.

This option will cause the rule to acceptany as a type for operands.any will be allowed to be summed with all other valid types.

Comment on lines +19 to 33
Options may be provided as an object with:

- `allowAny` to ignore this rule when either left or
right of plus operand is a type `any`

```json
{
"@typescript-eslint/restrict-plus-operands": "error"
"@typescript-eslint/estrict-plus-operands": [
"error",
{
"allowAny": true
}
]
}
```
Copy link
Member

Choose a reason for hiding this comment

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

This section can be changed to just this snippet.
We try to avoid putting the full config block in rule docs now.


typeOptions={allowAny?:boolean;}constdefaultOptions:Options={allowAny:false,};

@bradzacherbradzacher added awaiting responseIssues waiting for a reply from the OP or another party enhancement: plugin rule optionNew rule option for an existing eslint-plugin rule and removed enhancement: plugin rule optionNew rule option for an existing eslint-plugin rule labelsNov 13, 2019
@armano2armano2 added the help wantedExtra attention is needed labelJan 1, 2020
@bradzacherbradzacher added the stalePRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period labelApr 13, 2020
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsMay 14, 2020
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@bradzacherbradzacherbradzacher requested changes

Assignees
No one assigned
Labels
awaiting responseIssues waiting for a reply from the OP or another partyenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulehelp wantedExtra attention is neededstalePRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[restrict-plus-operands] Allowing any for summands
3 participants
@lonyele@bradzacher@armano2

[8]ページ先頭

©2009-2025 Movatter.jp