Skip to content

Commit

Permalink
fix(BindingStrings): Improve line/column info in JS/TS
Browse files Browse the repository at this point in the history
  • Loading branch information
maxreichmann committed Feb 3, 2025
1 parent 89fd78d commit 5b32027
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/linter/binding/BindingLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ export default class BindingLinter {
}
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
this.#context.addLintingMessage(this.#resourcePath, MESSAGE.PARSING_ERROR, {message}, position);
if (err instanceof Error) {
this.#context.addLintingMessage(this.#resourcePath, MESSAGE.PARSING_ERROR, {message}, position);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/linter/ui5Types/SourceFileLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ export default class SourceFileLinter {

const nodeSourceMap = this.sourceMaps?.get(this.resourcePath);
const {start: nodePos} = getPositionsForNode({
node: node,
node: node.initializer,
sourceFile: this.sourceFile,
resourcePath: this.resourcePath,
traceMap: nodeSourceMap ? new TraceMap(nodeSourceMap) : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sap.ui.define(
// Although the formatter property does not look like a global notation,
// it should still be detected if it is a string:
const input2 = new Input({
value: "{ path: 'invoice>Status', formatter: 'formatter.statusText' }"
value: "{ path: 'invoice>Status', formatter: formatter.statusText }"
});
}
);
19 changes: 10 additions & 9 deletions test/lib/linter/rules/snapshots/NoGlobals.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,32 @@ Generated by [AVA](https://avajs.dev).
{
coverageInfo: [],
errorCount: 3,
fatalErrorCount: 0,
fatalErrorCount: 1,
filePath: 'FormatterGlobalBindingString.js',
messages: [
{
column: 4,
column: 11,
line: 6,
message: 'Access of global variable \'ui5\' (ui5.walkthrough.model.formatter.statusText)',
messageDetails: 'Do not use global variables to access UI5 modules or APIs. See Best Practices for Developers (https://ui5.sap.com/#/topic/28fcd55b04654977b63dacbee0552712)',
ruleId: 'no-globals',
severity: 2,
},
{
column: 4,
column: 11,
line: 9,
message: 'Access of global variable \'ui5\' (ui5.walkthrough.model.formatter.statusText)',
messageDetails: 'Do not use global variables to access UI5 modules or APIs. See Best Practices for Developers (https://ui5.sap.com/#/topic/28fcd55b04654977b63dacbee0552712)',
ruleId: 'no-globals',
severity: 2,
},
{
column: 4,
column: 11,
fatal: true,
line: 15,
message: 'Access of global variable \'formatter\' (formatter.statusText)',
messageDetails: 'Do not use global variables to access UI5 modules or APIs. See Best Practices for Developers (https://ui5.sap.com/#/topic/28fcd55b04654977b63dacbee0552712)',
ruleId: 'no-globals',
message: 'Expected \'a\' instead of \'o\'',
messageDetails: 'Check the source file for syntax errors',
ruleId: 'parsing-error',
severity: 2,
},
],
Expand Down Expand Up @@ -228,15 +229,15 @@ Generated by [AVA](https://avajs.dev).
filePath: 'ModelDataTypes_NewString.js',
messages: [
{
column: 3,
column: 10,
line: 3,
message: 'Access of global variable \'sap\' (sap.ui.model.type.Integer)',
messageDetails: 'Do not use global variables to access UI5 modules or APIs. See Best Practices for Developers (https://ui5.sap.com/#/topic/28fcd55b04654977b63dacbee0552712)',
ruleId: 'no-globals',
severity: 2,
},
{
column: 3,
column: 10,
line: 7,
message: 'Access of global variable \'sap\' (sap.ui.model.type.Integer)',
messageDetails: 'Do not use global variables to access UI5 modules or APIs. See Best Practices for Developers (https://ui5.sap.com/#/topic/28fcd55b04654977b63dacbee0552712)',
Expand Down
Binary file modified test/lib/linter/rules/snapshots/NoGlobals.ts.snap
Binary file not shown.

0 comments on commit 5b32027

Please sign in to comment.