Skip to content

Commit 0c403f8

Browse files
committed
More strict null (#60565)
1 parent cbd6299 commit 0c403f8

23 files changed

+417
-346
lines changed

Diff for: src/tsconfig.strictNullChecks.json

+20
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@
9090
"./vs/code/electron-main/keyboard.ts",
9191
"./vs/code/electron-main/theme.ts",
9292
"./vs/code/node/shellEnv.ts",
93+
"./vs/editor/common/config/editorOptions.ts",
9394
"./vs/editor/common/config/editorZoom.ts",
95+
"./vs/editor/common/config/fontInfo.ts",
9496
"./vs/editor/common/controller/cursorEvents.ts",
9597
"./vs/editor/common/controller/wordCharacterClassifier.ts",
9698
"./vs/editor/common/core/characterClassifier.ts",
@@ -100,9 +102,27 @@
100102
"./vs/editor/common/core/selection.ts",
101103
"./vs/editor/common/core/stringBuilder.ts",
102104
"./vs/editor/common/core/uint.ts",
105+
"./vs/editor/common/model.ts",
106+
"./vs/editor/common/model/editStack.ts",
107+
"./vs/editor/common/model/intervalTree.ts",
103108
"./vs/editor/common/model/mirrorTextModel.ts",
109+
"./vs/editor/common/model/pieceTreeTextBuffer/pieceTreeBase.ts",
110+
"./vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBuffer.ts",
111+
"./vs/editor/common/model/pieceTreeTextBuffer/rbTreeBase.ts",
112+
"./vs/editor/common/model/textModel.ts",
104113
"./vs/editor/common/model/textModelEvents.ts",
105114
"./vs/editor/common/modes/languageSelector.ts",
115+
"./vs/editor/common/model/textModelSearch.ts",
116+
"./vs/editor/common/model/textModelTokens.ts",
117+
"./vs/editor/common/model/wordHelper.ts",
118+
"./vs/editor/common/modes.ts",
119+
"./vs/editor/common/modes/languageConfigurationRegistry.ts",
120+
"./vs/editor/common/modes/languageFeatureRegistry.ts",
121+
"./vs/editor/common/modes/nullMode.ts",
122+
"./vs/editor/common/modes/supports/electricCharacter.ts",
123+
"./vs/editor/common/modes/supports/onEnter.ts",
124+
"./vs/editor/common/modes/supports/richEditBrackets.ts",
125+
"./vs/editor/common/modes/tokenizationRegistry.ts",
106126
"./vs/editor/common/view/overviewZoneManager.ts",
107127
"./vs/editor/common/viewLayout/whitespaceComputer.ts",
108128
"./vs/editor/common/viewModel/prefixSumComputer.ts",

Diff for: src/vs/base/common/map.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -639,16 +639,18 @@ export class LinkedMap<K, V> {
639639
this.clear();
640640
return;
641641
}
642-
let current = this._head!;
642+
let current = this._head;
643643
let currentSize = this.size;
644644
while (current && currentSize > newSize) {
645645
this._map.delete(current.key);
646-
current = current.next!;
646+
current = current.next;
647647
currentSize--;
648648
}
649649
this._head = current;
650650
this._size = currentSize;
651-
current.previous = void 0;
651+
if (current) {
652+
current.previous = void 0;
653+
}
652654
}
653655

654656
private addItemFirst(item: Item<K, V>): void {

Diff for: src/vs/editor/common/config/editorOptions.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ export function cursorStyleToString(cursorStyle: TextEditorCursorStyle): string
834834
}
835835
}
836836

837-
function _cursorStyleFromString(cursorStyle: string, defaultValue: TextEditorCursorStyle): TextEditorCursorStyle {
837+
function _cursorStyleFromString(cursorStyle: string | undefined, defaultValue: TextEditorCursorStyle): TextEditorCursorStyle {
838838
if (typeof cursorStyle !== 'string') {
839839
return defaultValue;
840840
}
@@ -930,7 +930,7 @@ export interface InternalEditorViewOptions {
930930
readonly rulers: number[];
931931
readonly ariaLabel: string;
932932
readonly renderLineNumbers: RenderLineNumbersType;
933-
readonly renderCustomLineNumbers: (lineNumber: number) => string;
933+
readonly renderCustomLineNumbers: ((lineNumber: number) => string) | null;
934934
readonly selectOnLineNumbers: boolean;
935935
readonly glyphMargin: boolean;
936936
readonly revealHorizontalRightPadding: number;
@@ -1597,7 +1597,7 @@ function _boolean<T>(value: any, defaultValue: T): boolean | T {
15971597
return Boolean(value);
15981598
}
15991599

1600-
function _booleanMap(value: { [key: string]: boolean }, defaultValue: { [key: string]: boolean }): { [key: string]: boolean } {
1600+
function _booleanMap(value: { [key: string]: boolean } | undefined, defaultValue: { [key: string]: boolean }): { [key: string]: boolean } {
16011601
if (!value) {
16021602
return defaultValue;
16031603
}
@@ -1619,7 +1619,7 @@ function _string(value: any, defaultValue: string): string {
16191619
return value;
16201620
}
16211621

1622-
function _stringSet<T>(value: T, defaultValue: T, allowedValues: T[]): T {
1622+
function _stringSet<T>(value: T | undefined, defaultValue: T, allowedValues: T[]): T {
16231623
if (typeof value !== 'string') {
16241624
return defaultValue;
16251625
}
@@ -1652,7 +1652,7 @@ function _float(value: any, defaultValue: number): number {
16521652
return r;
16531653
}
16541654

1655-
function _wrappingIndentFromString(wrappingIndent: string, defaultValue: WrappingIndent): WrappingIndent {
1655+
function _wrappingIndentFromString(wrappingIndent: string | undefined, defaultValue: WrappingIndent): WrappingIndent {
16561656
if (typeof wrappingIndent !== 'string') {
16571657
return defaultValue;
16581658
}
@@ -1667,7 +1667,7 @@ function _wrappingIndentFromString(wrappingIndent: string, defaultValue: Wrappin
16671667
}
16681668
}
16691669

1670-
function _cursorBlinkingStyleFromString(cursorBlinkingStyle: string, defaultValue: TextEditorCursorBlinkingStyle): TextEditorCursorBlinkingStyle {
1670+
function _cursorBlinkingStyleFromString(cursorBlinkingStyle: string | undefined, defaultValue: TextEditorCursorBlinkingStyle): TextEditorCursorBlinkingStyle {
16711671
if (typeof cursorBlinkingStyle !== 'string') {
16721672
return defaultValue;
16731673
}
@@ -1687,7 +1687,7 @@ function _cursorBlinkingStyleFromString(cursorBlinkingStyle: string, defaultValu
16871687
return TextEditorCursorBlinkingStyle.Blink;
16881688
}
16891689

1690-
function _scrollbarVisibilityFromString(visibility: string, defaultValue: ScrollbarVisibility): ScrollbarVisibility {
1690+
function _scrollbarVisibilityFromString(visibility: string | undefined, defaultValue: ScrollbarVisibility): ScrollbarVisibility {
16911691
if (typeof visibility !== 'string') {
16921692
return defaultValue;
16931693
}
@@ -1726,7 +1726,7 @@ export class EditorOptionsValidator {
17261726
const viewInfo = this._sanitizeViewInfo(opts, defaults.viewInfo);
17271727
const contribInfo = this._sanitizeContribInfo(opts, defaults.contribInfo);
17281728

1729-
let configuredMulticursorModifier: 'altKey' | 'metaKey' | 'ctrlKey';
1729+
let configuredMulticursorModifier: 'altKey' | 'metaKey' | 'ctrlKey' | undefined = undefined;
17301730
if (typeof opts.multiCursorModifier === 'string') {
17311731
if (opts.multiCursorModifier === 'ctrlCmd') {
17321732
configuredMulticursorModifier = platform.isMacintosh ? 'metaKey' : 'ctrlKey';
@@ -1783,7 +1783,7 @@ export class EditorOptionsValidator {
17831783
};
17841784
}
17851785

1786-
private static _sanitizeScrollbarOpts(opts: IEditorScrollbarOptions, defaults: InternalEditorScrollbarOptions, mouseWheelScrollSensitivity: number): InternalEditorScrollbarOptions {
1786+
private static _sanitizeScrollbarOpts(opts: IEditorScrollbarOptions | undefined, defaults: InternalEditorScrollbarOptions, mouseWheelScrollSensitivity: number): InternalEditorScrollbarOptions {
17871787
if (typeof opts !== 'object') {
17881788
return defaults;
17891789
}
@@ -1810,7 +1810,7 @@ export class EditorOptionsValidator {
18101810
};
18111811
}
18121812

1813-
private static _sanitizeMinimapOpts(opts: IEditorMinimapOptions, defaults: InternalEditorMinimapOptions): InternalEditorMinimapOptions {
1813+
private static _sanitizeMinimapOpts(opts: IEditorMinimapOptions | undefined, defaults: InternalEditorMinimapOptions): InternalEditorMinimapOptions {
18141814
if (typeof opts !== 'object') {
18151815
return defaults;
18161816
}
@@ -1823,7 +1823,7 @@ export class EditorOptionsValidator {
18231823
};
18241824
}
18251825

1826-
private static _santizeFindOpts(opts: IEditorFindOptions, defaults: InternalEditorFindOptions): InternalEditorFindOptions {
1826+
private static _santizeFindOpts(opts: IEditorFindOptions | undefined, defaults: InternalEditorFindOptions): InternalEditorFindOptions {
18271827
if (typeof opts !== 'object') {
18281828
return defaults;
18291829
}
@@ -1835,7 +1835,7 @@ export class EditorOptionsValidator {
18351835
};
18361836
}
18371837

1838-
private static _sanitizeParameterHintOpts(opts: IEditorParameterHintOptions, defaults: InternalParameterHintOptions): InternalParameterHintOptions {
1838+
private static _sanitizeParameterHintOpts(opts: IEditorParameterHintOptions | undefined, defaults: InternalParameterHintOptions): InternalParameterHintOptions {
18391839
if (typeof opts !== 'object') {
18401840
return defaults;
18411841
}
@@ -1846,7 +1846,7 @@ export class EditorOptionsValidator {
18461846
};
18471847
}
18481848

1849-
private static _santizeHoverOpts(_opts: boolean | IEditorHoverOptions, defaults: InternalEditorHoverOptions): InternalEditorHoverOptions {
1849+
private static _santizeHoverOpts(_opts: boolean | IEditorHoverOptions | undefined, defaults: InternalEditorHoverOptions): InternalEditorHoverOptions {
18501850
let opts: IEditorHoverOptions;
18511851
if (typeof _opts === 'boolean') {
18521852
opts = {
@@ -1875,7 +1875,7 @@ export class EditorOptionsValidator {
18751875
};
18761876
}
18771877

1878-
private static _sanitizeTabCompletionOpts(opts: boolean | 'on' | 'off' | 'onlySnippets', defaults: 'on' | 'off' | 'onlySnippets'): 'on' | 'off' | 'onlySnippets' {
1878+
private static _sanitizeTabCompletionOpts(opts: boolean | 'on' | 'off' | 'onlySnippets' | undefined, defaults: 'on' | 'off' | 'onlySnippets'): 'on' | 'off' | 'onlySnippets' {
18791879
if (opts === false) {
18801880
return 'off';
18811881
} else if (opts === true) {
@@ -1896,7 +1896,7 @@ export class EditorOptionsValidator {
18961896
}
18971897

18981898
let renderLineNumbers: RenderLineNumbersType = defaults.renderLineNumbers;
1899-
let renderCustomLineNumbers: (lineNumber: number) => string = defaults.renderCustomLineNumbers;
1899+
let renderCustomLineNumbers: ((lineNumber: number) => string) | null = defaults.renderCustomLineNumbers;
19001900

19011901
if (typeof opts.lineNumbers !== 'undefined') {
19021902
let lineNumbers = opts.lineNumbers;
@@ -2198,7 +2198,7 @@ export class InternalEditorOptionsFactory {
21982198
pixelRatio: env.pixelRatio
21992199
});
22002200

2201-
let bareWrappingInfo: { isWordWrapMinified: boolean; isViewportWrapping: boolean; wrappingColumn: number; } = null;
2201+
let bareWrappingInfo: { isWordWrapMinified: boolean; isViewportWrapping: boolean; wrappingColumn: number; } | null = null;
22022202
{
22032203
const wordWrap = opts.wordWrap;
22042204
const wordWrapColumn = opts.wordWrapColumn;

Diff for: src/vs/editor/common/config/fontInfo.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,27 @@ const MAXIMUM_LINE_HEIGHT = 150;
2323
const MINIMUM_LETTER_SPACING = -5;
2424
const MAXIMUM_LETTER_SPACING = 20;
2525

26-
function safeParseFloat(n: number | string, defaultValue: number): number {
26+
function safeParseFloat(n: number | string | undefined, defaultValue: number): number {
2727
if (typeof n === 'number') {
2828
return n;
2929
}
30+
if (typeof n === 'undefined') {
31+
return defaultValue;
32+
}
3033
let r = parseFloat(n);
3134
if (isNaN(r)) {
3235
return defaultValue;
3336
}
3437
return r;
3538
}
3639

37-
function safeParseInt(n: number | string, defaultValue: number): number {
40+
function safeParseInt(n: number | string | undefined, defaultValue: number): number {
3841
if (typeof n === 'number') {
3942
return Math.round(n);
4043
}
44+
if (typeof n === 'undefined') {
45+
return defaultValue;
46+
}
4147
let r = parseInt(n);
4248
if (isNaN(r)) {
4349
return defaultValue;

0 commit comments

Comments
 (0)