npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2026 – Pkg Stats / Ryan Hefner

eslint-plugin-declguard

v1.2.0

Published

> πŸ›‘οΈ Enforce clean type boundaries in TypeScript code by controlling where types and interfaces can be exported from.

Readme

eslint-plugin-declguard

πŸ›‘οΈ Enforce clean type boundaries in TypeScript code by controlling where types and interfaces can be exported from.


πŸ“¦ Installation

npm install --save-dev eslint-plugin-declguard

πŸ”§ Usage

In your ESLint config:

module.exports = {
  plugins: ['declguard'],
  rules: {
    'declguard/no-exported-types-outside-dts': 'error',
  },
};

Or use the recommended preset:

module.exports = {
  extends: ['plugin:declguard/recommended']
};

βœ… Rule: no-exported-types-outside-dts

This rule prevents exporting TypeScript types and interfaces from files that don't match specified patterns.

Default Configuration

By default, types can only be exported from:

  • Files ending with .d.ts
  • Types ending with Props

❌ Disallowed (Default)

// my-feature.ts
export type User = { id: string };           // ❌
export interface Settings { darkMode: boolean } // ❌

βœ… Allowed (Default)

// my-feature.ts
export interface ButtonProps { label: string }  // βœ… Ends with Props
export type CardProps = { title: string };      // βœ… Ends with Props
// types.d.ts
export interface User { id: string }           // βœ… In .d.ts file
export type Settings = { darkMode: boolean }   // βœ… In .d.ts file

βš™οΈ Configuration

You can customize which files and type names are allowed:

// .eslintrc.js
module.exports = {
  rules: {
    'declguard/no-exported-types-outside-dts': ['error', {
      allowedFilePatterns: [
        '*.d.ts',
        '*.types.ts',
        '*.types.tsx',
        'types/*',
        '**/types.ts',
        'src/lib/**/*.ts',        // Allow all types in src/lib
        '!src/lib/vendor/**/*',   // But exclude vendor subdirectory
        'packages/*/types/**/*'   // Types in any package's types folder
      ],
      allowedTypeSuffixes: [
        'Props',
        'Type',
        'Interface',
        'Config'
      ]
    }]
  }
};

Configuration Options

  • allowedFilePatterns (string[]): Array of file patterns where type exports are allowed

    • Supports gitignore-style glob patterns (powered by minimatch)
    • Use ! prefix for negation/exclusion patterns
    • Patterns can include paths: src/lib/**/*.ts, packages/*/types/*
    • Default: ['*.d.ts']
  • allowedTypeSuffixes (string[]): Array of suffixes that allow types to be exported from any file

    • Default: ['Props']

Pattern Matching Examples

With the custom configuration above:

// src/components/Button.types.ts
export interface ButtonStyle { ... }        // βœ… File matches *.types.ts

// src/types/user.ts
export type User = { ... }                  // βœ… File in types/ directory

// src/lib/api/client.ts
export interface ApiClient { ... }          // βœ… Matches src/lib/**/*.ts

// src/lib/vendor/third-party.ts
export type VendorType = { ... }            // ❌ Excluded by !src/lib/vendor/**/*

// packages/ui/types/theme.ts
export interface Theme { ... }              // βœ… Matches packages/*/types/**/*

// src/components/Button.tsx
export type ButtonConfig = { ... }          // βœ… Type ends with Config
export interface ModalInterface { ... }     // βœ… Type ends with Interface

// src/utils/helpers.ts
export type Helper = { ... }                // ❌ Not allowed pattern

Advanced Path-Based Configuration

For projects with complex directory structures, you can use path-based patterns to control where types can be exported:

allowedFilePatterns: [
  // Standard type file patterns
  '*.d.ts',
  '*.types.ts',
  
  // Allow types in specific directories
  'src/shared/**/*.ts',           // All files in shared folder
  'src/api/types/**/*',           // API type definitions
  'packages/*/src/types/**/*',    // Types in monorepo packages
  
  // Exclude certain subdirectories
  'src/lib/**/*.ts',              // Allow in lib folder...
  '!src/lib/generated/**/*',      // ...but not in generated subfolder
  '!src/lib/vendor/**/*',         // ...and not in vendor subfolder
  
  // Match specific file names
  '**/constants.ts',              // Any constants.ts file
  '**/enums.ts',                  // Any enums.ts file
]

πŸ§‘β€πŸ’» Development

πŸ“ Project Structure

eslint-plugin-declguard/
β”œβ”€β”€ rules/                         # ESLint rule definitions
β”‚   └── no-exported-types-outside-dts.ts
β”œβ”€β”€ utils/                         # Shared utilities (e.g., createRule)
β”‚   └── createRule.ts
β”œβ”€β”€ index.ts                       # Plugin entry point
β”œβ”€β”€ package.json
└── tsconfig.json

πŸš€ Commands

  • npm run build β€” Compile TypeScript to dist/
  • npm run lint β€” Lint the plugin source

✨ Adding New Rules

  1. Create a new rule file in rules/
  2. Use the createRule helper from utils/
  3. Add the rule to index.ts
  4. Include it in the recommended config if appropriate

πŸ“¦ Publishing

The plugin is automatically published to npm when changes are pushed to the main branch via GitHub Actions.


MIT Β© DeclGuard Authors