Skip to content

Quickstart

Installation

Install the plugin from npm:

bash
npm install --save-dev import-integrity-lint

ESLint

Single package

For a single-package codebase, the configuration is minimal:

js
import { defineConfig } from 'eslint/config';
import importIntegrityPlugin from 'import-integrity-lint';

export default defineConfig([
  {
    settings: {
      'import-integrity': {
        packageRootDir: import.meta.dirname,
      },
    },
  },
  importIntegrityPlugin.configs.recommended,
]);

This enables the recommended ruleset and points Import Integrity at the current directory as the package root. Combine with your usual TypeScript parser setup if you have one.

Monorepo

For monorepos with a single root config, switch to monorepoRecommended and use monorepoRootDir instead of packageRootDir. A root config typically also needs a couple of additional pieces to coexist with code written primarily for the package-level config.

js
import { defineConfig } from 'eslint/config';
import importIntegrityPlugin from 'import-integrity-lint';
import tseslint from 'typescript-eslint';

export default defineConfig([
  {
    settings: {
      'import-integrity': {
        monorepoRootDir: import.meta.dirname,
      },
    },
  },
  importIntegrityPlugin.configs.monorepoRecommended,
  {
    files: ['**/*.{ts,tsx,mts,cts}'],
    languageOptions: {
      parser: tseslint.parser,
    },
    linterOptions: {
      // This minimal config produces many false positives for unused
      // disable directives, since they likely are used in package-specific
      // configs. We disable the check to avoid noise.
      reportUnusedDisableDirectives: 'off',
    },
    plugins: {
      // We have to enable the typescript-eslint plugin so eslint-disable
      // pragmas point to valid rules, even if they aren't enabled
      '@typescript-eslint': tseslint.plugin,
      // Enable any other plugins used in package-specific configs here
    },
  },
]);

A few notes:

  • monorepoRecommended includes the cross-package rules like no-unused-package-exports
  • monorepoRootDir points at the monorepo root; individual package roots are auto-discovered

For more on monorepo setup, including the alternative one-config-per-package pattern, see Monorepos.

For a full working example, see this repo's own eslint.config.mjs.

Oxlint

Single package

For a single-package codebase:

js
import importIntegrityPlugin from 'import-integrity-lint';

export default {
  settings: {
    'import-integrity': {
      packageRootDir: import.meta.dirname,
    },
  },
  jsPlugins: [
    {
      name: 'import-integrity',
      specifier: 'import-integrity-lint',
    },
  ],
  rules: {
    ...importIntegrityPlugin.configs.recommended.rules,
  },
};

Monorepo

For monorepos with a single root config, switch to monorepoRecommended and use monorepoRootDir. A root config typically also needs a couple of additional pieces to coexist with code written primarily for the package-level config.

js
import importIntegrityPlugin from 'import-integrity-lint';

export default {
  settings: {
    'import-integrity': {
      monorepoRootDir: import.meta.dirname,
    },
  },
  options: {
    // This minimal config produces many false positives for unused
    // disable directives, since they likely are used in package-specific
    // configs. We disable the check to avoid noise.
    reportUnusedDisableDirectives: 'off',
  },
  jsPlugins: [
    {
      name: 'import-integrity',
      specifier: 'import-integrity-lint',
    },
  ],
  rules: {
    ...importIntegrityPlugin.configs.monorepoRecommended.rules,
  },
};

A few notes:

  • monorepoRecommended includes the cross-package rules like no-unused-package-exports
  • monorepoRootDir points at the monorepo root; individual package roots are auto-discovered

For a full working example, see this repo's own oxlint.config.ts.

Next steps

  • Read Configuration to see the available settings.
  • Read Rules to see what the recommended config enables.
  • If you're in a monorepo, read Monorepos for the bigger picture on monorepo setup.