Linguist: Dynamically suppress files/folders

Created on 12 Oct 2013  路  13Comments  路  Source: github/linguist

I think files in node_modules/ should be suppressed in diffs, or at least the option for it should exist.

I recently added a module to package.json and ended up with 300 new files and 46k additions in node_modules/, and then made a pull request. That comparison took a while to load.

Related but not exactly the same: https://github.com/github/linguist/issues/137

Most helpful comment

+1. I think a good solution would be to add a URL param like ?exclude="node_modules/*". This would match the interface for the existing ?w= param which toggles whitespace diffing.

All 13 comments

That's something you would set in a .gitignore.
Why on earth would you want to commit your node_modules?

Here are 3 reasons why to put it in a .gitignore

  1. It makes the repo much bigger
  2. It's vendor code that can be downloaded by running a single command
  3. It's garbage code that messes with Githubs linguist

Just put _node_modules_ in the main .gitignore

Yeah, that was my own first thought as well, but I'm not making that choice by myself for the project in question.

Choice based on: http://www.futurealoof.com/posts/nodemodules-in-git.html.

TL;DR: Node doesn't have a Gemfile.lock, so

  • dependencies of dependencies and
  • dependencies with unspecified versions

could differ between deploys and developer machines.

As for your number 3: if it's vendor code, shouldn't it _not_ mess with linguist?

Hmm.. I understand.
You have a point there.

And yes it shouldn't mess with it but it always does (for me).
I've been looking for a solution for a while now to exclude specific files or folders from linguist.

Ah, what a pity. I'm guessing you haven't missed the discussion in #137?

As far as I can tell node_modules/ should be added permanently as a vendor folder though.

Is there any time you wouldn't make node_modules/? ignored. Seems like that could just be set in our in vendored file, and we'll always ignore site-wide.

Closing this issue since we're working on improving detection site-wide instead of just doing per-repo restrictions, but please feel free to open an PR for ignoring this directory.

node_modules/ is already listed in vendor.yml, so I'm assuming that already works.

I do not understand why you (GitHub) are so opposed to per-repo configuration.

@Frogging101, probably because it makes the parsing of the language data a lot more complex if each project can set its own world-view on these things?

Also Pods folder is excluded in vendor.yml, it doesn't work. It counts ruby as a language in my repo, and also it counts Pods in calculating line additions, shows Pods folder in diff window.

@milani Please open a new issue, it's not the same problem.

@tnm Re "Is there any time you wouldn't make node_modules ignored?" Here's a use case. When you do require("module-x") in Node.js it searches upwards from the file containing the statement until it finds a subdirectory named node_modules/module-x. So if I have a bunch of interdependent source-code-controlled modules in a single repository I can make them accessible to each other by simply putting them into a directory named node_modules. After git clone and npm install, our repo looks like this:

  • monorepo

    • node_modules (Shared 3rd party dependencies. gitignored)

    • src

    • node_modules (our JavaScript modules. Committed to git)



      • module-x


      • node_modules (module_x-specific 3rd party dependencies. gitignored)


      • module-y


      • node_modules (module_y-specific 3rd party dependencies. gitignored)



+1. I think a good solution would be to add a URL param like ?exclude="node_modules/*". This would match the interface for the existing ?w= param which toggles whitespace diffing.

Was this page helpful?
0 / 5 - 0 ratings