Skip to content

Commit

Permalink
docs: Update inconsistent docs for filtering files (#374)
Browse files Browse the repository at this point in the history
* docs: Update inconsistent docs for filtering files

The 'Filtering files' section in the readme had not been updated when the
`gitDir` option was deprecated in 5.0.

* docs: Address feedback

- Reword {project => package} root
- Add note about absolute paths.

* docs: Update filtering part

* docs: Re-word, format

* style(readme): Single line for para
  • Loading branch information
sudo-suhas committed Jan 10, 2018
1 parent 237d3f6 commit 8baab8c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ To set options and keep lint-staged extensible, advanced format can be used. Thi

## Filtering files

It is possible to run linters for certain paths only by using [minimatch](https://github.com/isaacs/minimatch) patterns. The paths used for filtering via minimatch are relative to the directory that contains the `.git` directory. The paths passed to the linters are absolute to avoid confusion in case they're executed with a different working directory, as would be the case when using the `gitDir` option.
It is possible to run linters for certain paths only by using glob patterns. [minimatch](https://github.com/isaacs/minimatch) is used to filter the staged files according to these patterns. File patterns should be specified _relative to the `package.json` location_ (i.e. where `lint-staged` is installed).

**NOTE:** If you're using `lint-staged<5` globs have to be _relative to the git root_.

```js
{
Expand All @@ -147,6 +149,17 @@ It is possible to run linters for certain paths only by using [minimatch](https:
}
```

When matching, `lint-staged` will do the following

* Resolve the git root automatically, no configuration needed.
* Pick the staged files which are present inside the project directory.
* Filter them using the specified glob patterns.
* Pass absolute paths to the linters as arguments.

**NOTE:** `lint-staged` will pass _absolute_ paths to the linters to avoid any confusion in case they're executed in a different working directory (i.e. when your `.git` directory isn't the same as your `package.json` directory).

Also see [How to use `lint-staged` in a multi package monorepo?](#how-to-use-lint-staged-in-a-multi-package-monorepo)

## What commands are supported?

Supported are both local npm scripts (`npm run-script`), or any executables installed locally or globally via `npm` as well as any executable from your $PATH.
Expand Down

0 comments on commit 8baab8c

Please sign in to comment.