-
-
Notifications
You must be signed in to change notification settings - Fork 949
refactor(linter/plugins): move assertions into own file #15945
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
graphite-app
merged 1 commit into
main
from
11-21-refactor_linter_plugins_move_assertions_into_own_file
Nov 21, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /** | ||
| * Assert a value is of a certain type. | ||
| * | ||
| * Has no runtime effect - only for guiding the type-checker. | ||
| * Minification removes this function and all calls to it, so it has zero runtime cost. | ||
| * | ||
| * @param value - Value | ||
| */ | ||
| // oxlint-disable-next-line no-unused-vars | ||
| export function assertIs<T>(value: unknown): asserts value is T {} | ||
|
|
||
| /** | ||
| * Assert a value is not `null` or `undefined`. | ||
| * | ||
| * In release builds, is a no-op. Only does runtime checks in debug builds. | ||
| * Minification removes this function and all calls to it in release builds, so it has zero runtime cost. | ||
| * | ||
| * @param value - Value | ||
| */ | ||
| export function assertIsNonNull<T>(value: T | null | undefined): asserts value is T { | ||
| if (!DEBUG) return; | ||
|
|
||
| if (value === null || value === undefined) { | ||
| // oxlint-disable-next-line typescript/restrict-template-expressions | ||
| throw new Error(`Expected non-null value, got ${value}`); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /** | ||
| * Utility type to make specified properties of a type nullable. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * type Foo = { str: string, num: number }; | ||
| * type FooWithNullableNum = SetNullable<Foo, 'num'>; | ||
| * // { str: string, num: number | null } | ||
| * ``` | ||
| */ | ||
| export type SetNullable<BaseType, Keys extends keyof BaseType = keyof BaseType> = { | ||
| [Key in keyof BaseType]: Key extends Keys ? BaseType[Key] | null : BaseType[Key]; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /** | ||
| * Get error message from an error. | ||
| * | ||
| * `err` is expected to be an `Error` object, but can be anything. | ||
| * | ||
| * * If it's an `Error`, the error message and stack trace is returned. | ||
| * * If it's another object with a string `message` property, `message` is returned. | ||
| * * Otherwise, a generic "Unknown error" message is returned. | ||
| * | ||
| * This function will never throw, and always returns a non-empty string, even if: | ||
| * | ||
| * * `err` is `null` or `undefined`. | ||
| * * `err` is an object with a getter for `message` property which throws. | ||
| * * `err` has a getter for `stack` or `message` property which returns a different value each time it's accessed. | ||
| * | ||
| * @param err - Error | ||
| * @returns Error message | ||
| */ | ||
| export function getErrorMessage(err: unknown): string { | ||
| try { | ||
| if (err instanceof Error) { | ||
| // Note: `stack` includes the error message | ||
| const { stack } = err; | ||
| if (typeof stack === 'string' && stack !== '') return stack; | ||
| } | ||
|
|
||
| const { message } = err as { message?: unknown }; | ||
| if (typeof message === 'string' && message !== '') return message; | ||
| } catch {} | ||
|
|
||
| return 'Unknown error'; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.