# How to Configure File-Level Include/Exclude Patterns with Minimatch in tsslint.config.ts

> Master tsslint file-level include and exclude patterns using Minimatch in your tsslint.config.ts. Control which rules apply to specific files for streamlined linting.

- Repository: [Johnson Chu/tsslint](https://github.com/johnsoncodehk/tsslint)
- Tags: how-to-guide
- Published: 2026-03-04

---

**Configure file-level `include` and `exclude` patterns in your [`tsslint.config.ts`](https://github.com/johnsoncodehk/tsslint/blob/main/tsslint.config.ts) file by supplying arrays of Minimatch glob strings to each config object; the linter evaluates these patterns in [`packages/core/index.ts`](https://github.com/johnsoncodehk/tsslint/blob/main/packages/core/index.ts) to determine which rule sets apply to each source file.**

In the `johnsoncodehk/tsslint` project, you control which linting rules apply to specific source files using **Minimatch** glob patterns declared directly in your configuration file. By populating the `include` and `exclude` arrays in [`tsslint.config.ts`](https://github.com/johnsoncodehk/tsslint/blob/main/tsslint.config.ts), you can precisely target—or ignore—files based on path patterns, leveraging the core matching logic implemented in the `@tsslint/core` package.

## Understanding the Config Interface

The type definitions for configuration objects reside in **[`packages/types/index.ts`](https://github.com/johnsoncodehk/tsslint/blob/main/packages/types/index.ts)** (lines 18‑22). The `Config` interface declares two optional fields that control file-level scoping:

- **`include?: string[]`** – An array of glob patterns that determine which files the configuration applies to.
- **`exclude?: string[]`** – An array of glob patterns that prevent the configuration from applying to matching files.

Both arrays accept standard Minimatch patterns. When you export a config from [`tsslint.config.ts`](https://github.com/johnsoncodehk/tsslint/blob/main/tsslint.config.ts) using `defineConfig()`, these arrays tell the linter exactly where your rules should run.

## How File Matching Works in the Core Engine

The file resolution logic lives in **[`packages/core/index.ts`](https://github.com/johnsoncodehk/tsslint/blob/main/packages/core/index.ts)**. When the linter needs to determine which configurations apply to a specific file, it calls the **`getConfigsForFile`** function (lines 24‑38).

For every configuration object, the engine executes the following check:

```typescript
if (exclude?.some(_minimatch)) return false;
if (include && !include.some(_minimatch)) return false;

```

The helper function **`_minimatch`** (lines 40‑56) performs the actual pattern matching by invoking:

```typescript
minimatch.minimatch(fileName, normalized, { dot: true })

```

This call uses the **Minimatch** library with the `dot: true` option enabled, ensuring that dotfiles are considered when matching patterns. The core implementation also maintains an internal cache (`minimatchCache`) to avoid re-computing matches for identical patterns across multiple files.

The evaluation order is strict: if any `exclude` pattern matches, the config is rejected immediately. If `include` is defined and no pattern matches, the config is also rejected. Only configs passing both checks are used to collect rules for the file.

## Practical Configuration Examples

### Basic Include and Exclude Patterns

The most common use case targets specific source directories while excluding generated files:

```typescript
// tsslint.config.ts
import { defineConfig } from '@tsslint/config';

export default defineConfig({
  // Only lint TypeScript files in the src directory
  include: ['src/**/*.ts'],
  // Ignore generated files regardless of location
  exclude: ['src/**/*.generated.ts'],

  rules: {
    'no-console': (await import('./rules/no-console.ts')),
  },
});

```

Paths are resolved relative to the directory where `tsslint` is executed (typically the project root).

### Multiple Config Objects for Different File Types

You can export an array of config objects to apply distinct rule sets to different file types, as demonstrated in **[`fixtures/multiple-configs/tsslint.config.ts`](https://github.com/johnsoncodehk/tsslint/blob/main/fixtures/multiple-configs/tsslint.config.ts)**:

```typescript
// tsslint.config.ts
import { defineConfig } from '@tsslint/config';

export default defineConfig([
  {
    include: ['**/*.ts'],
    rules: {
      'strict-ts': (await import('./rules/strict-ts.ts')),
    },
  },
  {
    include: ['**/*.vue'],
    exclude: ['**/tests/**/*.vue'],
    rules: {
      'vue-specific': (await import('./rules/vue-rules.ts')),
    },
  },
]);

```

Each object is evaluated independently. The first config applies only to `*.ts` files, while the second targets Vue single-file components but explicitly ignores those under any `tests/` directory.

### Using Negation and Dotfile Patterns

Minimatch supports negation patterns using the `!` prefix, which `tsslint` handles correctly due to the `{ dot: true }` option in the core matcher:

```typescript
export default defineConfig({
  // Match everything under src, including dotfiles, but exclude hidden directories
  include: ['src/**', '!src/**/.*'],
  // Ignore test files
  exclude: ['**/*.spec.ts', '**/*.test.ts'],

  rules: {
    'no-debugger': (await import('./rules/no-debugger.ts')),
  },
});

```

Because the core implementation passes `{ dot: true }` to Minimatch, files beginning with a dot are matched when your patterns explicitly reference them.

## Summary

- The `Config` type in **[`packages/types/index.ts`](https://github.com/johnsoncodehk/tsslint/blob/main/packages/types/index.ts)** defines optional `include` and `exclude` string arrays for file-level scoping.
- The **`getConfigsForFile`** function in **[`packages/core/index.ts`](https://github.com/johnsoncodehk/tsslint/blob/main/packages/core/index.ts)** evaluates every config object against the current file path using Minimatch.
- **Exclusion patterns take precedence**: if a file matches any `exclude` pattern, the config is discarded before checking `include`.
- The matching logic uses **`minimatch.minimatch`** with `{ dot: true }`, enabling consistent handling of dotfiles and supporting negation patterns.
- You can export multiple config objects from [`tsslint.config.ts`](https://github.com/johnsoncodehk/tsslint/blob/main/tsslint.config.ts) to apply different rules to different file types.

## Frequently Asked Questions

### What glob syntax does tsslint support for include/exclude patterns?

tsslint supports standard **Minimatch** syntax, including `*` (match any file), `**` (match across directories), `?` (single character), and character classes. Negation patterns using `!` are also supported within the `include` array. The implementation in [`packages/core/index.ts`](https://github.com/johnsoncodehk/tsslint/blob/main/packages/core/index.ts) explicitly enables the `dot: true` option, ensuring dotfiles are included in matches when patterns cover them.

### How does tsslint resolve conflicts between include and exclude patterns?

The linter evaluates patterns in a specific order of precedence. First, it checks if the file path matches any pattern in the `exclude` array; if it does, the configuration object is immediately rejected. Only if the file survives the exclusion check does the linter verify whether it matches the `include` array (if defined). This means **exclude always wins over include**.

### Can I configure different rules for TypeScript and Vue files in the same project?

Yes. Export an array of configuration objects from [`tsslint.config.ts`](https://github.com/johnsoncodehk/tsslint/blob/main/tsslint.config.ts), each with its own `include` pattern targeting the specific file extension. For example, use `include: ['**/*.ts']` for TypeScript-specific rules and `include: ['**/*.vue']` for Vue-specific rules. You can further refine each scope with `exclude` patterns to ignore test files or generated code, as shown in the [`fixtures/multiple-configs/tsslint.config.ts`](https://github.com/johnsoncodehk/tsslint/blob/main/fixtures/multiple-configs/tsslint.config.ts) example.

### Where is the Minimatch pattern matching logic implemented?

The actual matching logic resides in the **`_minimatch`** helper function within **[`packages/core/index.ts`](https://github.com/johnsoncodehk/tsslint/blob/main/packages/core/index.ts)** (lines 40‑56). This function normalizes patterns and invokes `minimatch.minimatch(fileName, normalized, { dot: true })`, caching results to optimize performance across large codebases. The surrounding **`getConfigsForFile`** function orchestrates the filtering of configuration objects based on these matches.