Skip to content

big ignore paths slow down cli #4989

@eps1lon

Description

@eps1lon

Environments:

  • Prettier Version: 1.14.2
  • Running Prettier via: CLI
  • Runtime: v10.8.0
  • Operating System: Linux

Steps to reproduce:

mkdir repro-dir && cd repro-dir
npm init
npm add prettier
# add some dependencies to feel the weight on the prettier cli
npm add express typescript webpack
touch index.js
cp -r node_modules a_deeply_nested_structure
echo "a_deeply_nested_structure" > .prettierignore
node_modules/.bin/prettier --list-different "**/*.js"

Expected behavior:
Does not walk down any folder in a_deeply_nested_structure. Prettier finishes instantly.

Actual behavior:
glob does walk down a_deeply_nested_structure. They get ignored in the end by prettier but this can slow down runtime heavily if we want to ignore big folders. You can check this by inspecting

prettier/src/cli/util.js

Lines 444 to 452 in d480858

const fileIgnored = ignorer.filter([filename]).length === 0;
if (
fileIgnored &&
(context.argv["debug-check"] ||
context.argv["write"] ||
context.argv["list-different"])
) {
return;
}

Is there a reason why the ignore patterns are not passed to node-glob?

If I got this right this behavior was request by #3590 but in my opinion it should be the responsibility of the extension to get knowledge of .prettierignore. As of right now the cli is very slow when someone has to ignore paths other than node_modules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cliIssues with Prettier's Command Line Interfacearea:ignore.prettierignore file, --ignore-path CLI option, /* prettier-ignore */ comments and so ontype:perfIssue with performance of Prettier

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions