@hubspot/eslint-config-ui-extensions package provides ESLint rules specifically designed for HubSpot UI extensions, and catches common issues like using unavailable browser APIs, incorrect imports, and other patterns that won’t work in the sandboxed web worker context.
It’s recommended to set up ESLint with this configuration when starting a new UI extensions project, but can be implemented at any time.
Installation
Install ESLint 9+ alongside this package:package.json has "type": "module" set, then add a lint script:
npm run lint to check for linting issues.
Recommended setup
The basic config above only includes HubSpot UI extensions-specific rules. For a production-ready setup, it’s recommended that you add standard ESLint rules, TypeScript support, React Hooks linting, Prettier compatibility, and unused import detection.Install additional dependencies
Full config
What each addition provides
| Package | Purpose |
|---|---|
@eslint/js | ESLint’s built-in recommended rules for catching common JavaScript issues |
typescript-eslint | TypeScript parsing and linting rules (stylistic adds consistent code style enforcement) |
eslint-plugin-react | React-specific rules; jsx-runtime config is for React 17+ (no need to import React in every file) |
eslint-plugin-react-hooks | Enforces Rules of Hooks and verifies dependency arrays |
eslint-config-prettier | Disables ESLint rules that conflict with Prettier formatting |
eslint-plugin-unused-imports | Auto-fixable detection and removal of unused imports |
JavaScript-only projects
If you’re not using TypeScript, you can simplify the config:Rules
The rules included in the shared config from@hubspot/eslint-config-ui-extensions are enabled by default, and should always be enabled when building UI extensions.
| Name | Description |
|---|---|
| no-browser-dialogs | Prevent usage of native browser dialog APIs (alert, confirm, and prompt) in UI extensions. |
| no-browser-storage | Prevent usage of browser storage APIs (localStorage and sessionStorage) in UI extensions, which run in a sandboxed web worker environment where these APIs are not available. |
| no-console | Prevent usage of console methods in UI extensions in favor of the SDK logger utility. |
| no-dom-access | Prevent access to the DOM (document object) in UI extensions, which run in a sandboxed web worker without DOM access. |
| no-html-elements | Disallow usage of unsupported HTML elements in UI extensions. |
| no-invalid-extension-point-imports | Prevent importing components from unsupported extension points. |
| no-invalid-image-src | Only allow valid image URLs in the src attribute of Image components from @hubspot/ui-extensions. |
| no-native-http | Prevent usage of native browser HTTP APIs (fetch and XMLHttpRequest) in UI extensions. |
| no-parent-imports | Prevent importing files from outside the extension point root directory. This rule can be automatically fixed by the --fix CLI option. |
| no-restricted-globals | Prevent usage of browser globals that are not available in the sandboxed web worker environment. |