Quickstart
Installation
Install the plugin from npm:
npm install --save-dev import-integrity-lintESLint
Single package
For a single-package codebase, the configuration is minimal:
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.
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:
monorepoRecommendedincludes the cross-package rules likeno-unused-package-exportsmonorepoRootDirpoints 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:
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.
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:
monorepoRecommendedincludes the cross-package rules likeno-unused-package-exportsmonorepoRootDirpoints 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.