OfficeDev / OfficeDev/Office-Addin-Scripts

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

Open
#877 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs triage
Dominant language
TypeScript
Stars
194
Forks
117
Avg merge
1d 32m
Merged PRs (30d)
2

Description

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.

  • Operating System: macOS 14.5
  • Node version: v22.4.1
  • Office version: Microsoft Excel Version 16.87 (24071426)
  • Tool version: eslint-plugin-office-addins@3.0.2

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the load-object-before-read rule and reproduce the ClientResult example from the issue, including awaiting context.sync() before reading value. The work is done when the rule no longer reports an error for that access pattern while continuing to check ordinary objects that require an explicit load.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.