motoko-compiler-warnings-fixes

Fix Motoko compiler warnings from dfx build --check with safe bulk edits.

Updated Mar 19, 2026
One-click install
npx skills add https://github.com/research-ag/motoko-skills --skill motoko-compiler-warnings-fixes
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: motoko-compiler-warnings-fixes
Source: https://github.com/research-ag/motoko-skills/tree/main/skills/fix-compiler-warnings
Command: npx skills add https://github.com/research-ag/motoko-skills --skill motoko-compiler-warnings-fixes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide helps developers identify, understand, and clean up Motoko compiler warnings (MOC) surfaced during dfx build --check, reducing noise and preventing regressions.

Core Features & Use Cases

  • Structured fixes for common warnings: provides safe patterns for M0194 unused identifiers and M0244 variable mutability, with emphasis on preserving type safety.
  • Bulk-fix workflows: describes step-by-step, test-driven approaches to apply changes across multiple canisters and code paths.
  • Practical guidelines: includes warnings about potential type errors (M0096) and rebuild verification to ensure correctness.

Quick Start

Run the build check and follow the guidelines to apply fixes across your Motoko codebase.

Frequently Asked Questions about motoko-compiler-warnings-fixes

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix Motoko compiler warnings like M0194 unused identifiers?

To fix M0194 unused identifier warnings in Motoko, prefix unused variables with an underscore. This safely suppresses the compiler warning without altering program logic or requiring variable deletion.

What's the best way to resolve M0244 variable mutability warnings in Motoko?

Resolving M0244 variable mutability warnings requires converting var declarations to let where appropriate. This refactoring improves code safety by enforcing immutability when a variable's value is never reassigned.

How do I safely apply bulk fixes for Motoko compiler warnings across multiple canisters?

Safely applying bulk Motoko warning fixes requires a test-driven workflow: identify warnings via dfx build --check, apply patterns like var to let conversion, and verify correctness through rebuilds to prevent regressions across code paths.

Why does fixing Motoko mutability warnings cause type errors like M0096?

Changing var to let can trigger M0096 type errors if the variable is later reassigned. Guarding against this requires verifying mutability is truly unused before conversion and validating the rebuild after modification.

Can I use dfx build --check to identify all compiler warnings in a Motoko codebase?

Yes, running dfx build --check surfaces Motoko compiler warnings (MOC) across the codebase. This identifies issues like unused identifiers and unnecessary mutability, providing the baseline for applying structured refactoring fixes.

When should I not convert a var declaration to let in Motoko?

You should not convert var to let when the variable is genuinely reassigned later in the code. Doing so causes type errors like M0096, breaking the build and requiring a rollback of the mutability fix.