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-nullish-coalescing] supportif statement assignment (??=) and fix several minor bugs#10861

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
22 commits
Select commitHold shift + click to select a range
fcc9bea
support if statement assignment
OlivierZalFeb 21, 2025
4e3a723
improve logic
OlivierZalFeb 25, 2025
185667d
fix false positive
OlivierZalFeb 25, 2025
f69b588
handle computed expression (patch for existing issue)
OlivierZalFeb 25, 2025
ed7be4c
add tests
OlivierZalFeb 26, 2025
2db7af7
simplify and add test
OlivierZalFeb 28, 2025
e9b280a
Merge branch 'main' into prefer-nullish-coalescing-10829
OlivierZalFeb 28, 2025
fc478dc
fix error
OlivierZalFeb 28, 2025
5e59468
add "IfStatement without curly brackets" use case
OlivierZalMar 5, 2025
54e0f50
Merge branch 'main' into prefer-nullish-coalescing-10829
OlivierZalMar 5, 2025
8e1a6a6
add test
OlivierZalMar 5, 2025
1e10987
Merge branch 'main' into prefer-nullish-coalescing-10829
OlivierZalMar 6, 2025
168a228
after review
OlivierZalMar 19, 2025
4440b11
forgot the `noFormat`
OlivierZalMar 19, 2025
50bf59e
fix test
OlivierZalMar 19, 2025
92ef701
Handle comments
OlivierZalMar 19, 2025
727109a
fix naming and add test
OlivierZalMar 19, 2025
7035591
improve indentation
OlivierZalMar 20, 2025
fc806c5
fix type
OlivierZalMar 20, 2025
8858559
simplify
OlivierZalMar 20, 2025
271db29
remove duplicated test case
kirkwaiblingerMar 22, 2025
513b085
Merge branch 'main' into prefer-nullish-coalescing-10829
OlivierZalMar 23, 2025
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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,6 +17,54 @@ This rule reports when you may consider replacing:
- An `||` operator with `??`
- An `||=` operator with `??=`
- Ternary expressions (`?:`) that are equivalent to `||` or `??` with `??`
- Assignment expressions (`=`) that can be safely replaced by `??=`

## Examples

<Tabs>
<TabItem value="❌ Incorrect">

```ts
declare const a: string | null;
declare const b: string | null;

const c = a || b;

declare let foo: { a: string } | null;
declare function makeFoo(): { a: string };

function lazyInitializeFooByTruthiness() {
if (!foo) {
foo = makeFoo();
}
}

function lazyInitializeFooByNullCheck() {
if (foo == null) {
foo = makeFoo();
}
}
```

</TabItem>
<TabItem value="✅ Correct">

```ts
declare const a: string | null;
declare const b: string | null;

const c = a ?? b;

declare let foo: { a: string } | null;
declare function makeFoo(): { a: string };

function lazyInitializeFoo() {
foo ??= makeFoo();
}
```

</TabItem>
</Tabs>

:::caution
This rule will not work as expected if [`strictNullChecks`](https://www.typescriptlang.org/tsconfig#strictNullChecks) is not enabled.
Expand DownExpand Up@@ -255,3 +303,4 @@ If you are not using TypeScript 3.7 (or greater), then you will not be able to u

- [TypeScript 3.7 Release Notes](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html)
- [Nullish Coalescing Operator Proposal](https://github.com/tc39/proposal-nullish-coalescing/)
- [`logical-assignment-operators`](https://eslint.org/docs/latest/rules/logical-assignment-operators)
10 changes: 4 additions & 6 deletionspackages/eslint-plugin/src/rules/consistent-type-exports.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -203,13 +203,11 @@ export default createRule<Options, MessageIds>({
// Cache the first encountered exports for the package. We will need to come
// back to these later when fixing the problems.
if (node.exportKind === 'type') {
if (sourceExports.typeOnlyNamedExport == null) {
// The export is a type export
sourceExports.typeOnlyNamedExport = node;
}
} else if (sourceExports.valueOnlyNamedExport == null) {
// The export is a type export
sourceExports.typeOnlyNamedExport ??= node;
} else {
// The export is a value export
sourceExports.valueOnlyNamedExport = node;
sourceExports.valueOnlyNamedExport??= node;
}

// Next for the current export, we will separate type/value specifiers.
Expand Down
4 changes: 1 addition & 3 deletionspackages/eslint-plugin/src/rules/no-unsafe-return.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -80,9 +80,7 @@ export default createRule({
ts.isArrowFunction(functionTSNode)
? getContextualType(checker, functionTSNode)
: services.getTypeAtLocation(functionNode);
if (!functionType) {
functionType = services.getTypeAtLocation(functionNode);
}
functionType ??= services.getTypeAtLocation(functionNode);
const callSignatures = tsutils.getCallSignaturesOfType(functionType);
// If there is an explicit type annotation *and* that type matches the actual
// function return type, we shouldn't complain (it's intentional, even if unsafe)
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp