From 559e8f67d35fab3757137af2db1dbd930fd06937 Mon Sep 17 00:00:00 2001 From: Urakov Alexandr Date: Mon, 31 Jul 2023 16:36:02 +0800 Subject: [PATCH] [ArkTS][Linter] Support strict-mode diagnostics Change-Id: I62890c72067888a149314f37418d2ee1e53d9d28 Signed-off-by: Urakov Alexandr --- linter/src/CompilerWrapper.ts | 16 ++- linter/src/LinterRunner.ts | 50 ++++++-- linter/src/Problems.ts | 3 +- linter/src/TypeScriptLinter.ts | 16 +-- linter/src/TypeScriptLinterConfig.ts | 1 + linter/src/Utils.ts | 40 ++++++ .../src/ts-diagnostics/TSCCompiledProgram.ts | 117 ++++++++++++++++++ .../TypeScriptDiagnosticsExtractor.ts | 56 +++++++++ linter/test/array_literals.ts.relax.json | 15 +++ linter/test/array_literals.ts.strict.json | 15 +++ linter/test/delete_operator.ts.relax.json | 5 + linter/test/delete_operator.ts.strict.json | 5 + linter/test/func_def_params.ts.strict.json | 5 + .../func_inferred_type_args.ts.relax.json | 5 + .../func_inferred_type_args.ts.strict.json | 5 + linter/test/functions.ts.autofix.json | 6 + linter/test/functions.ts.relax.json | 5 + linter/test/functions.ts.strict.json | 5 + .../interfaces_optional_props.ts.relax.json | 5 + .../interfaces_optional_props.ts.strict.json | 5 + .../literals_as_prop_names.ts.autofix.json | 24 ++++ .../test/literals_as_prop_names.ts.relax.json | 20 +++ .../literals_as_prop_names.ts.strict.json | 20 +++ linter/test/modules.ts.autofix.json | 6 + linter/test/modules.ts.relax.json | 5 + linter/test/modules.ts.strict.json | 5 + linter/test/object_literals.ts.relax.json | 25 ++++ linter/test/object_literals.ts.strict.json | 25 ++++ .../test/property_runtime_check.ts.relax.json | 5 + .../property_runtime_check.ts.strict.json | 5 + .../test/prototype_assignment.ts.autofix.json | 18 +++ .../test/prototype_assignment.ts.relax.json | 15 +++ .../test/prototype_assignment.ts.strict.json | 15 +++ linter/test/readonly_arr.ts.autofix.json | 12 ++ linter/test/readonly_arr.ts.relax.json | 13 +- linter/test/readonly_arr.ts.strict.json | 10 ++ linter/test/structural_identity.ts.relax.json | 5 + .../test/structural_identity.ts.strict.json | 5 + linter/test/ts_ignore.ts.relax.json | 5 + linter/test/ts_ignore.ts.strict.json | 5 + linter/test/type_declarations.ts.relax.json | 5 + linter/test/type_declarations.ts.strict.json | 5 + linter/test/types.ts.autofix.json | 24 ++++ linter/test/types.ts.relax.json | 20 +++ linter/test/types.ts.strict.json | 20 +++ linter/test/unique_names.ts.relax.json | 15 +++ linter/test/unique_names.ts.strict.json | 15 +++ linter/test/utility_types.ts.relax.json | 5 + linter/test/utility_types.ts.strict.json | 5 + linter/test/var_declarations.ts.relax.json | 5 + linter/test/var_declarations.ts.strict.json | 5 + 51 files changed, 719 insertions(+), 28 deletions(-) create mode 100644 linter/src/ts-diagnostics/TSCCompiledProgram.ts create mode 100644 linter/src/ts-diagnostics/TypeScriptDiagnosticsExtractor.ts diff --git a/linter/src/CompilerWrapper.ts b/linter/src/CompilerWrapper.ts index a92a316b2..080906125 100644 --- a/linter/src/CompilerWrapper.ts +++ b/linter/src/CompilerWrapper.ts @@ -19,11 +19,11 @@ import { consoleLog } from './TypeScriptLinter'; import { CommandLineOptions } from './CommandLineOptions'; import { LintOptions } from './LintOptions'; -export function compile(options: LintOptions, logTscErrors: boolean | undefined): ts.Program { - const createProgramOptions = formTscOptions(options.cmdOptions); +export function compile(options: LintOptions, extraOptions?: any): ts.Program { + const createProgramOptions = formTscOptions(options.cmdOptions, extraOptions); const program = ts.createProgram(createProgramOptions); // Log Tsc errors if needed - if (logTscErrors) { + if (options.cmdOptions.logTscErrors) { const diagnostics = ts.getPreEmitDiagnostics(program); logTscDiagnostic(diagnostics, consoleLog); diagnostics.forEach((diagnostic) => { @@ -39,7 +39,7 @@ export function compile(options: LintOptions, logTscErrors: boolean | undefined) return program; } -function formTscOptions(cmdOptions: CommandLineOptions): ts.CreateProgramOptions { +function formTscOptions(cmdOptions: CommandLineOptions, extraOptions?: any): ts.CreateProgramOptions { if (cmdOptions.parsedConfigFile) { let options: ts.CreateProgramOptions = { rootNames: cmdOptions.parsedConfigFile.fileNames, @@ -48,6 +48,10 @@ function formTscOptions(cmdOptions: CommandLineOptions): ts.CreateProgramOptions configFileParsingDiagnostics: ts.getConfigFileParsingDiagnostics(cmdOptions.parsedConfigFile), }; + if (extraOptions) { + options.options = Object.assign(options.options, extraOptions); + } + return options; } @@ -56,5 +60,9 @@ function formTscOptions(cmdOptions: CommandLineOptions): ts.CreateProgramOptions options: { target: ts.ScriptTarget.Latest, module: ts.ModuleKind.CommonJS, }, }; + if (extraOptions) { + options.options = Object.assign(options.options, extraOptions); + } + return options; } diff --git a/linter/src/LinterRunner.ts b/linter/src/LinterRunner.ts index b6f011133..05191bcfb 100644 --- a/linter/src/LinterRunner.ts +++ b/linter/src/LinterRunner.ts @@ -29,6 +29,8 @@ import { compile } from './CompilerWrapper'; import { CommandLineOptions } from './CommandLineOptions'; import { LintOptions } from './LintOptions'; import { AutofixInfoSet } from './Autofixer'; +import { TSCCompiledProgram, getStrictOptions } from './ts-diagnostics/TSCCompiledProgram'; +import { mergeArrayMaps } from './Utils'; const logger = Logger.getLogger(); @@ -36,7 +38,8 @@ const logger = Logger.getLogger(); export function lint(options: LintOptions): LintRunResult { const cmdOptions = options.cmdOptions; - const tsProgram = options.tsProgram ?? compile(options, cmdOptions.logTscErrors); + const tscDiagnosticsLinter = createLinter(options); + const tsProgram = tscDiagnosticsLinter.getOriginalProgram(); const linter = new TypeScriptLinter( tsProgram.getTypeChecker(), new AutofixInfoSet(cmdOptions.autofixInfo), @@ -63,28 +66,37 @@ export function lint(options: LintOptions): LintRunResult { if (srcFile) srcFiles.push(srcFile); } - let lintResults = lintFiles(srcFiles, linter); + const { errorNodes, problemsInfos } = lintFiles(srcFiles, linter); + const tscProblemsInfos = getTscDiagnostics(tscDiagnosticsLinter, srcFiles); consoleLog('\n\n\nFiles scanned: ', srcFiles.length); - consoleLog('\nFiles with problems: ', lintResults.errorNodes); + consoleLog('\nFiles with problems: ', errorNodes); - let errorNodes = 0, warningNodes = 0; + let errorNodesTotal = 0, warningNodes = 0; for (let i = 0; i < FaultID.LAST_ID; i++) { // if Strict mode - count all cases if (!linter.strictMode && faultsAttrs[i].migratable) // In relax mode skip migratable continue; if (faultsAttrs[i].warning) warningNodes += linter.nodeCounters[i]; - else errorNodes += linter.nodeCounters[i]; + else errorNodesTotal += linter.nodeCounters[i]; } - logTotalProblemsInfo(errorNodes, warningNodes, linter); + logTotalProblemsInfo(errorNodesTotal, warningNodes, linter); logProblemsPercentageByFeatures(linter); return { - errorNodes: errorNodes, - problemsInfos: lintResults.problemsInfos, + errorNodes: errorNodesTotal, + problemsInfos: mergeArrayMaps(problemsInfos, tscProblemsInfos), }; } +export function createLinter(options: LintOptions): TSCCompiledProgram { + if (options.tscDiagnosticsLinter) { + return options.tscDiagnosticsLinter; + } + const tsProgram = options.tsProgram ?? compile(options, getStrictOptions()); + return new TSCCompiledProgram(tsProgram, options); +} + function lintFiles(srcFiles: ts.SourceFile[], linter: TypeScriptLinter): LintRunResult { let problemFiles = 0; let problemsInfos: Map = new Map(); @@ -121,6 +133,28 @@ function lintFiles(srcFiles: ts.SourceFile[], linter: TypeScriptLinter): LintRun }; } +/** + * Extracts TSC diagnostics emitted by strict checks. + * Function might be time-consuming, as it runs second compilation. + * @param sourceFiles AST of the processed files + * @param tscDiagnosticsLinter linter initialized with the processed program + * @returns problems found by TSC, mapped by `ts.SourceFile.fileName` field + */ +function getTscDiagnostics( + tscDiagnosticsLinter: TSCCompiledProgram, + sourceFiles: ts.SourceFile[], +): Map { + const problemsInfos = new Map(); + sourceFiles.forEach(file => { + const problems = tscDiagnosticsLinter.getStrictDiagnostics(file); + if (problems.length != 0) { + logger.info(`Found ${problems.length} TSC strict diagnostics in ${file.fileName}`); + problemsInfos.set(path.normalize(file.fileName), problems); + } + }); + return problemsInfos; +} + function countProblemFiles( nodeCounters: number[], filesNumber: number, tsSrcFile: ts.SourceFile, fileNodes: number, fileErrorLines: number, fileWarningLines: number, linter: TypeScriptLinter, diff --git a/linter/src/Problems.ts b/linter/src/Problems.ts index f4c3f3bd8..efe3cec4a 100644 --- a/linter/src/Problems.ts +++ b/linter/src/Problems.ts @@ -33,7 +33,7 @@ export enum FaultID { InstanceofUnsupported, ShorthandAmbientModuleDecl, WildcardsInModuleName, UMDModuleDefinition, JSExtensionInModuleIdent, NewTarget, DynamicImport, DefiniteAssignment, IifeAsNamespace, Prototype, GlobalThis, UtilityType, PropertyDeclOnFunction, FunctionApplyBindCall, ReadonlyArr, ConstAssertion, ImportAssertion, - BigIntLiteral, SpreadOperator, LimitedStdLibApi, ErrorSuppression, + BigIntLiteral, SpreadOperator, LimitedStdLibApi, ErrorSuppression, StrictDiagnostic, LAST_ID, // this should always be last enum` } @@ -140,3 +140,4 @@ faultsAttrs[FaultID.ConstAssertion] = {cookBookRef: '142',}; faultsAttrs[FaultID.ImportAssertion] = {cookBookRef: '143',}; faultsAttrs[FaultID.LimitedStdLibApi] = {cookBookRef: '144',}; faultsAttrs[FaultID.ErrorSuppression] = {cookBookRef: '146',}; +faultsAttrs[FaultID.StrictDiagnostic] = {cookBookRef: '0'}; diff --git a/linter/src/TypeScriptLinter.ts b/linter/src/TypeScriptLinter.ts index 5dcc8e501..9b7705fb0 100644 --- a/linter/src/TypeScriptLinter.ts +++ b/linter/src/TypeScriptLinter.ts @@ -14,7 +14,7 @@ */ import * as ts from 'typescript'; -import { TsUtils } from './Utils'; +import { TsUtils, getNodeOrLineEnd } from './Utils'; import { FaultID, faultsAttrs } from './Problems'; import { cookBookMsg, cookBookTag } from './CookBookMsg'; import { LinterConfig } from './TypeScriptLinterConfig'; @@ -144,7 +144,7 @@ export class TypeScriptLinter { const badNodeInfo: ProblemInfo = { line: line, column: character, - endColumn: this.getNodeOrLineEnd(node, line), + endColumn: getNodeOrLineEnd(this.sourceFile!, startPos, endPos, line), start: startPos, end: endPos, type: faultType, @@ -440,18 +440,6 @@ export class TypeScriptLinter { } } - /** - * @param node AST node belonging to this `sourceFile` - * @param startLine node's start line - * @returns column index of the node's end if node is located on one line, line's end otherwise - */ - private getNodeOrLineEnd(node: ts.Node | ts.CommentRange, startLine: number): number { - const pos = this.sourceFile!.getLineAndCharacterOfPosition(this.tsUtils.getEndPos(node)); - return pos.line === startLine - ? pos.character - : this.sourceFile!.getLineEndOfPosition(this.tsUtils.getStartPos(node)); - } - private handleObjectLiteralExpression(node: ts.Node) { let objectLiteralExpr = node as ts.ObjectLiteralExpression; diff --git a/linter/src/TypeScriptLinterConfig.ts b/linter/src/TypeScriptLinterConfig.ts index c4cdb8538..80bdfb332 100644 --- a/linter/src/TypeScriptLinterConfig.ts +++ b/linter/src/TypeScriptLinterConfig.ts @@ -126,6 +126,7 @@ export class LinterConfig { LinterConfig.nodeDesc[FaultID.SpreadOperator] = 'Spread operation'; LinterConfig.nodeDesc[FaultID.LimitedStdLibApi] = 'Limited standard library API'; LinterConfig.nodeDesc[FaultID.ErrorSuppression] = 'Error suppression annotation'; + LinterConfig.nodeDesc[FaultID.StrictDiagnostic] = 'Strict diagnostic'; LinterConfig.initTsSyntaxKindNames(); } diff --git a/linter/src/Utils.ts b/linter/src/Utils.ts index 67421d305..4fda6bf6e 100644 --- a/linter/src/Utils.ts +++ b/linter/src/Utils.ts @@ -39,6 +39,46 @@ export function decodeAutofixInfo(info: string): AutofixInfo { return { problemID: infos[0], start: Number.parseInt(infos[1]), end: Number.parseInt(infos[2]) }; } +/** + * @param sourceFile AST of the processed file + * @param nodeStartPos node's start position (`node.getStart()`) + * @param nodeEndPos node's end position (`node.getEnd()`) + * @param nodeStartLine node's start line. NB! line count from 1, in contrast to TSC + * @returns column index of the node's end if node is located on one line, line's end otherwise + */ +export function getNodeOrLineEnd( + sourceFile: ts.SourceFile, + nodeStartPos: number, + nodeEndPos: number, + nodeStartLine: number, +): number { + const pos = sourceFile.getLineAndCharacterOfPosition(nodeEndPos); + // TSC counts lines and columns from zero + return (pos.line + 1) === nodeStartLine + ? pos.character + : sourceFile.getLineEndOfPosition(nodeStartPos); +} + +export function mergeArrayMaps(lhs: Map, rhs: Map): Map { + if (lhs.size == 0) { + return rhs; + } + if (rhs.size == 0) { + return lhs; + } + + rhs.forEach((values, key) => { + if (values.length != 0) { + if (lhs.has(key)) { + lhs.get(key)!.push(...values); + } else { + lhs.set(key, values); + } + } + }); + return lhs; +} + export class TsUtils { static statementKinds = [ ts.SyntaxKind.Block,ts.SyntaxKind.EmptyStatement,ts.SyntaxKind.VariableStatement,ts.SyntaxKind.ExpressionStatement, diff --git a/linter/src/ts-diagnostics/TSCCompiledProgram.ts b/linter/src/ts-diagnostics/TSCCompiledProgram.ts new file mode 100644 index 000000000..b1e531e6a --- /dev/null +++ b/linter/src/ts-diagnostics/TSCCompiledProgram.ts @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as ts from 'typescript'; +import { ProblemInfo } from '../ProblemInfo'; +import { ProblemSeverity } from '../ProblemSeverity'; +import { LintOptions } from '../LintOptions'; +import { TypeScriptDiagnosticsExtractor } from './TypeScriptDiagnosticsExtractor'; +import { compile } from '../CompilerWrapper'; +import { getNodeOrLineEnd } from '../Utils'; +import { FaultID } from '../Problems'; + +export class TSCCompiledProgram { + private diagnosticsExtractor: TypeScriptDiagnosticsExtractor; + private wasStrict: boolean; + + constructor(program: ts.Program, options: LintOptions) { + const { strict, nonStrict, wasStrict } = getTwoCompiledVersions(program, options); + this.diagnosticsExtractor = new TypeScriptDiagnosticsExtractor(strict, nonStrict); + this.wasStrict = wasStrict; + } + + public getOriginalProgram(): ts.Program { + return this.wasStrict + ? this.diagnosticsExtractor.strictProgram + : this.diagnosticsExtractor.nonStrictProgram; + } + + public getStrictDiagnostics(sourceFile: ts.SourceFile): ProblemInfo[] { + return this.diagnosticsExtractor.getStrictDiagnostics(sourceFile) + .map(x => transformDiagnostics(x)); + } +} + +export function getStrictOptions(strict: boolean = true) { + return { + strictNullChecks: strict, + strictFunctionTypes: strict, + strictPropertyInitialization: strict, + noImplicitReturns: strict, + } +} + +function getTwoCompiledVersions( + program: ts.Program, + options: LintOptions, +): { strict: ts.Program; nonStrict: ts.Program; wasStrict: boolean } { + const compilerOptions = { ...program.getCompilerOptions()}; + + const wasStrict = inverseStrictOptions(compilerOptions); + const inversedOptions = getStrictOptions(!wasStrict); + const withInversedOptions = compile(options, inversedOptions); + + return { + strict: wasStrict ? program : withInversedOptions, + nonStrict: wasStrict ? withInversedOptions : program, + wasStrict: wasStrict, + } +} + +/** + * Returns true if options were initially strict + */ +function inverseStrictOptions(compilerOptions: ts.CompilerOptions): boolean { + const strictOptions = getStrictOptions(); + let wasStrict = false; + Object.keys(strictOptions).forEach(x => { + wasStrict = wasStrict || !!compilerOptions[x]; + }); + // wasStrict evaluates true if any of the strict options was set + return wasStrict; +} + +function transformDiagnostics(diagnostic: ts.Diagnostic): ProblemInfo { + const { line, column } = getLineAndColumn(diagnostic); + const startPos = diagnostic.start!; + const endPos = startPos + diagnostic.length!; + // TODO: set correct information & create .md rule description + return { + line: line, + column: column, + endColumn: getNodeOrLineEnd(diagnostic.file!, startPos, endPos, line), + start: startPos, + end: endPos, + type: 'StrictModeError', + severity: ProblemSeverity.ERROR, // expect strict options to always present + problem: FaultID[FaultID.StrictDiagnostic], + suggest: diagnostic.messageText.toString(), + rule: diagnostic.messageText.toString(), + ruleTag: 0, + autofixable: false, + }; +} + +/** + * Returns line and column of the diagnostic's node, counts from 1 + */ +function getLineAndColumn(diagnostic: ts.Diagnostic): { line: number; column: number } { + let { line, character } = diagnostic.file!.getLineAndCharacterOfPosition(diagnostic.start!); + // TSC counts lines and columns from zero + return { + line: line + 1, + column: character + 1, + } +} diff --git a/linter/src/ts-diagnostics/TypeScriptDiagnosticsExtractor.ts b/linter/src/ts-diagnostics/TypeScriptDiagnosticsExtractor.ts new file mode 100644 index 000000000..b02536724 --- /dev/null +++ b/linter/src/ts-diagnostics/TypeScriptDiagnosticsExtractor.ts @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as ts from 'typescript'; + +export class TypeScriptDiagnosticsExtractor { + constructor(public strictProgram: ts.Program, public nonStrictProgram: ts.Program) { + } + + /** + * Returns diagnostics which appear in strict compilation mode only + */ + public getStrictDiagnostics(sourceFile: ts.SourceFile): ts.Diagnostic[] { + const strict = getAllDiagnostics(this.strictProgram, sourceFile); + const nonStrict = getAllDiagnostics(this.nonStrictProgram, sourceFile); + + // collect hashes for later easier comparison + const nonStrictHashes = nonStrict.reduce((result, value) => { + const hash = hashDiagnostic(value); + if (hash) { + result.add(hash); + } + return result; + }, new Set()); + // return diagnostics which weren't detected in non-strict mode + return strict.filter(value => { + const hash = hashDiagnostic(value); + return (hash && !nonStrictHashes.has(hash)); + }); + } +} + +function getAllDiagnostics(program: ts.Program, sourceFile: ts.SourceFile): ts.Diagnostic[] { + return program.getSemanticDiagnostics(sourceFile) + .concat(program.getSyntacticDiagnostics(sourceFile)) + .filter(diag => diag.file === sourceFile); +} + +function hashDiagnostic(diagnostic: ts.Diagnostic): string | undefined { + if (diagnostic.start === undefined || diagnostic.length === undefined) { + return undefined; + } + return `${diagnostic.code}%${diagnostic.start}%${diagnostic.length}`; +} diff --git a/linter/test/array_literals.ts.relax.json b/linter/test/array_literals.ts.relax.json index c026bdf47..bd8629495 100644 --- a/linter/test/array_literals.ts.relax.json +++ b/linter/test/array_literals.ts.relax.json @@ -118,6 +118,21 @@ "line": 126, "column": 30, "problem": "ObjectLiteralNoContextType" + }, + { + "line": 18, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 19, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 20, + "column": 3, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/array_literals.ts.strict.json b/linter/test/array_literals.ts.strict.json index 71304420b..f2aced3ff 100644 --- a/linter/test/array_literals.ts.strict.json +++ b/linter/test/array_literals.ts.strict.json @@ -123,6 +123,21 @@ "line": 126, "column": 30, "problem": "ObjectLiteralNoContextType" + }, + { + "line": 18, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 19, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 20, + "column": 3, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/delete_operator.ts.relax.json b/linter/test/delete_operator.ts.relax.json index 1af2b8cad..2addafd48 100644 --- a/linter/test/delete_operator.ts.relax.json +++ b/linter/test/delete_operator.ts.relax.json @@ -73,6 +73,11 @@ "line": 44, "column": 23, "problem": "DeleteOperator" + }, + { + "line": 44, + "column": 30, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/delete_operator.ts.strict.json b/linter/test/delete_operator.ts.strict.json index 1af2b8cad..2addafd48 100644 --- a/linter/test/delete_operator.ts.strict.json +++ b/linter/test/delete_operator.ts.strict.json @@ -73,6 +73,11 @@ "line": 44, "column": 23, "problem": "DeleteOperator" + }, + { + "line": 44, + "column": 30, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/func_def_params.ts.strict.json b/linter/test/func_def_params.ts.strict.json index 9ef989840..88261a03f 100644 --- a/linter/test/func_def_params.ts.strict.json +++ b/linter/test/func_def_params.ts.strict.json @@ -14,5 +14,10 @@ "limitations under the License." ], "nodes": [ + { + "line": 16, + "column": 1, + "problem": "LimitedReturnTypeInference" + } ] } \ No newline at end of file diff --git a/linter/test/func_inferred_type_args.ts.relax.json b/linter/test/func_inferred_type_args.ts.relax.json index 6138cc504..dcc02fc62 100644 --- a/linter/test/func_inferred_type_args.ts.relax.json +++ b/linter/test/func_inferred_type_args.ts.relax.json @@ -123,6 +123,11 @@ "line": 60, "column": 18, "problem": "TupleType" + }, + { + "line": 61, + "column": 1, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/func_inferred_type_args.ts.strict.json b/linter/test/func_inferred_type_args.ts.strict.json index 6138cc504..dcc02fc62 100644 --- a/linter/test/func_inferred_type_args.ts.strict.json +++ b/linter/test/func_inferred_type_args.ts.strict.json @@ -123,6 +123,11 @@ "line": 60, "column": 18, "problem": "TupleType" + }, + { + "line": 61, + "column": 1, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/functions.ts.autofix.json b/linter/test/functions.ts.autofix.json index 1494a96b1..9e96283aa 100755 --- a/linter/test/functions.ts.autofix.json +++ b/linter/test/functions.ts.autofix.json @@ -208,6 +208,12 @@ "column": 1, "problem": "FunctionContainsThis", "autofixable": false + }, + { + "line": 107, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false } ] } \ No newline at end of file diff --git a/linter/test/functions.ts.relax.json b/linter/test/functions.ts.relax.json index bd460a798..6e7f7d399 100644 --- a/linter/test/functions.ts.relax.json +++ b/linter/test/functions.ts.relax.json @@ -28,6 +28,11 @@ "line": 103, "column": 1, "problem": "FunctionContainsThis" + }, + { + "line": 107, + "column": 3, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/functions.ts.strict.json b/linter/test/functions.ts.strict.json index 66f8cf949..726203465 100644 --- a/linter/test/functions.ts.strict.json +++ b/linter/test/functions.ts.strict.json @@ -123,6 +123,11 @@ "line": 103, "column": 1, "problem": "FunctionContainsThis" + }, + { + "line": 107, + "column": 3, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/interfaces_optional_props.ts.relax.json b/linter/test/interfaces_optional_props.ts.relax.json index 18ac144f5..ce85cb8b4 100644 --- a/linter/test/interfaces_optional_props.ts.relax.json +++ b/linter/test/interfaces_optional_props.ts.relax.json @@ -14,5 +14,10 @@ "limitations under the License." ], "nodes": [ + { + "line": 22, + "column": 34, + "problem": "ObjectLiteralNoContextType" + } ] } \ No newline at end of file diff --git a/linter/test/interfaces_optional_props.ts.strict.json b/linter/test/interfaces_optional_props.ts.strict.json index 18ac144f5..ce85cb8b4 100644 --- a/linter/test/interfaces_optional_props.ts.strict.json +++ b/linter/test/interfaces_optional_props.ts.strict.json @@ -14,5 +14,10 @@ "limitations under the License." ], "nodes": [ + { + "line": 22, + "column": 34, + "problem": "ObjectLiteralNoContextType" + } ] } \ No newline at end of file diff --git a/linter/test/literals_as_prop_names.ts.autofix.json b/linter/test/literals_as_prop_names.ts.autofix.json index 3527aaf74..6fa935a22 100644 --- a/linter/test/literals_as_prop_names.ts.autofix.json +++ b/linter/test/literals_as_prop_names.ts.autofix.json @@ -168,6 +168,30 @@ "column": 13, "problem": "ObjectLiteralNoContextType", "autofixable": false + }, + { + "line": 34, + "column": 11, + "problem": "StrictDiagnostic", + "autofixable": false + }, + { + "line": 35, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false + }, + { + "line": 55, + "column": 12, + "problem": "StrictDiagnostic", + "autofixable": false + }, + { + "line": 56, + "column": 12, + "problem": "StrictDiagnostic", + "autofixable": false } ] } \ No newline at end of file diff --git a/linter/test/literals_as_prop_names.ts.relax.json b/linter/test/literals_as_prop_names.ts.relax.json index 212bf339f..4093c9924 100644 --- a/linter/test/literals_as_prop_names.ts.relax.json +++ b/linter/test/literals_as_prop_names.ts.relax.json @@ -23,6 +23,26 @@ "line": 59, "column": 13, "problem": "ObjectLiteralNoContextType" + }, + { + "line": 34, + "column": 11, + "problem": "StrictDiagnostic" + }, + { + "line": 35, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 55, + "column": 12, + "problem": "StrictDiagnostic" + }, + { + "line": 56, + "column": 12, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/literals_as_prop_names.ts.strict.json b/linter/test/literals_as_prop_names.ts.strict.json index f4cd055c3..da9706e0f 100644 --- a/linter/test/literals_as_prop_names.ts.strict.json +++ b/linter/test/literals_as_prop_names.ts.strict.json @@ -78,6 +78,26 @@ "line": 59, "column": 13, "problem": "ObjectLiteralNoContextType" + }, + { + "line": 34, + "column": 11, + "problem": "StrictDiagnostic" + }, + { + "line": 35, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 55, + "column": 12, + "problem": "StrictDiagnostic" + }, + { + "line": 56, + "column": 12, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/modules.ts.autofix.json b/linter/test/modules.ts.autofix.json index fbb25f5c2..fa89cb438 100755 --- a/linter/test/modules.ts.autofix.json +++ b/linter/test/modules.ts.autofix.json @@ -248,6 +248,12 @@ "column": 7, "problem": "ImportAssignment", "autofixable": false + }, + { + "line": 103, + "column": 10, + "problem": "StrictDiagnostic", + "autofixable": false } ] } \ No newline at end of file diff --git a/linter/test/modules.ts.relax.json b/linter/test/modules.ts.relax.json index cf6083c3a..f5029c0ba 100644 --- a/linter/test/modules.ts.relax.json +++ b/linter/test/modules.ts.relax.json @@ -103,6 +103,11 @@ "line": 114, "column": 7, "problem": "ImportAssignment" + }, + { + "line": 103, + "column": 10, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/modules.ts.strict.json b/linter/test/modules.ts.strict.json index 899f9cd50..d282c25af 100644 --- a/linter/test/modules.ts.strict.json +++ b/linter/test/modules.ts.strict.json @@ -168,6 +168,11 @@ "line": 114, "column": 7, "problem": "ImportAssignment" + }, + { + "line": 103, + "column": 10, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/object_literals.ts.relax.json b/linter/test/object_literals.ts.relax.json index 0ac869033..fc1fdd35c 100644 --- a/linter/test/object_literals.ts.relax.json +++ b/linter/test/object_literals.ts.relax.json @@ -253,6 +253,31 @@ "line": 129, "column": 5, "problem": "ObjectLiteralNoContextType" + }, + { + "line": 22, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 23, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 27, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 29, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 30, + "column": 3, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/object_literals.ts.strict.json b/linter/test/object_literals.ts.strict.json index c4c6f0b2f..d301f9090 100644 --- a/linter/test/object_literals.ts.strict.json +++ b/linter/test/object_literals.ts.strict.json @@ -303,6 +303,31 @@ "line": 129, "column": 5, "problem": "ObjectLiteralNoContextType" + }, + { + "line": 22, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 23, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 27, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 29, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 30, + "column": 3, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/property_runtime_check.ts.relax.json b/linter/test/property_runtime_check.ts.relax.json index 33c5b9a06..97c35791e 100644 --- a/linter/test/property_runtime_check.ts.relax.json +++ b/linter/test/property_runtime_check.ts.relax.json @@ -183,6 +183,11 @@ "line": 110, "column": 7, "problem": "PropertyRuntimeCheck" + }, + { + "line": 17, + "column": 3, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/property_runtime_check.ts.strict.json b/linter/test/property_runtime_check.ts.strict.json index 33c5b9a06..97c35791e 100644 --- a/linter/test/property_runtime_check.ts.strict.json +++ b/linter/test/property_runtime_check.ts.strict.json @@ -183,6 +183,11 @@ "line": 110, "column": 7, "problem": "PropertyRuntimeCheck" + }, + { + "line": 17, + "column": 3, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/prototype_assignment.ts.autofix.json b/linter/test/prototype_assignment.ts.autofix.json index 214ac1d3e..235d8662c 100755 --- a/linter/test/prototype_assignment.ts.autofix.json +++ b/linter/test/prototype_assignment.ts.autofix.json @@ -145,6 +145,24 @@ "column": 20, "problem": "Prototype", "autofixable": false + }, + { + "line": 40, + "column": 5, + "problem": "StrictDiagnostic", + "autofixable": false + }, + { + "line": 47, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false + }, + { + "line": 48, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false } ] } \ No newline at end of file diff --git a/linter/test/prototype_assignment.ts.relax.json b/linter/test/prototype_assignment.ts.relax.json index 44898e571..892b5d4df 100644 --- a/linter/test/prototype_assignment.ts.relax.json +++ b/linter/test/prototype_assignment.ts.relax.json @@ -93,6 +93,21 @@ "line": 53, "column": 20, "problem": "Prototype" + }, + { + "line": 40, + "column": 5, + "problem": "StrictDiagnostic" + }, + { + "line": 47, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 48, + "column": 3, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/prototype_assignment.ts.strict.json b/linter/test/prototype_assignment.ts.strict.json index 3349069b1..2aaead98e 100644 --- a/linter/test/prototype_assignment.ts.strict.json +++ b/linter/test/prototype_assignment.ts.strict.json @@ -123,6 +123,21 @@ "line": 53, "column": 20, "problem": "Prototype" + }, + { + "line": 40, + "column": 5, + "problem": "StrictDiagnostic" + }, + { + "line": 47, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 48, + "column": 3, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/readonly_arr.ts.autofix.json b/linter/test/readonly_arr.ts.autofix.json index 12dc0b60b..bd3479561 100644 --- a/linter/test/readonly_arr.ts.autofix.json +++ b/linter/test/readonly_arr.ts.autofix.json @@ -26,6 +26,18 @@ "replacementText": "string[]" } ] + }, + { + "line": 17, + "column": 12, + "problem": "StrictDiagnostic", + "autofixable": false + }, + { + "line": 18, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false } ] } \ No newline at end of file diff --git a/linter/test/readonly_arr.ts.relax.json b/linter/test/readonly_arr.ts.relax.json index b06227021..ac1284435 100644 --- a/linter/test/readonly_arr.ts.relax.json +++ b/linter/test/readonly_arr.ts.relax.json @@ -13,5 +13,16 @@ "See the License for the specific language governing permissions and", "limitations under the License." ], - "nodes": [] + "nodes": [ + { + "line": 17, + "column": 12, + "problem": "StrictDiagnostic" + }, + { + "line": 18, + "column": 3, + "problem": "StrictDiagnostic" + } + ] } \ No newline at end of file diff --git a/linter/test/readonly_arr.ts.strict.json b/linter/test/readonly_arr.ts.strict.json index 4218e5296..5f11751c5 100644 --- a/linter/test/readonly_arr.ts.strict.json +++ b/linter/test/readonly_arr.ts.strict.json @@ -18,6 +18,16 @@ "line": 21, "column": 19, "problem": "ReadonlyArr" + }, + { + "line": 17, + "column": 12, + "problem": "StrictDiagnostic" + }, + { + "line": 18, + "column": 3, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/structural_identity.ts.relax.json b/linter/test/structural_identity.ts.relax.json index 903c94d19..30c667dac 100755 --- a/linter/test/structural_identity.ts.relax.json +++ b/linter/test/structural_identity.ts.relax.json @@ -43,6 +43,11 @@ "line": 37, "column": 13, "problem": "StructuralIdentity" + }, + { + "line": 37, + "column": 5, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/structural_identity.ts.strict.json b/linter/test/structural_identity.ts.strict.json index 903c94d19..30c667dac 100755 --- a/linter/test/structural_identity.ts.strict.json +++ b/linter/test/structural_identity.ts.strict.json @@ -43,6 +43,11 @@ "line": 37, "column": 13, "problem": "StructuralIdentity" + }, + { + "line": 37, + "column": 5, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/ts_ignore.ts.relax.json b/linter/test/ts_ignore.ts.relax.json index 76b4c6138..a8d64b5a5 100644 --- a/linter/test/ts_ignore.ts.relax.json +++ b/linter/test/ts_ignore.ts.relax.json @@ -28,6 +28,11 @@ "line": 25, "column": 19, "problem": "ErrorSuppression" + }, + { + "line": 18, + "column": 5, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/ts_ignore.ts.strict.json b/linter/test/ts_ignore.ts.strict.json index 76b4c6138..a8d64b5a5 100644 --- a/linter/test/ts_ignore.ts.strict.json +++ b/linter/test/ts_ignore.ts.strict.json @@ -28,6 +28,11 @@ "line": 25, "column": 19, "problem": "ErrorSuppression" + }, + { + "line": 18, + "column": 5, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/type_declarations.ts.relax.json b/linter/test/type_declarations.ts.relax.json index 9bb0205d9..ef4475e80 100644 --- a/linter/test/type_declarations.ts.relax.json +++ b/linter/test/type_declarations.ts.relax.json @@ -63,6 +63,11 @@ "line": 96, "column": 13, "problem": "AnyType" + }, + { + "line": 42, + "column": 11, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/type_declarations.ts.strict.json b/linter/test/type_declarations.ts.strict.json index bf5339e00..27aaac088 100644 --- a/linter/test/type_declarations.ts.strict.json +++ b/linter/test/type_declarations.ts.strict.json @@ -73,6 +73,11 @@ "line": 96, "column": 13, "problem": "AnyType" + }, + { + "line": 42, + "column": 11, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/types.ts.autofix.json b/linter/test/types.ts.autofix.json index 54f54a35a..ef7f93ac4 100644 --- a/linter/test/types.ts.autofix.json +++ b/linter/test/types.ts.autofix.json @@ -340,6 +340,30 @@ "replacementText": "x: T" } ] + }, + { + "line": 106, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false + }, + { + "line": 148, + "column": 3, + "problem": "StrictDiagnostic", + "autofixable": false + }, + { + "line": 149, + "column": 18, + "problem": "StrictDiagnostic", + "autofixable": false + }, + { + "line": 150, + "column": 17, + "problem": "StrictDiagnostic", + "autofixable": false } ] } \ No newline at end of file diff --git a/linter/test/types.ts.relax.json b/linter/test/types.ts.relax.json index 2a6cbf9a6..77ee7275e 100644 --- a/linter/test/types.ts.relax.json +++ b/linter/test/types.ts.relax.json @@ -178,6 +178,26 @@ "line": 128, "column": 18, "problem": "ObjectLiteralNoContextType" + }, + { + "line": 106, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 148, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 149, + "column": 18, + "problem": "StrictDiagnostic" + }, + { + "line": 150, + "column": 17, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/types.ts.strict.json b/linter/test/types.ts.strict.json index 47a59aca9..dba26d032 100644 --- a/linter/test/types.ts.strict.json +++ b/linter/test/types.ts.strict.json @@ -233,6 +233,26 @@ "line": 139, "column": 22, "problem": "ArrowFunctionWithOmittedTypes" + }, + { + "line": 106, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 148, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 149, + "column": 18, + "problem": "StrictDiagnostic" + }, + { + "line": 150, + "column": 17, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/unique_names.ts.relax.json b/linter/test/unique_names.ts.relax.json index 854cc77a7..d468701cf 100644 --- a/linter/test/unique_names.ts.relax.json +++ b/linter/test/unique_names.ts.relax.json @@ -53,6 +53,21 @@ "line": 134, "column": 19, "problem": "ObjectLiteralNoContextType" + }, + { + "line": 163, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 164, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 173, + "column": 3, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/unique_names.ts.strict.json b/linter/test/unique_names.ts.strict.json index e868237f3..3b6a44084 100644 --- a/linter/test/unique_names.ts.strict.json +++ b/linter/test/unique_names.ts.strict.json @@ -353,6 +353,21 @@ "line": 174, "column": 3, "problem": "PrivateIdentifier" + }, + { + "line": 163, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 164, + "column": 3, + "problem": "StrictDiagnostic" + }, + { + "line": 173, + "column": 3, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/utility_types.ts.relax.json b/linter/test/utility_types.ts.relax.json index ab7e78c41..a68bcd54d 100644 --- a/linter/test/utility_types.ts.relax.json +++ b/linter/test/utility_types.ts.relax.json @@ -59,6 +59,11 @@ "column": 35, "problem": "ObjectLiteralNoContextType" }, + { + "line": 50, + "column": 22, + "problem": "ObjectLiteralNoContextType" + }, { "line": 51, "column": 15, diff --git a/linter/test/utility_types.ts.strict.json b/linter/test/utility_types.ts.strict.json index 1e9011455..06d9ddc09 100644 --- a/linter/test/utility_types.ts.strict.json +++ b/linter/test/utility_types.ts.strict.json @@ -64,6 +64,11 @@ "column": 35, "problem": "ObjectLiteralNoContextType" }, + { + "line": 50, + "column": 22, + "problem": "ObjectLiteralNoContextType" + }, { "line": 51, "column": 15, diff --git a/linter/test/var_declarations.ts.relax.json b/linter/test/var_declarations.ts.relax.json index fa5ed280b..87eabb4e1 100644 --- a/linter/test/var_declarations.ts.relax.json +++ b/linter/test/var_declarations.ts.relax.json @@ -18,6 +18,11 @@ "line": 31, "column": 3, "problem": "ForInStatement" + }, + { + "line": 23, + "column": 12, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file diff --git a/linter/test/var_declarations.ts.strict.json b/linter/test/var_declarations.ts.strict.json index 4cabc048c..fd22371de 100644 --- a/linter/test/var_declarations.ts.strict.json +++ b/linter/test/var_declarations.ts.strict.json @@ -53,6 +53,11 @@ "line": 37, "column": 8, "problem": "VarDeclaration" + }, + { + "line": 23, + "column": 12, + "problem": "StrictDiagnostic" } ] } \ No newline at end of file -- Gitee