Stop ESLint from searching up the directory tree

For most projects, I use a monorepo, and nest my scripts in a directory. I’ll npm init each script, and maintain an isolated set of dependencies outside of the main dependency tree. This includes maintaining a separate .eslintrc file as well.

Typically, this isn’t a problem, but recently with a new project that was created with create-next-app, I ended up with some issues with linting of one of my scripts. As it turns out, the issue was due to sourcing the .eslintrc file in the root of the project directly, even though I had an .eslintrc file in my script directory.

What I was not aware of, is that the stock functionality of eslint is to search up the directory tree, utilizing each .eslintrc file along the way.

Well that’s not the behavior I wanted.

Configuring a root config file

Like many things in life, there is a configuration option for that!

To stop eslint from searching up the directory tree, you need to tell eslint that the .eslintrc file is the root file. When it sees a root file, it will source it, and then stop searching.

To configure your .eslintrc file as a root file, simply add a root property with a value of true to your config:

module.exports = {
  // Stuff like env, extends, etc...
  root: true,
  // Other stuff like rules...
Josh Sherman - The Man, The Myth, The Avatar

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.

If you found this article helpful, please consider buying me a coffee.