Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codemod vs. eslint --fix

Tags:

eslint

codemod

I want to write a couple of scripts to automatically detect missing imports and import them based upon a root directory. Is it better to write this script as a codemod script or as an eslint rule with the fix option?

like image 633
Josh Unger Avatar asked Sep 14 '25 01:09

Josh Unger


1 Answers

Codemods are meant for migrations while linting is there permanently to nag/warn your developers about some mistake they have potentially made while developing. Both can be used together.

For your case, I think there are two approaches you can take:

  1. Write a lint rule that detects the problem and a codemod to fix existing occurences of the problem. The lint rule ensures that developers won't miss that out in future.

  2. Write a lint rule that detects the problem along with a --fix option to automatically fix the problem.

I would lean towards approach two because it's more futureproof. You might want to just use this no-unresolved ESLint rule directly rather than writing your own. In any case, the fix/codemod is not trivial and can be a performance hit if your project has many directories and files.

like image 128
Yangshun Tay Avatar answered Sep 17 '25 19:09

Yangshun Tay