Skip to content

Commit 2c32308

Browse files
committed
no-null/no-null
1 parent a8ee8fb commit 2c32308

31 files changed

+77
-34
lines changed

.eslintrc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"es6": true
1313
},
1414
"plugins": [
15-
"@typescript-eslint", "microsoft-typescript", "import"
15+
"@typescript-eslint", "microsoft-typescript", "no-null", "import"
1616
],
1717
"rules": {
1818
"@typescript-eslint/adjacent-overload-signatures": "error",
@@ -56,6 +56,7 @@
5656
"@typescript-eslint/type-annotation-spacing": "error",
5757
"@typescript-eslint/unified-signatures": "error",
5858

59+
/** eslint-plugin-microsoft-typescript */
5960
"microsoft-typescript/object-literal-surrounding-space": "error",
6061
"microsoft-typescript/no-type-assertion-whitespace": "error",
6162
"microsoft-typescript/type-operator-spacing": "error",
@@ -69,9 +70,11 @@
6970
"microsoft-typescript/debug-assert": "error",
7071
"microsoft-typescript/no-keywords": "error",
7172

72-
"import/no-extraneous-dependencies": ["error", {
73-
"optionalDependencies": false
74-
}],
73+
/** eslint-plugin-import */
74+
"import/no-extraneous-dependencies": ["error", { "optionalDependencies": false }],
75+
76+
/** eslint-plugin-no-null */
77+
"no-null/no-null": "error",
7578

7679
"arrow-body-style": "off",
7780
"arrow-parens": "off",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"eslint-formatter-autolinkable-stylish": "latest",
6969
"eslint-plugin-import": "2.18.0",
7070
"eslint-plugin-microsoft-typescript": "0.1.11",
71+
"eslint-plugin-no-null": "1.0.2",
7172
"fancy-log": "latest",
7273
"fs-extra": "^6.0.1",
7374
"glob": "latest",

scripts/configurePrerelease.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function main(): void {
5252
writeFileSync(tsFilePath, modifiedTsFileContents);
5353
}
5454

55+
/* eslint-disable no-null/no-null */
5556
function updateTsFile(tsFilePath: string, tsFileContents: string, majorMinor: string, patch: string, nightlyPatch: string): string {
5657
const majorMinorRgx = /export const versionMajorMinor = "(\d+\.\d+)"/;
5758
const majorMinorMatch = majorMinorRgx.exec(tsFileContents);
@@ -76,6 +77,7 @@ function parsePackageJsonVersion(versionString: string): { majorMinor: string, p
7677
assert(match !== null, "package.json 'version' should match " + versionRgx.toString());
7778
return { majorMinor: match![1], patch: match![2] };
7879
}
80+
/* eslint-enable no-null/no-null */
7981

8082
/** e.g. 0-dev.20170707 */
8183
function getPrereleasePatch(tag: string, plainPatch: string): string {

src/compiler/commandLineParser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ namespace ts {
16421642

16431643
case SyntaxKind.NullKeyword:
16441644
reportInvalidOptionValue(option && option.name === "extends"); // "extends" is the only option we don't allow null/undefined for
1645-
return null;
1645+
return null; // eslint-disable-line no-null/no-null
16461646

16471647
case SyntaxKind.StringLiteral:
16481648
if (!isDoubleQuotedString(valueExpression)) {
@@ -2013,7 +2013,7 @@ namespace ts {
20132013
}
20142014

20152015
function isNullOrUndefined(x: any): x is null | undefined {
2016-
return x === undefined || x === null;
2016+
return x === undefined || x === null; // eslint-disable-line no-null/no-null
20172017
}
20182018

20192019
function directoryOfCombinedPath(fileName: string, basePath: string) {

src/compiler/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace ts {
7474

7575
/** Create a MapLike with good performance. */
7676
function createDictionaryObject<T>(): MapLike<T> {
77-
const map = Object.create(/*prototype*/ null);
77+
const map = Object.create(/*prototype*/ null); // eslint-disable-line no-null/no-null
7878

7979
// Using 'delete' on an object causes V8 to put the object in dictionary mode.
8080
// This disables creation of hidden classes, which are expensive when an object is

src/compiler/debug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace ts {
5454
}
5555

5656
export function assertDefined<T>(value: T | null | undefined, message?: string): T {
57+
// eslint-disable-next-line no-null/no-null
5758
if (value === undefined || value === null) return fail(message);
5859
return value;
5960
}

src/compiler/moduleNameResolver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ namespace ts {
130130
return;
131131
}
132132
const value = jsonContent[fieldName];
133-
if (typeof value !== typeOfTag || value === null) {
133+
if (typeof value !== typeOfTag || value === null) { // eslint-disable-line no-null/no-null
134134
if (state.traceEnabled) {
135+
// eslint-disable-next-line no-null/no-null
135136
trace(state.host, Diagnostics.Expected_type_of_0_field_in_package_json_to_be_1_got_2, fieldName, typeOfTag, value === null ? "null" : typeof value);
136137
}
137138
return;
@@ -420,6 +421,7 @@ namespace ts {
420421
const packageJsonPath = combinePaths(root, normalized, "package.json");
421422
// `types-publisher` sometimes creates packages with `"typings": null` for packages that don't provide their own types.
422423
// See `createNotNeededPackageJSON` in the types-publisher` repo.
424+
// eslint-disable-next-line no-null/no-null
423425
const isNotNeededPackage = host.fileExists(packageJsonPath) && (readJson(packageJsonPath, host) as PackageJson).typings === null;
424426
if (!isNotNeededPackage) {
425427
const baseFileName = getBaseFileName(normalized);

src/compiler/program.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2084,7 +2084,7 @@ namespace ts {
20842084

20852085
function collectDynamicImportOrRequireCalls(file: SourceFile) {
20862086
const r = /import|require/g;
2087-
while (r.exec(file.text) !== null) {
2087+
while (r.exec(file.text) !== null) { // eslint-disable-line no-null/no-null
20882088
const node = getNodeAtPosition(file, r.lastIndex);
20892089
if (isRequireCall(node, /*checkArgumentIsStringLiteralLike*/ true)) {
20902090
imports = append(imports, node.arguments[0]);
@@ -3094,7 +3094,7 @@ namespace ts {
30943094

30953095
function getCompilerOptionsObjectLiteralSyntax() {
30963096
if (_compilerOptionsObjectLiteralSyntax === undefined) {
3097-
_compilerOptionsObjectLiteralSyntax = null;
3097+
_compilerOptionsObjectLiteralSyntax = null; // eslint-disable-line no-null/no-null
30983098
const jsonObjectLiteral = getTsConfigObjectLiteralExpression(options.configFile);
30993099
if (jsonObjectLiteral) {
31003100
for (const prop of getPropertyAssignment(jsonObjectLiteral, "compilerOptions")) {

src/compiler/sourcemap.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,19 @@ namespace ts {
6868
return sourceIndex;
6969
}
7070

71+
/* eslint-disable microsoft-typescript/boolean-trivia, no-null/no-null */
7172
function setSourceContent(sourceIndex: number, content: string | null) {
7273
enter();
7374
if (content !== null) {
7475
if (!sourcesContent) sourcesContent = [];
7576
while (sourcesContent.length < sourceIndex) {
76-
// eslint-disable-next-line microsoft-typescript/boolean-trivia
7777
sourcesContent.push(null);
7878
}
7979
sourcesContent[sourceIndex] = content;
8080
}
8181
exit();
8282
}
83+
/* eslint-enable microsoft-typescript/boolean-trivia, no-null/no-null */
8384

8485
function addName(name: string) {
8586
enter();
@@ -309,6 +310,7 @@ namespace ts {
309310
}
310311
}
311312

313+
/* eslint-disable no-null/no-null */
312314
function isStringOrNull(x: any) {
313315
return typeof x === "string" || x === null;
314316
}
@@ -324,6 +326,7 @@ namespace ts {
324326
&& (x.sourcesContent === undefined || x.sourcesContent === null || isArray(x.sourcesContent) && every(x.sourcesContent, isStringOrNull))
325327
&& (x.names === undefined || x.names === null || isArray(x.names) && every(x.names, isString));
326328
}
329+
/* eslint-enable no-null/no-null */
327330

328331
export function tryParseRawSourceMap(text: string) {
329332
try {

src/compiler/utilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8623,6 +8623,7 @@ namespace ts {
86238623
}
86248624

86258625
export function isJsonEqual(a: unknown, b: unknown): boolean {
8626+
// eslint-disable-next-line no-null/no-null
86268627
return a === b || typeof a === "object" && a !== null && typeof b === "object" && b !== null && equalOwnProperties(a as MapLike<unknown>, b as MapLike<unknown>, isJsonEqual);
86278628
}
86288629

0 commit comments

Comments
 (0)