From 80c85983fb8ec209e65fc2c481f1cdca595ed9da Mon Sep 17 00:00:00 2001 From: Gustavo Santana Date: Wed, 22 Aug 2018 15:26:40 -0400 Subject: [PATCH] Docs: gitignore syntax updates (fixes #8139) (#10776) * Docs: .gitignore syntax updates (fixes #8139) # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch gitignore-syntax-updates # Changes to be committed: #modified: docs/user-guide/command-line-interface.md #modified: docs/user-guide/configuring.md # Adds cross links between .eslintignore and --ignore-pattern sections. Adds link to --ignore-pattern section directing to .gitignore specs. Adds description to .eslintignore section that emphasizes forward slashes being necessary with examples of valid and invalid syntax. Adds explicit statements to both sections that support this example. * adds a comma --- docs/user-guide/command-line-interface.md | 3 +-- docs/user-guide/configuring.md | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/user-guide/command-line-interface.md b/docs/user-guide/command-line-interface.md index 9a7ade28137..7de5a50a1e2 100644 --- a/docs/user-guide/command-line-interface.md +++ b/docs/user-guide/command-line-interface.md @@ -254,13 +254,12 @@ Example: #### `--ignore-pattern` -This option allows you to specify patterns of files to ignore (in addition to those in `.eslintignore`). You can repeat the option to provide multiple patterns. The supported syntax is the same as in the `.eslintignore` file. You should quote your patterns in order to avoid shell interpretation of glob patterns. +This option allows you to specify patterns of files to ignore (in addition to those in `.eslintignore`). You can repeat the option to provide multiple patterns. The supported syntax is the same as for `.eslintignore` [files](./configuring.md#.eslintignore), which use the same patterns as the `.gitignore` [specification](https://git-scm.com/docs/gitignore). You should quote your patterns in order to avoid shell interpretation of glob patterns. Example: eslint --ignore-pattern '/lib/' --ignore-pattern '/src/vendor/*' . - ### Using stdin #### `--stdin` diff --git a/docs/user-guide/configuring.md b/docs/user-guide/configuring.md index 4daa7dd5958..0db1e4dcf40 100644 --- a/docs/user-guide/configuring.md +++ b/docs/user-guide/configuring.md @@ -839,6 +839,8 @@ Currently the sole method for telling ESLint which file extensions to lint is by ## Ignoring Files and Directories +### `.eslintignore` + You can tell ESLint to ignore specific files and directories by creating an `.eslintignore` file in your project's root directory. The `.eslintignore` file is a plain text file where each line is a glob pattern indicating which paths should be omitted from linting. For example, the following will omit all JavaScript files: ```text @@ -850,9 +852,21 @@ When ESLint is run, it looks in the current working directory to find an `.eslin Globs are matched using [node-ignore](https://github.com/kaelzhang/node-ignore), so a number of features are available: * Lines beginning with `#` are treated as comments and do not affect ignore patterns. -* Paths are relative to `.eslintignore` location or the current working directory. This also influences paths passed via `--ignore-pattern`. -* Ignore patterns behave according to the `.gitignore` [specification](https://git-scm.com/docs/gitignore) +* Paths are relative to `.eslintignore` location or the current working directory. This is also true of paths passed in via the `--ignore-pattern` [command](./command-line-interface.md#--ignore-pattern). * Lines preceded by `!` are negated patterns that re-include a pattern that was ignored by an earlier pattern. +* Ignore patterns behave according to the `.gitignore` [specification](https://git-scm.com/docs/gitignore). + +Of particular note is that like `.gitignore` files, all paths used as patterns for both `.eslintignore` and `--ignore-pattern` must use forward slashes as their path separators. + +```text +# Valid +/root/src/*.js + +# Invalid +\root\src\*.js +``` + +Please see `.gitignore`'s specification for further examples of valid syntax. In addition to any patterns in a `.eslintignore` file, ESLint always ignores files in `/node_modules/*` and `/bower_components/*`.