Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Onnxruntime ESLintConfig

From Leeroopedia
Revision as of 15:46, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Microsoft_Onnxruntime_ESLintConfig.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains JavaScript, Linting, Configuration
Last Updated 2026-02-10 04:00 GMT

Overview

The ESLint flat configuration for the ONNX Runtime JavaScript/TypeScript packages, defining linting rules, plugins, and per-directory overrides for the web, node, common, and React Native modules.

Description

The `eslint.config.mjs` file defines the ESLint configuration for all TypeScript code in the ONNX Runtime JavaScript workspace using the ESLint 9 flat config format. Key aspects:

  • Plugins: Integrates `@typescript-eslint`, `eslint-plugin-prefer-arrow`, `eslint-plugin-header`, `eslint-plugin-import`, `eslint-plugin-unicorn`, and `eslint-plugin-jsdoc`. The header plugin has a workaround for ESLint 9 compatibility (`header.rules.header.meta.schema = false`).
  • Global ignores: Excludes `*.js`, `*.mjs`, `node_modules/`, `ort-schema/`, `dist/`, `test/data/`, type test files, and the config file itself.
  • Base configuration: Extends `eslint:recommended`, `@typescript-eslint/eslint-recommended`, and `@typescript-eslint/recommended` using `FlatCompat`.
  • Core rules (applied to all TS files):
 - Header enforcement: Microsoft copyright header required on all files.
 - Import rules: No extraneous dependencies, no internal module imports (except `**/lib/**`), no unassigned imports.
 - TypeScript rules: Array type (`array-simple`), await-thenable, naming conventions, no-empty-function, no-explicit-any, no-floating-promises, no-for-in-array, promise-function-async, restrict-plus-operands.
 - Style rules: camelcase, curly, eqeqeq (smart), no-bitwise, no-console, no-eval, no-var, prefer-const, prefer-arrow-functions, etc.
  • Per-directory overrides:
 - `node/**/*.ts`: Adds Node.js globals.
 - `common/lib/**/*.ts`, `node/lib/**/*.ts`: Enables jsdoc alignment and indentation checks.
 - `common/test/**/*.ts`: Relaxes naming conventions and import restrictions.
 - `node/script/**/*.ts`, `node/test/**/*.ts`, `web/script/**/*.ts`, `web/test/**/*.ts`: Relaxes many rules for test/script files (allows any types, console, non-arrow functions).
 - `web/lib/**/*.ts`: Allows specific ORT C API underscore-prefixed identifiers (`_OrtCreateSession`, `_OrtRun`, etc.).
 - `web/lib/onnxjs/**/*.ts`: Relaxes rules for legacy ONNX.js code.
 - `react_native/**/*.ts`: Various relaxations for React Native code.
 - `web/lib/**/3rd-party/**/*.ts`: Disables header and filename-case rules for third-party code.

Usage

This configuration is used by the ESLint tooling in the `js/` workspace to enforce code quality and consistency across all ONNX Runtime JavaScript/TypeScript packages.

Code Reference

Source Location

Signature

import typescriptEslint from '@typescript-eslint/eslint-plugin';
import preferArrow from 'eslint-plugin-prefer-arrow';
import header from 'eslint-plugin-header';
import _import from 'eslint-plugin-import';
import unicorn from 'eslint-plugin-unicorn';
import jsdoc from 'eslint-plugin-jsdoc';
import { fixupPluginRules } from '@eslint/compat';
import tsParser from '@typescript-eslint/parser';

export default [
  { ignores: ['**/*.js', '**/*.mjs', '**/node_modules/', '**/dist/'] },
  ...compat.extends('eslint:recommended', 'plugin:@typescript-eslint/recommended'),
  {
    plugins: { '@typescript-eslint': typescriptEslint, 'prefer-arrow': preferArrow,
               header, import: fixupPluginRules(_import), unicorn, jsdoc },
    rules: {
      'header/header': [2, 'line', [' Copyright (c) Microsoft Corporation...']],
      '@typescript-eslint/no-explicit-any': 'error',
      '@typescript-eslint/no-floating-promises': 'error',
      // ... 50+ rules ...
    },
  },
  // Per-directory overrides for node, web, common, react_native, scripts
];

Import

// Run ESLint from the js/ directory:
// npx eslint --config eslint.config.mjs "**/*.ts"

I/O Contract

Override Scope Key Changes Description
Default (all TS) Strict rules: no-any, no-floating-promises, header required Core quality enforcement
node/**/*.ts Node.js globals added Server-side Node.js code
common/lib, node/lib jsdoc check-alignment, check-indentation Library code documentation standards
test/script files Many rules relaxed (any, console, naming) Test and script flexibility
web/lib/**/*.ts Underscore-dangle allowed for ORT C API bindings WASM binding identifiers
3rd-party code Header and filename-case disabled External code exemptions

Usage Examples

// Run linting on the JS workspace
// cd js && npx eslint .

// The config enforces rules like:
// 1. Microsoft copyright header on every file
// 2. No explicit 'any' type in production code
// 3. Arrow function preference
// 4. camelCase naming convention
// 5. No floating promises (must be awaited or void)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment