javascript-eslint-strict-directive-normalization
Normalize JavaScript and TypeScript strict-mode directives so a repository follows one deterministic policy equivalent to ESLint's strict rule. The codemod inserts, removes, or deduplicates 'use strict' at script and function scope, skips ESM insertion, removes redundant module directives when enabled, and can clean up ineffective misplaced literals.
Installation
bash
Usage
Default behavior:
policy=globalcleanupMisplaced=trueremoveRedundantInModules=truepreserveStyle=truequoteStyle=single
Supported policies:
global: add one top-level strict directive to classic scripts, dedupe duplicates, and remove redundant function-level strict directives.function: add one strict directive to each function-like block body in classic scripts unless the file is already globally strict. Functions with non-simple parameter lists are skipped because function-level strict mode would be invalid there.never: remove strict directives from program and function directive prologues.safe: conservatively add function-level strict directives only when the function avoids known strict-mode hazards (this,arguments,eval,with, legacy octal literals, duplicate parameters, and non-simple parameter lists). Existing strict directives are still deduplicated.
Important preserve and no-op behavior:
- Does not insert strict directives into ESM files, including package-level module contexts such as
.jsfiles under apackage.jsonwith"type": "module". - Removes redundant ESM strict directives only when
removeRedundantInModules=true. - Skips
.d.tsfiles,dist,vendor,generated, and*.min.*inputs. - Does not wrap concise arrow functions just to add a directive.
- Preserves the relative order of existing directives such as
'use client'or'use asm'when adding'use strict'. - Skips prologue rewrites when doing so would cross comment-sensitive directive regions.
Examples:
bash
Development
bash
License
MIT