or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

analysis-correctness.mdconfigs.mdenvironment-specific.mdindex.mdmodule-systems.mdpath-resolution.mdstatic-analysis.mdstyle-organization.mdtypescript.md
tile.json

path-resolution.mddocs/

Path and Resolution Rules

These rules control how module paths are resolved and validated, including restrictions on absolute paths, internal modules, file extensions, and path structure. They help enforce consistent import patterns and prevent problematic path usage.

Path Restrictions

no-restricted-paths

Restricts which files can be imported in a given folder.

const noRestrictedPaths: RuleModule<'path' | 'zone', [
  {
    zones?: Array<{
      target: string | string[];
      from: string | string[];
      except?: string[];
      message?: string;
    }>;
    basePath?: string;
  }?
]>;

Options:

  • zones (Array): Path restriction zones
  • basePath (string): Base path for relative zones

Example:

// Configuration
{
  "import-x/no-restricted-paths": ["error", {
    "zones": [
      {
        "target": "./src/client",
        "from": "./src/server",
        "message": "Client code cannot import server modules"
      }
    ]
  }]
}

// In src/client/component.js
// ✗ BAD - importing from restricted server directory
import config from '../server/config';

// ✓ GOOD - importing from allowed directories
import utils from './utils';
import api from '../shared/api';

no-absolute-path

Forbids import of modules using absolute paths.

const noAbsolutePath: RuleModule<'absolute', [
  {
    esmodule?: boolean;
    commonjs?: boolean;
    amd?: boolean;
  }?
]>;

Options:

  • esmodule (boolean): Check ES module imports (default: true)
  • commonjs (boolean): Check CommonJS requires (default: true)
  • amd (boolean): Check AMD requires (default: true)

Example:

// ✗ BAD - absolute paths
import utils from '/Users/dev/project/src/utils';
const config = require('/home/user/app/config');

// ✓ GOOD - relative or module paths
import utils from './utils';
import utils from '../shared/utils';
const config = require('config');

no-internal-modules

Forbids import of internal modules of external packages.

const noInternalModules: RuleModule<'internalModule', [
  {
    allow?: string[];
    forbid?: string[];
  }?
]>;

Options:

  • allow (string[]): Patterns to allow
  • forbid (string[]): Patterns to explicitly forbid

Example:

// ✗ BAD - importing internal modules
import Button from 'react-bootstrap/lib/Button';
import utils from 'lodash/internal/utils';

// ✓ GOOD - importing public API
import { Button } from 'react-bootstrap';
import { map } from 'lodash';

// ✓ GOOD - if 'react-bootstrap/lib/*' is in allow list
import Button from 'react-bootstrap/lib/Button';

File Extensions

extensions

Ensures consistent use of file extension within the import path.

const extensions: RuleModule<'missing' | 'unexpected', [
  'never' | 'always' | 'ignorePackages' | {
    [extension: string]: 'never' | 'always' | 'ignorePackages';
  }
]>;

Options:

  • 'never': Never use extensions
  • 'always': Always use extensions
  • 'ignorePackages': Never use extensions for packages, configurable for files
  • Object: Per-extension configuration

Example:

// With { "js": "never", "ts": "always" }

// ✗ BAD - .js extension when "never"
import utils from './utils.js';

// ✗ BAD - missing .ts extension when "always"  
import types from './types';

// ✓ GOOD - correct extension usage
import utils from './utils';
import types from './types.ts';

Path Structure

no-useless-path-segments

Forbids unnecessary path segments in import and require statements.

const noUselessPathSegments: RuleModule<'useless', [
  {
    commonjs?: boolean;
    noUselessIndex?: boolean;
  }?
]>;

Options:

  • commonjs (boolean): Check CommonJS requires (default: true)
  • noUselessIndex (boolean): Remove useless index file references (default: false)

Example:

// ✗ BAD - useless path segments
import utils from '../foo/../bar/utils';
import config from './config/./index';
import helper from './utils/../utils/helper';

// ✓ GOOD - clean paths
import utils from '../bar/utils';
import config from './config';
import helper from './utils/helper';

// With noUselessIndex: true
// ✗ BAD - useless index reference
import main from './components/index';

// ✓ GOOD - direct directory import
import main from './components';

Package Import Patterns

no-relative-packages

Forbids importing packages through relative paths.

const noRelativePackages: RuleModule<'relative', [
  {
    commonjs?: boolean;
    exceptions?: string[];
  }?
]>;

Options:

  • commonjs (boolean): Check CommonJS requires (default: true)
  • exceptions (string[]): Package names to allow relative imports

Example:

// ✗ BAD - relative import of package
import lodash from '../node_modules/lodash';
import react from '../../node_modules/react';

// ✓ GOOD - direct package import
import lodash from 'lodash';
import react from 'react';

no-relative-parent-imports

Forbids importing modules from parent directories.

const noRelativeParentImports: RuleModule<'parent', [
  {
    commonjs?: boolean;
    exceptions?: string[];
  }?
]>;

Options:

  • commonjs (boolean): Check CommonJS requires (default: true)
  • exceptions (string[]): Path patterns to allow

Example:

// In src/components/Button/Button.js

// ✗ BAD - importing from parent directories
import utils from '../../utils/helpers';
import config from '../../../config';

// ✓ GOOD - importing from same or child directories
import styles from './Button.styles';
import Icon from './Icon';

// ✓ GOOD - if '../../utils/*' is in exceptions
import utils from '../../utils/helpers';

Resolution Configuration Types

interface PathRestrictionZone {
  target: string | string[];
  from: string | string[];
  except?: string[];
  message?: string;
}

interface PathRestrictionOptions {
  zones?: PathRestrictionZone[];
  basePath?: string;
}

interface ExtensionOptions {
  [extension: string]: 'never' | 'always' | 'ignorePackages';
}

interface UselessPathOptions {
  commonjs?: boolean;
  noUselessIndex?: boolean;
}

interface RelativePathOptions {
  commonjs?: boolean;
  exceptions?: string[];
}

interface InternalModuleOptions {
  allow?: string[];
  forbid?: string[];
}

Common Path Patterns

Monorepo Patterns

// ✓ GOOD - workspace package imports
import utils from '@myorg/utils';
import components from '@myorg/components';

// ✗ BAD - relative imports across packages
import utils from '../../../packages/utils/src';

Absolute Import Aliases

// ✓ GOOD - configured path aliases
import utils from '@/utils';
import components from '@/components/Button';
import config from '~/config';

// Configuration in webpack/TypeScript
{
  "compilerOptions": {
    "paths": {
      "@/*": ["./src/*"],
      "~/*": ["./"]
    }
  }
}

Layer Architecture

// Configuration for layered architecture
{
  "import-x/no-restricted-paths": ["error", {
    "zones": [
      {
        "target": "./src/presentation",
        "from": ["./src/data", "./src/domain/entities"],
        "message": "Presentation layer cannot directly access data layer"
      },
      {
        "target": "./src/domain",
        "from": "./src/data",
        "message": "Domain layer cannot depend on data layer"
      }
    ]
  }]
}