DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 966,155 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in

Discussion on: How to Create Custom ESLint Rules (It's Not as Hard as You Think...)

Collapse
 
devtghosh profile image
Devjyoti Ghosh

Hey, I want to create a rule about if new files are created make sure they are in TS. How would I go about doing that?

I am facing this issue because my codebase is half in JS and half in TS and we aren't looking to migrating everything just yet. We just want to make sure new files are created in TS.

Collapse
 
fabioemoutinho profile image
FΓ‘bio Englert Moutinho Author

Hi Devjyoti! The first thing I would do is to create a rule that throws a warning for every .js file in the repo.
The next thing is to find out if there is a way to create a rule that:

  1. takes a number as an argument which represents the cap of .js files in the project.
  2. counts the total number of .js files and compares it with the argument. If it is greater than the argument, throw an error.

Another possible solution is to use the first rule I mentioned paired with the eslint.org/docs/user-guide/command... option and allow warnings until it reaches the .js file number cap