Skip to content

eslint-plugin-office-addins: Include globals in the recommended config #999

Description

@alainbryden

The recommended config exported by eslint-plugin-office-addins doesn't appear to declare the Office.js runtime globals — Excel, Office, OfficeExtension, OfficeRuntime, Word, PowerPoint, OneNote, etc.

If my understanding is correct, this means every consumer of the plugin has to manually add these to their ESLint config to avoid no-undef errors where they reference them:

// eslint.config.mjs
{
  languageOptions: {
    globals: {
      Excel: "readonly",
      Office: "readonly",
      OfficeExtension: "readonly",
      OfficeRuntime: "readonly",
     // ...
    },
  },
}

Suggested Change
I believe the recommended config should include these globals, so that new Office Add-in projects work out of the box without requiring developers to discover and manually declare each Office.js namespace they use in their globals. I think this just means adding a languageOptions.globals block to the exported "recommended" flat config array, e.g.:

{
  languageOptions: {
    globals: {
      Excel: "readonly",
      Office: "readonly",
      OfficeExtension: "readonly",
      OfficeRuntime: "readonly",
      Word: "readonly",
      PowerPoint: "readonly",
      OneNote: "readonly",
      Visio: "readonly",
    },
  },
}

Rationale
I'm a JS novice, so forgive me if this is incorrect, but it seems that unlike a lot of npm packages, Office.js is designed to be a global-injected library, not a module. That is to say, there is no import { Excel } from 'office-js' alternative - it's necessarily loaded via a <script> tag, such as

<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js">

at which point it injects Office, Excel, Word, OfficeExtension, etc. namespaces onto window.

This means that where these globals are referenced in js/ts/vue files, there would be no other way to inform ESLint that these types are legitimate and "in scope".

Hope that makes sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions