OfficeDev / Office-Addin-Scripts

A set of scripts and packages that are consumed in Office add-ins projects.
MIT License
159 stars 100 forks source link

eslint-plugin-office-addins: load-object-before-read doesn't understand ClientResult #877

Open yoonbuck opened 4 months ago

yoonbuck commented 4 months ago

Expected behavior

When using a ClientResult, calling load is not required (in fact there is no load()) – instead context.sync() is sufficient to make its value available.

The load-object-before-read rule should understand this exception and not show an error in this situation.

Current behavior

The load-object-before-read rule shows an error where value is accessed on a ClientResult, even after awaiting context.sync().

Note that the code works fine in Office, this is only an error in the linter.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Attempt to use a ClientResult's value after awaiting context.sync() (example code below)

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

Failure Logs

A simple test case based on the example on the documentation page for ClientResult:

const tableCount = context.workbook.tables.getCount();

// This sync call implicitly loads tableCount.value.
// Any other ClientResult values are loaded too.
await context.sync();

console.log(tableCount.value); // eslint error: An explicit load call on 'tableCount' for property 'value' needs to be made before the property can be read.
image

Seems to be the same issue as someone is experiencing here: https://stackoverflow.com/questions/78191843/do-we-need-to-call-load-before-reading-ooxml-of-an-api-object