Skip to content

Commit 17e420d

Browse files
authored
Use built-in no-restricted-syntax to ban null instead of plugin, ban null type too (#58095)
1 parent 72f413c commit 17e420d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+128
-139
lines changed

.eslintrc.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
],
1818
"plugins": [
1919
"@typescript-eslint",
20-
"no-null",
2120
"eslint-plugin-local"
2221
],
2322
"ignorePatterns": [
@@ -60,6 +59,18 @@
6059
"prefer-object-spread": "error",
6160
"unicode-bom": ["error", "never"],
6261

62+
"no-restricted-syntax": [
63+
"error",
64+
{
65+
"selector": "Literal[raw=null]",
66+
"message": "Avoid using null; use undefined instead."
67+
},
68+
{
69+
"selector": "TSNullKeyword",
70+
"message": "Avoid using null; use undefined instead."
71+
}
72+
],
73+
6374
// Enabled in eslint:recommended, but not applicable here
6475
"no-extra-boolean-cast": "off",
6576
"no-case-declarations": "off",
@@ -132,10 +143,7 @@
132143
"local/no-in-operator": "error",
133144
"local/debug-assert": "error",
134145
"local/no-keywords": "error",
135-
"local/jsdoc-format": "error",
136-
137-
// eslint-plugin-no-null
138-
"no-null/no-null": "error"
146+
"local/jsdoc-format": "error"
139147
},
140148
"overrides": [
141149
// By default, the ESLint CLI only looks at .js files. But, it will also look at

package-lock.json

Lines changed: 0 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"eslint": "^8.57.0",
6464
"eslint-formatter-autolinkable-stylish": "^1.3.0",
6565
"eslint-plugin-local": "^4.2.1",
66-
"eslint-plugin-no-null": "^1.0.2",
6766
"fast-xml-parser": "^4.3.6",
6867
"glob": "^10.3.10",
6968
"hereby": "^1.8.9",

scripts/configurePrerelease.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function main() {
6464
writeFileSync(tsFilePath, modifiedTsFileContents);
6565
}
6666

67-
/* eslint-disable no-null/no-null */
67+
/* eslint-disable no-restricted-syntax */
6868
/**
6969
* @param {string} tsFilePath
7070
* @param {string} tsFileContents
@@ -101,7 +101,7 @@ function parsePackageJsonVersion(versionString) {
101101
assert(match !== null, "package.json 'version' should match " + versionRgx.toString());
102102
return { majorMinor: match[1], patch: match[2] };
103103
}
104-
/* eslint-enable no-null/no-null */
104+
/* eslint-enable no-restricted-syntax */
105105

106106
/**
107107
* e.g. 0-dev.20170707

scripts/eslint/rules/argument-trivia.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module.exports = createRule({
5353
}
5454

5555
if (node.type === AST_NODE_TYPES.Literal) {
56-
// eslint-disable-next-line no-null/no-null
56+
// eslint-disable-next-line no-restricted-syntax
5757
return node.value === null || node.value === true || node.value === false;
5858
}
5959

scripts/eslint/rules/only-arrow-functions.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ module.exports = createRule({
6767
return;
6868
}
6969

70-
if ((allowNamedFunctions && node.id !== null) || isMethodType(node)) { // eslint-disable-line no-null/no-null
70+
if ((allowNamedFunctions && node.id !== null) || isMethodType(node)) { // eslint-disable-line no-restricted-syntax
7171
return;
7272
}
7373

src/compiler/commandLineParser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,7 @@ export function convertToJson(
23942394
return false;
23952395

23962396
case SyntaxKind.NullKeyword:
2397-
return null; // eslint-disable-line no-null/no-null
2397+
return null; // eslint-disable-line no-restricted-syntax
23982398

23992399
case SyntaxKind.StringLiteral:
24002400
if (!isDoubleQuotedString(valueExpression)) {
@@ -2869,8 +2869,8 @@ export function setConfigFileInOptions(options: CompilerOptions, configFile: TsC
28692869
}
28702870
}
28712871

2872-
function isNullOrUndefined(x: any): x is null | undefined {
2873-
return x === undefined || x === null; // eslint-disable-line no-null/no-null
2872+
function isNullOrUndefined(x: any): x is null | undefined { // eslint-disable-line no-restricted-syntax
2873+
return x === undefined || x === null; // eslint-disable-line no-restricted-syntax
28742874
}
28752875

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

src/compiler/core.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -872,9 +872,9 @@ export function arrayIsEqualTo<T>(array1: readonly T[] | undefined, array2: read
872872
*
873873
* @internal
874874
*/
875-
export function compact<T>(array: (T | undefined | null | false | 0 | "")[]): T[];
875+
export function compact<T>(array: (T | undefined | null | false | 0 | "")[]): T[]; // eslint-disable-line no-restricted-syntax
876876
/** @internal */
877-
export function compact<T>(array: readonly (T | undefined | null | false | 0 | "")[]): readonly T[];
877+
export function compact<T>(array: readonly (T | undefined | null | false | 0 | "")[]): readonly T[]; // eslint-disable-line no-restricted-syntax
878878
// ESLint thinks these can be combined with the above - they cannot; they'd produce higher-priority inferences and prevent the falsey types from being stripped
879879
/** @internal */
880880
export function compact<T>(array: T[]): T[]; // eslint-disable-line @typescript-eslint/unified-signatures
@@ -1511,8 +1511,8 @@ export function group<T, K>(values: readonly T[], getGroupId: (value: T) => K, r
15111511
/** @internal */
15121512
export function groupBy<T, U extends T>(values: readonly T[] | undefined, keySelector: (value: T) => value is U): { true?: U[]; false?: Exclude<T, U>[]; };
15131513
/** @internal */
1514-
export function groupBy<T, K extends string | number | boolean | null | undefined>(values: readonly T[] | undefined, keySelector: (value: T) => K): { [P in K as `${P}`]?: T[]; };
1515-
export function groupBy<T, K extends string | number | boolean | null | undefined>(values: readonly T[] | undefined, keySelector: (value: T) => K): { [P in K as `${P}`]?: T[]; } {
1514+
export function groupBy<T, K extends string | number | boolean | null | undefined>(values: readonly T[] | undefined, keySelector: (value: T) => K): { [P in K as `${P}`]?: T[]; }; // eslint-disable-line no-restricted-syntax
1515+
export function groupBy<T, K extends string | number | boolean | null | undefined>(values: readonly T[] | undefined, keySelector: (value: T) => K): { [P in K as `${P}`]?: T[]; } { // eslint-disable-line no-restricted-syntax
15161516
const result: Record<string, T[]> = {};
15171517
if (values) {
15181518
for (const value of values) {

src/compiler/debug.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,13 @@ export namespace Debug {
244244
}
245245

246246
export function assertIsDefined<T>(value: T, message?: string, stackCrawlMark?: AnyFunction): asserts value is NonNullable<T> {
247-
// eslint-disable-next-line no-null/no-null
247+
// eslint-disable-next-line no-restricted-syntax
248248
if (value === undefined || value === null) {
249249
fail(message, stackCrawlMark || assertIsDefined);
250250
}
251251
}
252252

253-
export function checkDefined<T>(value: T | null | undefined, message?: string, stackCrawlMark?: AnyFunction): T {
253+
export function checkDefined<T>(value: T | null | undefined, message?: string, stackCrawlMark?: AnyFunction): T { // eslint-disable-line no-restricted-syntax
254254
assertIsDefined(value, message, stackCrawlMark || checkDefined);
255255
return value;
256256
}
@@ -935,7 +935,7 @@ m2: ${(this.mapper2 as unknown as DebugTypeMapper).__debugToString().split("\n")
935935
FlowFlags.Condition |
936936
FlowFlags.ArrayMutation;
937937

938-
const links: Record<number, FlowGraphNode> = Object.create(/*o*/ null); // eslint-disable-line no-null/no-null
938+
const links: Record<number, FlowGraphNode> = Object.create(/*o*/ null); // eslint-disable-line no-restricted-syntax
939939
const nodes: FlowGraphNode[] = [];
940940
const edges: FlowGraphEdge[] = [];
941941
const root = buildGraphNode(flowNode, new Set());

src/compiler/executeCommandLine.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ function executeCommandLineWorker(
653653
configParseResult.errors.forEach(reportDiagnostic);
654654
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
655655
}
656-
// eslint-disable-next-line no-null/no-null
656+
// eslint-disable-next-line no-restricted-syntax
657657
sys.write(JSON.stringify(convertToTSConfig(configParseResult, configFileName, sys), null, 4) + sys.newLine);
658658
return sys.exit(ExitStatus.Success);
659659
}
@@ -693,7 +693,7 @@ function executeCommandLineWorker(
693693
}
694694
else {
695695
if (commandLineOptions.showConfig) {
696-
// eslint-disable-next-line no-null/no-null
696+
// eslint-disable-next-line no-restricted-syntax
697697
sys.write(JSON.stringify(convertToTSConfig(commandLine, combinePaths(currentDirectory, "tsconfig.json"), sys), null, 4) + sys.newLine);
698698
return sys.exit(ExitStatus.Success);
699699
}

0 commit comments

Comments
 (0)