Skip to content

Commit

Permalink
fix: Fatal error while analyzing JSONModel#loadData with 2 or 5 argum…
Browse files Browse the repository at this point in the history
…ents

When analyzing calls of JSONModel#loadData that use 2 or 5 arguments, a
fatal error 'Cannot read properties of undefined (reading 'kind')' was
reported for the entire file.
  • Loading branch information
RandomByte committed Sep 30, 2024
1 parent 6545780 commit 8f99ebf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
11 changes: 9 additions & 2 deletions src/linter/ui5Types/SourceFileLinter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import ts, {Identifier} from "typescript";
import path from "node:path/posix";
import {getLogger} from "@ui5/logger";
import SourceFileReporter from "./SourceFileReporter.js";
import LinterContext, {ResourcePath, CoverageCategory} from "../LinterContext.js";
import {MESSAGE} from "../messages.js";
import analyzeComponentJson from "./asyncComponentFlags.js";
import {deprecatedLibraries} from "../../utils/deprecations.js";
import {getPropertyName} from "./utils.js";

const log = getLogger("linter:ui5Types:SourceFileLinter");

interface DeprecationInfo {
symbol: ts.Symbol;
messageDetails: string;
Expand Down Expand Up @@ -73,6 +76,10 @@ export default class SourceFileLinter {
this.#reporter.deduplicateMessages();
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
log.verbose(`Error while linting ${this.#resourcePath}: ${message}`);
if (err instanceof Error) {
log.verbose(`Call stack: ${err.stack}`);
}
this.#context.addLintingMessage(this.#resourcePath, MESSAGE.PARSING_ERROR, {message});
}
}
Expand Down Expand Up @@ -497,7 +504,7 @@ export default class SourceFileLinter {
}

#analyzeJsonModelLoadDataCall(node: ts.CallExpression) {
if (!node.arguments.length || node.arguments.length < 2) {
if (!node.arguments.length || node.arguments.length < 3) {
return;
}

Expand All @@ -508,7 +515,7 @@ export default class SourceFileLinter {
}, asyncArg);
}

if (node.arguments.length < 5) {
if (node.arguments.length < 6) {
return;
}
const cacheArg = node.arguments[5];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ sap.ui.define([
getParam(); // (deprecated since 1.92) If no parameter is given

var jsonModel = new JSONModel();
jsonModel.loadData("/api/users", undefined); // No deprecation
jsonModel.loadData("/api/users", undefined, false); // Parameter bAsync is deprecated as of Version 1.107 (default=true)
jsonModel.loadData("/api/users", undefined, true, "GET", false, false); // Parameter bCache is deprecated as of Version 1.107 (default=true)

Expand Down
22 changes: 11 additions & 11 deletions test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -1003,87 +1003,87 @@ Generated by [AVA](https://avajs.dev).
},
{
column: 46,
line: 25,
line: 26,
message: 'Usage of deprecated value for parameter \'bAsync\' of \'sap/ui/model/json/JSONModel#loadData\'',
messageDetails: 'Parameter \'bAsync\' must be either omitted or set to true. See API reference (https://ui5.sap.com/1.120/#/api/sap.ui.model.json.JSONModel%23methods/loadData)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 66,
line: 26,
line: 27,
message: 'Usage of deprecated value for parameter \'bCache\' of \'sap/ui/model/json/JSONModel#loadData\'',
messageDetails: 'Parameter \'bCache\' must be either omitted or set to true. See API reference (https://ui5.sap.com/1.120/#/api/sap.ui.model.json.JSONModel%23methods/loadData)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 3,
line: 29,
line: 30,
message: 'Usage of deprecated parameter \'synchronizationMode\' of constructor \'sap/ui/model/odata/v4/ODataModel\'',
messageDetails: 'As of version 1.110.0, the \'synchronizationMode\' parameter is obsolete and must be omitted. See the API reference (https://ui5.sap.com/1.120/#/api/sap/ui/model/odata/v4/ODataModel#constructor)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 3,
line: 32,
line: 33,
message: 'Usage of deprecated parameter \'synchronizationMode\' of constructor \'sap/ui/model/odata/v4/ODataModel\'',
messageDetails: 'As of version 1.110.0, the \'synchronizationMode\' parameter is obsolete and must be omitted. See the API reference (https://ui5.sap.com/1.120/#/api/sap/ui/model/odata/v4/ODataModel#constructor)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 3,
line: 40,
line: 41,
message: 'Usage of deprecated parameter \'batchGroupId\' in \'sap/ui/model/odata/v2/ODataModel#createEntry\'',
messageDetails: 'Use the \'groupId\' parameter instead. See the API reference (https://ui5.sap.com/1.120/#/api/sap.ui.model.odata.v2.ODataModel%23methods/createEntry)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 3,
line: 41,
line: 42,
message: 'Usage of deprecated value for parameter \'properties\' in \'sap/ui/model/odata/v2/ODataModel#createEntry\'',
messageDetails: 'Passing a list of property names is deprecated. Pass the initial values as an object instead. See the API reference (https://ui5.sap.com/1.120/#/api/sap.ui.model.odata.v2.ODataModel%23methods/createEntry)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 4,
line: 53,
line: 54,
message: 'Usage of deprecated value for parameter \'async\' of \'sap/ui/core/Component#createComponent\'',
messageDetails: 'The \'async\' property must be either omitted or set to true. See the API reference (https://ui5.sap.com/1.120/#/api/sap.ui.core.Component%23methods/createComponent)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 2,
line: 68,
line: 69,
message: 'Usage of deprecated value for parameter \'oConfig.async\' of constructor \'sap/ui/core/Router\'',
messageDetails: 'The \'oConfig.async\' parameter must be set to true. See the API reference (https://ui5.sap.com/1.120/#/api/sap/ui/core/routing/Router#constructor)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 2,
line: 69,
line: 70,
message: 'Usage of deprecated value for parameter \'oConfig.async\' of constructor \'sap/ui/core/Router\'',
messageDetails: 'The \'oConfig.async\' parameter must be set to true. See the API reference (https://ui5.sap.com/1.120/#/api/sap/ui/core/routing/Router#constructor)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 3,
line: 73,
line: 74,
message: 'Usage of deprecated value for parameter \'homeIcon\' of \'sap/ui/util/Mobile#init\'',
messageDetails: 'Parameter \'homeIcon\' must be either omitted or set to true. See API reference (https://ui5.sap.com/1.120/#/api/sap.ui.util.Mobile%23methods/init)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 3,
line: 74,
line: 75,
message: 'Usage of deprecated value for parameter \'homeIconPrecomposed\' of \'sap/ui/util/Mobile#init\'',
messageDetails: 'Parameter \'homeIconPrecomposed\' must be either omitted or set to true. See API reference (https://ui5.sap.com/1.120/#/api/sap.ui.util.Mobile%23methods/init)',
ruleId: 'no-deprecated-api',
Expand Down
Binary file modified test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.snap
Binary file not shown.

0 comments on commit 8f99ebf

Please sign in to comment.