mirror of
https://github.com/hanzoai/azure-sdk-for-js.git
synced 2026-10-30 19:51:51 +00:00
### Packages impacted by this PR
- `@azure/eslint-plugin-azure-sdk` (the actual guardrail)
- `@azure-rest/ai-inference` and `@azure/communication-chat` (real
dependency bugs the new rule caught)
- `@azure/monitor-opentelemetry`, `@azure/loadtesting/playwright`
(grandfathered in their `eslint.config.mjs`)
### Describe the problem that is addressed by this PR
There is nothing preventing developers from using a dependency that is
either undeclared or devDependency in shipped SDK code.
Ideally we'd want to make sure dependencies are approved, versioned
correctly, and are installed when the package that uses them is
installed.
As an example:
```ts
_require = nodeModule.createRequire(import.meta.url);
_otel = _require("@opentelemetry/api");
```
In the above:
- devDependency (works in tests but not in shipped code)
- unversioned local install (may be major version ahead)
- missing package entirely (throws)
Are all possible outcomes which we want to avoid.
This PR adds two `src/**`-scoped lint rules to the shared config:
- **`no-restricted-syntax`** - bans `createRequire()` and aliasing the
global `require` in production source. The message points folks at a
plain static import.
- **`import-x/no-extraneous-dependencies`** (`devDependencies: false`,
`includeTypes: false`) - bans runtime value imports of
`devDependency`-only packages from `src/`.
While turning the second rule on I ran it across the whole repo and it
caught two genuine bugs: `@azure-rest/ai-inference` and
`@azure/communication-chat` both use `@azure/core-util` at runtime
(`isError`, `getErrorMessage`, `randomUUID`) but only declared it as a
`devDependency` (probably came along for the ride with
core-rest-pipeline or core-client). Those are fixed here (moved to
`dependencies`).
A few packages will continue to have this rule disabled:
`monitor-opentelemetry`, and `loadtesting/playwright` - legitimate
advanced uses
---------
Co-authored-by: Copilot <[email protected]>