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): [prefer-optional-chain] support suggesting!foo || !foo.bar as a valid match for the rule#5266

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

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
19 commits
Select commitHold shift + click to select a range
cfded63
feat/issue5245-negated-or-optional-chaining
Jun 27, 2022
741d5e3
Merge remote-tracking branch 'upstream/main' into feat/issue5245-nega…
Jun 28, 2022
5f6cb28
Merge remote-tracking branch 'upstream/main' into feat/issue5245-nega…
Jun 29, 2022
931274c
fix lint errors with the updated rule
Jun 29, 2022
d0f7c3a
Merge remote-tracking branch 'upstream/main' into feat/issue5245-nega…
Jul 2, 2022
fdd99e0
reduce duplication
Jul 2, 2022
92f4285
coverage
Jul 2, 2022
e63bd2f
coverage
Jul 2, 2022
393d182
coverage
Jul 2, 2022
7a1fa82
Merge branch 'main' into feat/issue5245-negated-or-optional-chaining
Jul 17, 2022
70319e9
Merge remote-tracking branch 'upstream/main' into feat/issue5245-nega…
Jul 26, 2022
aa0063f
CR fixes
Jul 29, 2022
54c2ba7
Merge remote-tracking branch 'upstream/main' into feat/issue5245-nega…
Jul 29, 2022
265a1e8
refactor more duplications
Jul 29, 2022
f946a99
better
Jul 29, 2022
078bd0d
Remove commented " == undefined" tests in the "negated or" rule
Jul 29, 2022
6b1244c
Merge branch 'main' into feat/issue5245-negated-or-optional-chaining
Aug 6, 2022
1f35a88
Merge remote-tracking branch 'upstream/main' into feat/issue5245-nega…
Aug 19, 2022
cf8c41b
fix description conflict in md
Aug 19, 2022
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
12 changes: 11 additions & 1 deletionpackages/eslint-plugin/docs/rules/prefer-optional-chain.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
---
description: 'Enforce using concise optional chain expressions instead of chained logical ands.'
description: 'Enforce using concise optional chain expressions instead of chained logical ands, negated logical ors, or empty objects.'
---

> 🛑 This file is source code, not the primary documentation location! 🛑
Expand DownExpand Up@@ -65,9 +65,15 @@ foo && foo.a && foo.a.b && foo.a.b.c;
foo && foo['a'] && foo['a'].b && foo['a'].b.c;
foo && foo.a && foo.a.b && foo.a.b.method && foo.a.b.method();

// With empty objects
(((foo || {}).a || {}).b || {}).c;
(((foo || {})['a'] || {}).b || {}).c;

// With negated `or`s
!foo || !foo.bar;
!foo || !foo[bar];
!foo || !foo.bar || !foo.bar.baz || !foo.bar.baz();

Comment on lines +72 to +76
Copy link
ContributorAuthor

@omril1omril1Jul 2, 2022
edited
Loading

Choose a reason for hiding this comment

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

I think the examples should be arranged in a table, need some opinions

// this rule also supports converting chained strict nullish checks:
foo &&
foo.a != null &&
Expand All@@ -85,6 +91,10 @@ foo?.['a']?.b?.c;
foo?.a?.b?.method?.();

foo?.a?.b?.c?.d?.e;

!foo?.bar;
!foo?.[bar];
!foo?.bar?.baz?.();
```

**Note:** there are a few edge cases where this rule will false positive. Use your best judgement when evaluating reported errors.
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -90,7 +90,7 @@ export default util.createRule<Options, MessageIds>({
| TSESTree.FunctionExpression
| TSESTree.FunctionDeclaration,
): boolean {
if (!options.allowedNames || !options.allowedNames.length) {
if (!options.allowedNames?.length) {
return false;
}

Expand Down
11 changes: 4 additions & 7 deletionspackages/eslint-plugin/src/rules/no-useless-constructor.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -34,13 +34,10 @@ function checkAccessibility(node: TSESTree.MethodDefinition): boolean {
* Check if method is not useless due to typescript parameter properties and decorators
*/
function checkParams(node: TSESTree.MethodDefinition): boolean {
return (
!node.value.params ||
!node.value.params.some(
param =>
param.type === AST_NODE_TYPES.TSParameterProperty ||
param.decorators?.length,
)
return !node.value.params.some(
param =>
param.type === AST_NODE_TYPES.TSParameterProperty ||
param.decorators?.length,
);
}

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp