mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-24 04:30:53 -06:00
Add rules from eslint's recommended set that triggered good lints (#50422)
This commit is contained in:
parent
a11c41621b
commit
16156b1baf
@ -2,7 +2,6 @@
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"warnOnUnsupportedTypeScriptVersion": false,
|
||||
"ecmaVersion": 6,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"env": {
|
||||
@ -27,6 +26,7 @@
|
||||
"rules": {
|
||||
"@typescript-eslint/adjacent-overload-signatures": "error",
|
||||
"@typescript-eslint/array-type": "error",
|
||||
"@typescript-eslint/no-array-constructor": "error",
|
||||
|
||||
"brace-style": "off",
|
||||
"@typescript-eslint/brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
|
||||
@ -62,12 +62,14 @@
|
||||
"@typescript-eslint/prefer-for-of": "error",
|
||||
"@typescript-eslint/prefer-function-type": "error",
|
||||
"@typescript-eslint/prefer-namespace-keyword": "error",
|
||||
"@typescript-eslint/prefer-as-const": "error",
|
||||
|
||||
"quotes": "off",
|
||||
"@typescript-eslint/quotes": ["error", "double", { "avoidEscape": true, "allowTemplateLiterals": true }],
|
||||
|
||||
"semi": "off",
|
||||
"@typescript-eslint/semi": "error",
|
||||
"@typescript-eslint/no-extra-semi": "error",
|
||||
|
||||
"space-before-function-paren": "off",
|
||||
"@typescript-eslint/space-before-function-paren": ["error", {
|
||||
@ -80,6 +82,8 @@
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"@typescript-eslint/unified-signatures": "error",
|
||||
|
||||
"@typescript-eslint/no-extra-non-null-assertion": "error",
|
||||
|
||||
// scripts/eslint/rules
|
||||
"local/object-literal-surrounding-space": "error",
|
||||
"local/no-type-assertion-whitespace": "error",
|
||||
@ -143,6 +147,9 @@
|
||||
"quote-props": ["error", "consistent-as-needed"],
|
||||
"space-in-parens": "error",
|
||||
"unicode-bom": ["error", "never"],
|
||||
"use-isnan": "error"
|
||||
"use-isnan": "error",
|
||||
"no-prototype-builtins": "error",
|
||||
"no-self-assign": "error",
|
||||
"no-dupe-else-if": "error"
|
||||
}
|
||||
}
|
||||
|
||||
@ -185,7 +185,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
|
||||
|
||||
function setProperties(target: any, properties: any) {
|
||||
for (const name in properties) {
|
||||
if (properties.hasOwnProperty(name)) {
|
||||
if (Object.prototype.hasOwnProperty.call(properties, name)) {
|
||||
const value = properties[name];
|
||||
if (typeof value === "object") {
|
||||
setProperties(target[name], value);
|
||||
|
||||
@ -3044,7 +3044,7 @@ namespace ts {
|
||||
return;
|
||||
}
|
||||
const rootExpr = getLeftmostAccessExpression(node.left);
|
||||
if (isIdentifier(rootExpr) && lookupSymbolForName(container, rootExpr.escapedText)!?.flags & SymbolFlags.Alias) {
|
||||
if (isIdentifier(rootExpr) && lookupSymbolForName(container, rootExpr.escapedText)?.flags! & SymbolFlags.Alias) {
|
||||
return;
|
||||
}
|
||||
// Fix up parent pointers since we're going to use these nodes before we bind into them
|
||||
|
||||
@ -9219,7 +9219,7 @@ namespace ts {
|
||||
if (container && (container.kind === SyntaxKind.Constructor || isJSConstructor(container))) {
|
||||
return container as ConstructorDeclaration;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/** Create a synthetic property access flow node after the last statement of the file */
|
||||
@ -29892,7 +29892,7 @@ namespace ts {
|
||||
return !!s && getMinArgumentCount(s) >= 1 && isTypeAssignableTo(keyedType, getTypeAtPosition(s, 0));
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
const suggestedMethod = isAssignmentTarget(expr) ? "set" : "get";
|
||||
if (!hasProp(suggestedMethod)) {
|
||||
|
||||
@ -3709,7 +3709,7 @@ namespace ts {
|
||||
export function convertCompilerOptionsForTelemetry(opts: CompilerOptions): CompilerOptions {
|
||||
const out: CompilerOptions = {};
|
||||
for (const key in opts) {
|
||||
if (opts.hasOwnProperty(key)) {
|
||||
if (hasProperty(opts, key)) {
|
||||
const type = getOptionFromName(key);
|
||||
if (type !== undefined) { // Ignore unknown options
|
||||
out[key] = getOptionValueWithEmptyStrings(opts[key], type);
|
||||
|
||||
@ -279,7 +279,7 @@ namespace ts {
|
||||
if (typeof func !== "function") {
|
||||
return "";
|
||||
}
|
||||
else if (func.hasOwnProperty("name")) {
|
||||
else if (hasProperty(func, "name")) {
|
||||
return (func as any).name;
|
||||
}
|
||||
else {
|
||||
@ -625,7 +625,7 @@ namespace ts {
|
||||
];
|
||||
|
||||
for (const ctor of nodeConstructors) {
|
||||
if (!ctor.prototype.hasOwnProperty("__debugKind")) {
|
||||
if (!hasProperty(ctor, "__debugKind")) {
|
||||
Object.defineProperties(ctor.prototype, {
|
||||
// for use with vscode-js-debug's new customDescriptionGenerator in launch.json
|
||||
__tsDebuggerDisplay: {
|
||||
|
||||
@ -5639,7 +5639,7 @@ namespace ts {
|
||||
setOriginalNode(clone, node);
|
||||
|
||||
for (const key in node) {
|
||||
if (clone.hasOwnProperty(key) || !node.hasOwnProperty(key)) {
|
||||
if (hasProperty(clone, key) || !hasProperty(node, key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@ -744,7 +744,7 @@ namespace ts {
|
||||
return visitNodes(cbNode, cbNodes, node.typeParameters) ||
|
||||
visitNodes(cbNode, cbNodes, node.parameters) ||
|
||||
visitNode(cbNode, node.type);
|
||||
};
|
||||
}
|
||||
|
||||
function forEachChildInUnionOrIntersectionType<T>(node: UnionTypeNode | IntersectionTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
|
||||
return visitNodes(cbNode, cbNodes, node.types);
|
||||
|
||||
@ -503,7 +503,7 @@ namespace ts {
|
||||
/* @internal */ imports: SourceFile["imports"];
|
||||
/* @internal */ moduleAugmentations: SourceFile["moduleAugmentations"];
|
||||
impliedNodeFormat?: SourceFile["impliedNodeFormat"];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the resulting resolution mode for some reference in some file - this is generally the explicitly
|
||||
|
||||
@ -361,7 +361,7 @@ namespace ts {
|
||||
|
||||
/* @internal */
|
||||
export function computeLineStarts(text: string): number[] {
|
||||
const result: number[] = new Array();
|
||||
const result: number[] = [];
|
||||
let pos = 0;
|
||||
let lineStart = 0;
|
||||
while (pos < text.length) {
|
||||
|
||||
@ -25,7 +25,7 @@ namespace ts { // eslint-disable-line local/one-namespace-per-file
|
||||
// The actual constraint is that JSON.stringify be able to serialize it without throwing.
|
||||
interface Args {
|
||||
[key: string]: string | number | boolean | null | undefined | Args | readonly (string | number | boolean | null | undefined | Args)[];
|
||||
};
|
||||
}
|
||||
|
||||
/** Starts tracing for the given project. */
|
||||
export function startTracing(tracingMode: Mode, traceDir: string, configFilePath?: string) {
|
||||
|
||||
@ -218,9 +218,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
function reportNonlocalAugmentation(containingFile: SourceFile, parentSymbol: Symbol, symbol: Symbol) {
|
||||
const primaryDeclaration = parentSymbol.declarations?.find(d => getSourceFileOfNode(d) === containingFile)!;
|
||||
const primaryDeclaration = parentSymbol.declarations?.find(d => getSourceFileOfNode(d) === containingFile);
|
||||
const augmentingDeclarations = filter(symbol.declarations, d => getSourceFileOfNode(d) !== containingFile);
|
||||
if (augmentingDeclarations) {
|
||||
if (primaryDeclaration && augmentingDeclarations) {
|
||||
for (const augmentations of augmentingDeclarations) {
|
||||
context.addDiagnostic(addRelatedInfo(
|
||||
createDiagnosticForNode(augmentations, Diagnostics.Declaration_augments_declaration_in_another_file_This_cannot_be_serialized),
|
||||
|
||||
@ -487,7 +487,7 @@ namespace ts {
|
||||
// TODO(rbuckton): Should be a `Set`, but that requires changing the code below that uses `mutateMapSkippingNewValues`
|
||||
const currentProjects = new Map(
|
||||
getBuildOrderFromAnyBuildOrder(buildOrder).map(
|
||||
resolved => [toResolvedConfigFilePath(state, resolved), true as true])
|
||||
resolved => [toResolvedConfigFilePath(state, resolved), true as const])
|
||||
);
|
||||
|
||||
const noopOnDelete = { onDeleteValue: noop };
|
||||
|
||||
@ -563,7 +563,7 @@ namespace ts {
|
||||
|
||||
interface ScriptTargetFeatures {
|
||||
[key: string]: { [key: string]: string[] | undefined };
|
||||
};
|
||||
}
|
||||
|
||||
export function getScriptTargetFeatures(): ScriptTargetFeatures {
|
||||
return {
|
||||
@ -5558,7 +5558,7 @@ namespace ts {
|
||||
|
||||
export function isWatchSet(options: CompilerOptions) {
|
||||
// Firefox has Object.prototype.watch
|
||||
return options.watch && options.hasOwnProperty("watch");
|
||||
return options.watch && hasProperty(options, "watch");
|
||||
}
|
||||
|
||||
export function closeFileWatcher(watcher: FileWatcher) {
|
||||
|
||||
@ -1121,7 +1121,7 @@ namespace ts {
|
||||
|
||||
/* @internal */
|
||||
export function isNodeArray<T extends Node>(array: readonly T[]): array is NodeArray<T> {
|
||||
return array.hasOwnProperty("pos") && array.hasOwnProperty("end");
|
||||
return hasProperty(array, "pos") && hasProperty(array, "end");
|
||||
}
|
||||
|
||||
// Literals
|
||||
|
||||
@ -431,7 +431,7 @@ namespace ts {
|
||||
function getHeader(sys: System, message: string) {
|
||||
const colors = createColors(sys);
|
||||
const header: string[] = [];
|
||||
const terminalWidth = sys.getWidthOfTerminal?.() ?? 0;;
|
||||
const terminalWidth = sys.getWidthOfTerminal?.() ?? 0;
|
||||
const tsIconLength = 5;
|
||||
|
||||
const tsIconFirstLine = colors.blueBackground(padLeft("", tsIconLength));
|
||||
|
||||
@ -2737,7 +2737,7 @@ namespace FourSlash {
|
||||
const identifier = this.classificationToIdentifier(a.classificationType as number);
|
||||
const text = this.activeFile.content.slice(a.textSpan.start, a.textSpan.start + a.textSpan.length);
|
||||
replacement.push(` c2.semanticToken("${identifier}", "${text}"), `);
|
||||
};
|
||||
}
|
||||
replacement.push(");");
|
||||
|
||||
throw new Error("You need to change the source code of fourslash test to use replaceWithSemanticClassifications");
|
||||
|
||||
@ -1900,11 +1900,11 @@ namespace FourSlashInterface {
|
||||
};
|
||||
export interface DiagnosticIgnoredInterpolations {
|
||||
template: string
|
||||
};
|
||||
}
|
||||
export type RenameLocationOptions = FourSlash.Range | { readonly range: FourSlash.Range, readonly prefixText?: string, readonly suffixText?: string };
|
||||
export interface RenameOptions {
|
||||
readonly findInStrings?: boolean;
|
||||
readonly findInComments?: boolean;
|
||||
readonly providePrefixAndSuffixTextForRename?: boolean;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -335,7 +335,7 @@ namespace Harness {
|
||||
|
||||
export function setCompilerOptionsFromHarnessSetting(settings: TestCaseParser.CompilerSettings, options: ts.CompilerOptions & HarnessOptions): void {
|
||||
for (const name in settings) {
|
||||
if (settings.hasOwnProperty(name)) {
|
||||
if (ts.hasProperty(settings, name)) {
|
||||
const value = settings[name];
|
||||
if (value === undefined) {
|
||||
throw new Error(`Cannot have undefined value for compiler option '${name}'.`);
|
||||
@ -1496,7 +1496,7 @@ namespace Harness {
|
||||
|
||||
export function getConfigNameFromFileName(filename: string): "tsconfig.json" | "jsconfig.json" | undefined {
|
||||
const flc = ts.getBaseFileName(filename).toLowerCase();
|
||||
return ts.find(["tsconfig.json" as "tsconfig.json", "jsconfig.json" as "jsconfig.json"], x => x === flc);
|
||||
return ts.find(["tsconfig.json" as const, "jsconfig.json" as const], x => x === flc);
|
||||
}
|
||||
|
||||
if (Error) (Error as any).stackTraceLimit = 100;
|
||||
|
||||
@ -314,7 +314,7 @@ namespace Utils {
|
||||
|
||||
function findChildName(parent: any, child: any) {
|
||||
for (const name in parent) {
|
||||
if (parent.hasOwnProperty(name) && parent[name] === child) {
|
||||
if (ts.hasProperty(parent, name) && parent[name] === child) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@ -916,7 +916,6 @@ namespace vfs {
|
||||
if (this._shadowRoot) {
|
||||
this._copyShadowLinks(this._shadowRoot._getRootLinks(), this._lazy.links);
|
||||
}
|
||||
this._lazy.links = this._lazy.links;
|
||||
}
|
||||
return this._lazy.links;
|
||||
}
|
||||
@ -1578,7 +1577,7 @@ namespace vfs {
|
||||
const entry = normalizeFileSetEntry(container[name]);
|
||||
const file = dirname ? vpath.combine(dirname, name) : name;
|
||||
// eslint-disable-next-line no-null/no-null
|
||||
if (entry === null || entry === undefined || entry instanceof Unlink || entry instanceof Rmdir) {
|
||||
if (entry === null || entry === undefined || entry instanceof Unlink) {
|
||||
text += `//// [${file}] unlink\r\n`;
|
||||
}
|
||||
else if (entry instanceof Rmdir) {
|
||||
|
||||
@ -94,7 +94,7 @@ namespace Playback { // eslint-disable-line local/one-namespace-per-file
|
||||
function memoize<T>(func: (s: string) => T): Memoized<T> {
|
||||
let lookup: { [s: string]: T } = {};
|
||||
const run: Memoized<T> = ((s: string) => {
|
||||
if (lookup.hasOwnProperty(s)) return lookup[s];
|
||||
if (ts.hasProperty(lookup, s)) return lookup[s];
|
||||
return lookup[s] = func(s);
|
||||
}) as Memoized<T>;
|
||||
run.reset = () => {
|
||||
|
||||
@ -940,7 +940,7 @@ namespace ts.server {
|
||||
// raw is now fixed and ready
|
||||
this.safelist = raw.typesMap;
|
||||
for (const key in raw.simpleMap) {
|
||||
if (raw.simpleMap.hasOwnProperty(key)) {
|
||||
if (hasProperty(raw.simpleMap, key)) {
|
||||
this.legacySafelist.set(key, raw.simpleMap[key].toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
@ -297,7 +297,7 @@ namespace ts.server {
|
||||
interface ProjectNavigateToItems {
|
||||
project: Project;
|
||||
navigateToItems: readonly NavigateToItem[];
|
||||
};
|
||||
}
|
||||
|
||||
function createDocumentSpanSet(): Set<DocumentSpan> {
|
||||
return createSet(({textSpan}) => textSpan.start + 100003 * textSpan.length, documentSpansEqual);
|
||||
|
||||
@ -1107,7 +1107,7 @@ namespace ts.Completions {
|
||||
|
||||
return { isSnippet, insertText, labelDetails };
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
function createObjectLiteralMethod(
|
||||
symbol: Symbol,
|
||||
@ -4335,7 +4335,7 @@ namespace ts.Completions {
|
||||
|
||||
function isArrowFunctionBody(node: Node) {
|
||||
return node.parent && isArrowFunction(node.parent) && node.parent.body === node;
|
||||
};
|
||||
}
|
||||
|
||||
/** True if symbol is a type or a module containing at least one type. */
|
||||
function symbolCanBeReferencedAtTypeLocation(symbol: Symbol, checker: TypeChecker, seenModules = new Map<SymbolId, true>()): boolean {
|
||||
|
||||
@ -411,23 +411,23 @@ namespace ts.formatting {
|
||||
}
|
||||
|
||||
function isOptionEnabled(optionName: keyof FormatCodeSettings): (context: FormattingContext) => boolean {
|
||||
return (context) => context.options && context.options.hasOwnProperty(optionName) && !!context.options[optionName];
|
||||
return (context) => context.options && hasProperty(context.options, optionName) && !!context.options[optionName];
|
||||
}
|
||||
|
||||
function isOptionDisabled(optionName: keyof FormatCodeSettings): (context: FormattingContext) => boolean {
|
||||
return (context) => context.options && context.options.hasOwnProperty(optionName) && !context.options[optionName];
|
||||
return (context) => context.options && hasProperty(context.options, optionName) && !context.options[optionName];
|
||||
}
|
||||
|
||||
function isOptionDisabledOrUndefined(optionName: keyof FormatCodeSettings): (context: FormattingContext) => boolean {
|
||||
return (context) => !context.options || !context.options.hasOwnProperty(optionName) || !context.options[optionName];
|
||||
return (context) => !context.options || !hasProperty(context.options, optionName) || !context.options[optionName];
|
||||
}
|
||||
|
||||
function isOptionDisabledOrUndefinedOrTokensOnSameLine(optionName: keyof FormatCodeSettings): (context: FormattingContext) => boolean {
|
||||
return (context) => !context.options || !context.options.hasOwnProperty(optionName) || !context.options[optionName] || context.TokensAreOnSameLine();
|
||||
return (context) => !context.options || !hasProperty(context.options, optionName) || !context.options[optionName] || context.TokensAreOnSameLine();
|
||||
}
|
||||
|
||||
function isOptionEnabledOrUndefined(optionName: keyof FormatCodeSettings): (context: FormattingContext) => boolean {
|
||||
return (context) => !context.options || !context.options.hasOwnProperty(optionName) || !!context.options[optionName];
|
||||
return (context) => !context.options || !hasProperty(context.options, optionName) || !!context.options[optionName];
|
||||
}
|
||||
|
||||
function isForContext(context: FormattingContext): boolean {
|
||||
|
||||
@ -54,7 +54,7 @@ namespace ts.refactor {
|
||||
readonly exportName: Identifier; // This is exportNode.name except for VariableStatement_s.
|
||||
readonly wasDefault: boolean;
|
||||
readonly exportingModuleSymbol: Symbol;
|
||||
};
|
||||
}
|
||||
|
||||
function getInfo(context: RefactorContext, considerPartialSpans = true): ExportInfo | RefactorErrorInfo | undefined {
|
||||
const { file, program } = context;
|
||||
|
||||
@ -51,7 +51,7 @@ namespace ts.refactor.convertToOptionalChainExpression {
|
||||
finalExpression: PropertyAccessExpression | ElementAccessExpression | CallExpression,
|
||||
occurrences: Occurrence[],
|
||||
expression: ValidExpression,
|
||||
};
|
||||
}
|
||||
|
||||
type ValidExpressionOrStatement = ValidExpression | ValidStatement;
|
||||
|
||||
@ -119,7 +119,7 @@ namespace ts.refactor.convertToOptionalChainExpression {
|
||||
function getBinaryInfo(expression: BinaryExpression): OptionalChainInfo | RefactorErrorInfo | undefined {
|
||||
if (expression.operatorToken.kind !== SyntaxKind.AmpersandAmpersandToken) {
|
||||
return { error: getLocaleSpecificMessage(Diagnostics.Can_only_convert_logical_AND_access_chains) };
|
||||
};
|
||||
}
|
||||
const finalExpression = getFinalExpressionInChain(expression.right);
|
||||
|
||||
if (!finalExpression) return { error: getLocaleSpecificMessage(Diagnostics.Could_not_find_convertible_access_expression) };
|
||||
|
||||
@ -5,7 +5,7 @@ namespace ts.refactor {
|
||||
*/
|
||||
export interface RefactorErrorInfo {
|
||||
error: string;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if some refactor info has refactor error info.
|
||||
|
||||
@ -97,7 +97,7 @@ namespace ts.refactor {
|
||||
// Filters imports and prologue directives out of the range of statements to move.
|
||||
// Imports will be copied to the new file anyway, and may still be needed in the old file.
|
||||
// Prologue directives will be copied to the new file and should be left in the old file.
|
||||
return !isPureImport(statement) && !isPrologueDirective(statement);;
|
||||
return !isPureImport(statement) && !isPrologueDirective(statement);
|
||||
}
|
||||
|
||||
function isPureImport(node: Node): boolean {
|
||||
|
||||
@ -935,7 +935,7 @@ namespace ts.Completions.StringCompletions {
|
||||
const dependencies: object | undefined = (contents as any)[key];
|
||||
if (!dependencies) continue;
|
||||
for (const dep in dependencies) {
|
||||
if (dependencies.hasOwnProperty(dep) && !startsWith(dep, "@types/")) {
|
||||
if (hasProperty(dependencies, dep) && !startsWith(dep, "@types/")) {
|
||||
result.push(dep);
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ namespace ts {
|
||||
|
||||
it("verify getOutputFileNames", () => {
|
||||
const sys = new fakes.System(input.fs().makeReadonly(), { executingFilePath: "/lib/tsc" }) as TscCompileSystem;
|
||||
;
|
||||
|
||||
assert.deepEqual(
|
||||
getOutputFileNames(
|
||||
parseConfigFileWithSystem("/src/tsconfig.json", {}, /*extendedConfigCache*/ undefined, {}, sys, noop)!,
|
||||
|
||||
@ -836,7 +836,7 @@ namespace ts.projectSystem {
|
||||
checkAllErrors(request);
|
||||
}
|
||||
|
||||
interface SkipErrors { semantic?: true; suggestion?: true };
|
||||
interface SkipErrors { semantic?: true; suggestion?: true }
|
||||
export interface CheckAllErrors extends VerifyGetErrRequestBase {
|
||||
files: readonly any[];
|
||||
skip?: readonly (SkipErrors | undefined)[];
|
||||
|
||||
@ -567,7 +567,7 @@ namespace ts.projectSystem {
|
||||
path: "/a/b/file1.js",
|
||||
content: "var x = 10;",
|
||||
fileName: "/a/b/file1.js",
|
||||
scriptKind: "JS" as "JS"
|
||||
scriptKind: "JS" as const
|
||||
};
|
||||
|
||||
const host = createServerHost([]);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user