Repository: okonet/lint-staged
Pull request #179 (2017-06-01 12:17:04)

Add advanced option globOptions to customise how matching works
Adds the `globOptions` key to advanced config to allow customisation of how matching works.

Will also solve (although it is not a bug in hindsight but not ideal either): https://github.com/okonet/lint-staged/issues/173

codecov[bot]: # [Codecov](https://codecov.io/gh/okonet/lint-staged/pull/179?src=pr&el=h1) Report
> Merging [#179](https://codecov.io/gh/okonet/lint-staged/pull/179?src=pr&el=desc) into [master](https://codecov.io/gh/okonet/lint-staged/commit/4c600178ac26604f5d543028ac846a061e0729f9?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/okonet/lint-staged/pull/179/graphs/tree.svg?width=650&height=150&token=LSoEgsjk4O&src=pr)](https://codecov.io/gh/okonet/lint-staged/pull/179?src=pr&el=tree)

```diff
@@          Coverage Diff          @@
##           master   #179   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           5      5           
  Lines          65     67    +2     
  Branches        8      8           
=====================================
+ Hits           65     67    +2
```


| [Impacted Files](https://codecov.io/gh/okonet/lint-staged/pull/179?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/generateTasks.js](https://codecov.io/gh/okonet/lint-staged/pull/179?src=pr&el=tree#diff-c3JjL2dlbmVyYXRlVGFza3MuanM=) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/okonet/lint-staged/pull/179?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/okonet/lint-staged/pull/179?src=pr&el=footer). Last update [4c60017...a5fc5cb](https://codecov.io/gh/okonet/lint-staged/pull/179?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

okonet: One last thing that is missing is the documentation. Could you please update the README?
georeith: @okonet Added 👍 

Patch:
diff --git a/README.md b/README.md
index ee292b8..2089fa3 100644
--- a/README.md
+++ b/README.md
@@ -91,6 +91,7 @@ To set options and keep lint-staged extensible, advanced format can be used. Thi
 * `chunkSize` — Max allowed chunk size based on number of files for glob pattern. This is important on windows based systems to avoid command length limitations. See #147
 * `subTaskConcurrency` — `2` — Controls concurrency for processing chunks generated for each linter.
 * `verbose` — *false* — runs lint-staged in verbose mode. When `true` it will use https://github.com/SamVerschueren/listr-verbose-renderer.
+* `globOptions` — `{ matchBase: true, dot: true }` — [minimatch options](https://github.com/isaacs/minimatch#options) to customize how glob patterns match files.
 
 ## Filtering files
 
diff --git a/src/generateTasks.js b/src/generateTasks.js
index 261cec3..6278aea 100644
--- a/src/generateTasks.js
+++ b/src/generateTasks.js
@@ -2,16 +2,19 @@
 
 const minimatch = require('minimatch')
 
+const readConfigOption = require('./readConfigOption')
+
 module.exports = function generateTasks(config, files) {
     const linters = config.linters !== undefined ? config.linters : config
     const resolve = file => files[file]
     return Object.keys(linters)
         .map((pattern) => {
             const commands = linters[pattern]
-            const filter = minimatch.filter(pattern, {
+            const globOptions = readConfigOption(config, 'globOptions', {})
+            const filter = minimatch.filter(pattern, Object.assign({
                 matchBase: true,
                 dot: true
-            })
+            }, globOptions))
             const fileList = Object.keys(files).filter(filter).map(resolve)
             return {
                 pattern,


Test patch:
diff --git a/test/generateTasks.spec.js b/test/generateTasks.spec.js
index dcd5c9b..22ca650 100644
--- a/test/generateTasks.spec.js
+++ b/test/generateTasks.spec.js
@@ -146,4 +146,25 @@ describe('generateTasks', () => {
             ]
         })
     })
+
+    it('should support globOptions specified in advanced configuration', () => {
+        const result = generateTasks(
+            {
+                globOptions: {
+                    matchBase: false,
+                    nocase: true
+                },
+                linters: {
+                    'TeSt.*': 'lint'
+                }
+            },
+            files
+        )
+        const linter = result.find(item => item.pattern === 'TeSt.*')
+        expect(linter).toEqual({
+            pattern: 'TeSt.*',
+            commands: 'lint',
+            fileList: ['/root/test.js', '/root/test.css', '/root/test.txt']
+        })
+    })
 })