Skip to content

Commit 16156b1

Browse files
authored
Add rules from eslint's recommended set that triggered good lints (#50422)
1 parent a11c416 commit 16156b1

34 files changed

+54
-48
lines changed

.eslintrc.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"parser": "@typescript-eslint/parser",
33
"parserOptions": {
44
"warnOnUnsupportedTypeScriptVersion": false,
5-
"ecmaVersion": 6,
65
"sourceType": "module"
76
},
87
"env": {
@@ -27,6 +26,7 @@
2726
"rules": {
2827
"@typescript-eslint/adjacent-overload-signatures": "error",
2928
"@typescript-eslint/array-type": "error",
29+
"@typescript-eslint/no-array-constructor": "error",
3030

3131
"brace-style": "off",
3232
"@typescript-eslint/brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
@@ -62,12 +62,14 @@
6262
"@typescript-eslint/prefer-for-of": "error",
6363
"@typescript-eslint/prefer-function-type": "error",
6464
"@typescript-eslint/prefer-namespace-keyword": "error",
65+
"@typescript-eslint/prefer-as-const": "error",
6566

6667
"quotes": "off",
6768
"@typescript-eslint/quotes": ["error", "double", { "avoidEscape": true, "allowTemplateLiterals": true }],
6869

6970
"semi": "off",
7071
"@typescript-eslint/semi": "error",
72+
"@typescript-eslint/no-extra-semi": "error",
7173

7274
"space-before-function-paren": "off",
7375
"@typescript-eslint/space-before-function-paren": ["error", {
@@ -80,6 +82,8 @@
8082
"@typescript-eslint/type-annotation-spacing": "error",
8183
"@typescript-eslint/unified-signatures": "error",
8284

85+
"@typescript-eslint/no-extra-non-null-assertion": "error",
86+
8387
// scripts/eslint/rules
8488
"local/object-literal-surrounding-space": "error",
8589
"local/no-type-assertion-whitespace": "error",
@@ -143,6 +147,9 @@
143147
"quote-props": ["error", "consistent-as-needed"],
144148
"space-in-parens": "error",
145149
"unicode-bom": ["error", "never"],
146-
"use-isnan": "error"
150+
"use-isnan": "error",
151+
"no-prototype-builtins": "error",
152+
"no-self-assign": "error",
153+
"no-dupe-else-if": "error"
147154
}
148155
}

scripts/word2md.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
185185

186186
function setProperties(target: any, properties: any) {
187187
for (const name in properties) {
188-
if (properties.hasOwnProperty(name)) {
188+
if (Object.prototype.hasOwnProperty.call(properties, name)) {
189189
const value = properties[name];
190190
if (typeof value === "object") {
191191
setProperties(target[name], value);

src/compiler/binder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3044,7 +3044,7 @@ namespace ts {
30443044
return;
30453045
}
30463046
const rootExpr = getLeftmostAccessExpression(node.left);
3047-
if (isIdentifier(rootExpr) && lookupSymbolForName(container, rootExpr.escapedText)!?.flags & SymbolFlags.Alias) {
3047+
if (isIdentifier(rootExpr) && lookupSymbolForName(container, rootExpr.escapedText)?.flags! & SymbolFlags.Alias) {
30483048
return;
30493049
}
30503050
// Fix up parent pointers since we're going to use these nodes before we bind into them

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9219,7 +9219,7 @@ namespace ts {
92199219
if (container && (container.kind === SyntaxKind.Constructor || isJSConstructor(container))) {
92209220
return container as ConstructorDeclaration;
92219221
}
9222-
};
9222+
}
92239223
}
92249224

92259225
/** Create a synthetic property access flow node after the last statement of the file */
@@ -29892,7 +29892,7 @@ namespace ts {
2989229892
return !!s && getMinArgumentCount(s) >= 1 && isTypeAssignableTo(keyedType, getTypeAtPosition(s, 0));
2989329893
}
2989429894
return false;
29895-
};
29895+
}
2989629896

2989729897
const suggestedMethod = isAssignmentTarget(expr) ? "set" : "get";
2989829898
if (!hasProp(suggestedMethod)) {

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3709,7 +3709,7 @@ namespace ts {
37093709
export function convertCompilerOptionsForTelemetry(opts: CompilerOptions): CompilerOptions {
37103710
const out: CompilerOptions = {};
37113711
for (const key in opts) {
3712-
if (opts.hasOwnProperty(key)) {
3712+
if (hasProperty(opts, key)) {
37133713
const type = getOptionFromName(key);
37143714
if (type !== undefined) { // Ignore unknown options
37153715
out[key] = getOptionValueWithEmptyStrings(opts[key], type);

src/compiler/debug.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ namespace ts {
279279
if (typeof func !== "function") {
280280
return "";
281281
}
282-
else if (func.hasOwnProperty("name")) {
282+
else if (hasProperty(func, "name")) {
283283
return (func as any).name;
284284
}
285285
else {
@@ -625,7 +625,7 @@ namespace ts {
625625
];
626626

627627
for (const ctor of nodeConstructors) {
628-
if (!ctor.prototype.hasOwnProperty("__debugKind")) {
628+
if (!hasProperty(ctor, "__debugKind")) {
629629
Object.defineProperties(ctor.prototype, {
630630
// for use with vscode-js-debug's new customDescriptionGenerator in launch.json
631631
__tsDebuggerDisplay: {

src/compiler/factory/nodeFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5639,7 +5639,7 @@ namespace ts {
56395639
setOriginalNode(clone, node);
56405640

56415641
for (const key in node) {
5642-
if (clone.hasOwnProperty(key) || !node.hasOwnProperty(key)) {
5642+
if (hasProperty(clone, key) || !hasProperty(node, key)) {
56435643
continue;
56445644
}
56455645

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ namespace ts {
744744
return visitNodes(cbNode, cbNodes, node.typeParameters) ||
745745
visitNodes(cbNode, cbNodes, node.parameters) ||
746746
visitNode(cbNode, node.type);
747-
};
747+
}
748748

749749
function forEachChildInUnionOrIntersectionType<T>(node: UnionTypeNode | IntersectionTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
750750
return visitNodes(cbNode, cbNodes, node.types);

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ namespace ts {
503503
/* @internal */ imports: SourceFile["imports"];
504504
/* @internal */ moduleAugmentations: SourceFile["moduleAugmentations"];
505505
impliedNodeFormat?: SourceFile["impliedNodeFormat"];
506-
};
506+
}
507507

508508
/**
509509
* Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly

src/compiler/scanner.ts

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

362362
/* @internal */
363363
export function computeLineStarts(text: string): number[] {
364-
const result: number[] = new Array();
364+
const result: number[] = [];
365365
let pos = 0;
366366
let lineStart = 0;
367367
while (pos < text.length) {

0 commit comments

Comments
 (0)