Filtering

Control which files and code locations dart_mutant mutates.

File Selection

Glob Patterns

Target specific files using glob patterns:

# Only mutate core library files
dart_mutant --glob "lib/src/core/**/*.dart"

# Only mutate a specific file
dart_mutant --glob "lib/src/calculator.dart"

# Multiple patterns
dart_mutant --glob "lib/src/models/**/*.dart" --glob "lib/src/services/**/*.dart"

Exclude Patterns

Exclude files from mutation:

# Exclude legacy code
dart_mutant --exclude "**/legacy/**"

# Exclude multiple patterns
dart_mutant --exclude "**/deprecated/**" --exclude "**/experimental/**"

Default Exclusions

dart_mutant automatically excludes these patterns:

Pattern Reason
**/*.g.dart Generated by json_serializable, etc.
**/*.freezed.dart Generated by freezed
**/*.gr.dart Generated by auto_route
**/generated/** Common generated code directory
**/*.gen.dart Generic generated files

What Gets Excluded

Beyond file patterns, dart_mutant skips these code elements:

Comments

// This comment won't be mutated
/* Neither will this */
/// Or doc comments

Import/Export Statements

import 'package:flutter/material.dart';  // Skipped
export 'src/models.dart';  // Skipped

Annotations

@override  // Skipped
@deprecated  // Skipped
@JsonSerializable()  // Skipped
void myMethod() {}

Constant Expressions

const maxRetries = 3;  // Skipped (would break compilation)
static const timeout = Duration(seconds: 30);  // Skipped

Assert Statements

assert(value != null);  // Skipped (debug only)

Smart Exclusions

dart_mutant analyzes context to avoid useless mutations:

String Literals

Only strings in meaningful positions are mutated:

// Mutated - affects logic
if (status == "active") { }

// Not mutated - just logging
print("Debug: $value");

Trivial Returns

// Not mutated - empty methods are usually intentional
void dispose() {}

// Mutated - has actual logic
void dispose() {
  _controller.close();
}

Custom Exclusion Rules

For fine-grained control, use comments:

// dart_mutant:ignore-line
bool isEnabled = true;  // This line won't be mutated

// dart_mutant:ignore-start
void legacyCode() {
  // Nothing in this block will be mutated
}
// dart_mutant:ignore-end

Performance Tips

Focus on Critical Code

Instead of excluding files, focus mutations on important code:

# Only mutate business logic
dart_mutant --glob "lib/src/domain/**/*.dart"

# Skip UI code
dart_mutant --exclude "**/widgets/**" --exclude "**/screens/**"

Incremental Testing

For PR checks, only test changed files:

dart_mutant --incremental --base-ref main

Sampling

For large codebases, sample mutations:

# Test 100 random mutations for quick feedback
dart_mutant --sample 100

Next Steps