Skip to content

Commit 5b55844

Browse files
committed
Add support for resolving patterns from cwd
Related to unifiedjs/unified-engine#41. Related to unifiedjs/unified-engine#43.
1 parent 2cd7dc6 commit 5b55844

File tree

8 files changed

+133
-49
lines changed

8 files changed

+133
-49
lines changed

lib/options.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ function options(flags, configuration) {
7777
settings: settings(config.setting),
7878
ignoreName: configuration.ignoreName,
7979
ignorePath: config.ignorePath,
80+
ignorePathResolveFrom: config.ignorePathResolveFrom,
8081
ignorePatterns: commaSeparated(config.ignorePattern),
8182
detectIgnore: config.ignore,
8283
pluginPrefix: configuration.pluginPrefix,

lib/schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@
101101
"type": "string",
102102
"value": "<path>"
103103
},
104+
{
105+
"long": "ignore-path-resolve-from",
106+
"description": "resolve patterns in `ignore-path` from its directory or cwd",
107+
"type": "string",
108+
"value": "dir|cwd",
109+
"default": "dir"
110+
},
104111
{
105112
"long": "ignore-pattern",
106113
"description": "specify ignore patterns",

readme.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ start({
6666
* [`--output [path]`](#--output-path)
6767
* [`--rc-path <path>`](#--rc-path-path)
6868
* [`--ignore-path <path>`](#--ignore-path-path)
69+
* [`--ignore-path-resolve-from dir|cwd`](#--ignore-path-resolve-from-dircwd)
6970
* [`--setting <settings>`](#--setting-settings)
7071
* [`--report <reporter>`](#--report-reporter)
7172
* [`--use <plugin>`](#--use-plugin)
@@ -262,6 +263,18 @@ File path to an [ignore file][ignore-file] to load, regardless of
262263
* **Alias**: `-i`
263264
* **Engine**: [`ignorePath`][engine-ignore-path]
264265

266+
### `--ignore-path-resolve-from dir|cwd`
267+
268+
```sh
269+
cli . --ignore-path node_modules/my-config/my-ignore --ignore-path-resolve-from cwd
270+
```
271+
272+
Resolve patterns in the ignore file from its directory (`dir`, default) or the
273+
current working directory (`cwd`).
274+
275+
* **Default**: `dir`
276+
* **Engine**: [`ignorePathResolveFrom`][engine-ignore-path-resolve-from]
277+
265278
### `--setting <settings>`
266279

267280
```sh
@@ -648,6 +661,8 @@ abide by its terms.
648661

649662
[engine-ignore-path]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsignorepath
650663

664+
[engine-ignore-path-resolve-from]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsignorepathresolvefrom
665+
651666
[engine-reporter]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsreporter
652667

653668
[engine-reporter-options]: https://github.com/unifiedjs/unified-engine/blob/master/doc/options.md#optionsreporteroptions

test/fixtures/example/HELP

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,30 @@ Usage: foo [options] [path | glob ...]
44

55
Options:
66

7-
-h --help output usage information
8-
-v --version output version number
9-
-o --output [path] specify output location
10-
-r --rc-path <path> specify configuration file
11-
-i --ignore-path <path> specify ignore file
12-
-s --setting <settings> specify settings
13-
-e --ext <extensions> specify extensions
14-
-u --use <plugins> use plugins
15-
-w --watch watch for changes and reprocess
16-
-q --quiet output only warnings and errors
17-
-S --silent output only errors
18-
-f --frail exit with 1 on warnings
19-
-t --tree specify input and output as syntax tree
20-
--report <reporter> specify reporter
21-
--file-path <path> specify path to process as
22-
--ignore-pattern <globs> specify ignore patterns
23-
--tree-in specify input as syntax tree
24-
--tree-out output syntax tree
25-
--inspect output formatted syntax tree
26-
--[no-]stdout specify writing to stdout (on by default)
27-
--[no-]color specify color in report (on by default)
28-
--[no-]config search for configuration files (on by default)
29-
--[no-]ignore search for ignore files (on by default)
7+
-h --help output usage information
8+
-v --version output version number
9+
-o --output [path] specify output location
10+
-r --rc-path <path> specify configuration file
11+
-i --ignore-path <path> specify ignore file
12+
-s --setting <settings> specify settings
13+
-e --ext <extensions> specify extensions
14+
-u --use <plugins> use plugins
15+
-w --watch watch for changes and reprocess
16+
-q --quiet output only warnings and errors
17+
-S --silent output only errors
18+
-f --frail exit with 1 on warnings
19+
-t --tree specify input and output as syntax tree
20+
--report <reporter> specify reporter
21+
--file-path <path> specify path to process as
22+
--ignore-path-resolve-from dir|cwd resolve patterns in `ignore-path` from its directory or cwd
23+
--ignore-pattern <globs> specify ignore patterns
24+
--tree-in specify input as syntax tree
25+
--tree-out output syntax tree
26+
--inspect output formatted syntax tree
27+
--[no-]stdout specify writing to stdout (on by default)
28+
--[no-]color specify color in report (on by default)
29+
--[no-]config search for configuration files (on by default)
30+
--[no-]ignore search for ignore files (on by default)
3031

3132
Examples:
3233

test/fixtures/example/LONG_FLAG

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
Error: Unknown option `--no`, expected:
2-
-h --help output usage information
3-
-v --version output version number
4-
-o --output [path] specify output location
5-
-r --rc-path <path> specify configuration file
6-
-i --ignore-path <path> specify ignore file
7-
-s --setting <settings> specify settings
8-
-e --ext <extensions> specify extensions
9-
-u --use <plugins> use plugins
10-
-w --watch watch for changes and reprocess
11-
-q --quiet output only warnings and errors
12-
-S --silent output only errors
13-
-f --frail exit with 1 on warnings
14-
-t --tree specify input and output as syntax tree
15-
--report <reporter> specify reporter
16-
--file-path <path> specify path to process as
17-
--ignore-pattern <globs> specify ignore patterns
18-
--tree-in specify input as syntax tree
19-
--tree-out output syntax tree
20-
--inspect output formatted syntax tree
21-
--[no-]stdout specify writing to stdout (on by default)
22-
--[no-]color specify color in report (on by default)
23-
--[no-]config search for configuration files (on by default)
24-
--[no-]ignore search for ignore files (on by default)
2+
-h --help output usage information
3+
-v --version output version number
4+
-o --output [path] specify output location
5+
-r --rc-path <path> specify configuration file
6+
-i --ignore-path <path> specify ignore file
7+
-s --setting <settings> specify settings
8+
-e --ext <extensions> specify extensions
9+
-u --use <plugins> use plugins
10+
-w --watch watch for changes and reprocess
11+
-q --quiet output only warnings and errors
12+
-S --silent output only errors
13+
-f --frail exit with 1 on warnings
14+
-t --tree specify input and output as syntax tree
15+
--report <reporter> specify reporter
16+
--file-path <path> specify path to process as
17+
--ignore-path-resolve-from dir|cwd resolve patterns in `ignore-path` from its directory or cwd
18+
--ignore-pattern <globs> specify ignore patterns
19+
--tree-in specify input as syntax tree
20+
--tree-out output syntax tree
21+
--inspect output formatted syntax tree
22+
--[no-]stdout specify writing to stdout (on by default)
23+
--[no-]color specify color in report (on by default)
24+
--[no-]config search for configuration files (on by default)
25+
--[no-]ignore search for ignore files (on by default)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
delta.text

test/fixtures/example/delta.text

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
delta

test/index.js

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ test('unified-args', function (t) {
249249
'alpha.text: no issues found',
250250
'bravo.text: no issues found',
251251
'charlie' + sep + 'delta.text: no issues found',
252-
'charlie' + sep + 'echo.text: no issues found'
252+
'charlie' + sep + 'echo.text: no issues found',
253+
'delta.text: no issues found'
253254
].join('\n')
254255

255256
t.plan(1)
@@ -287,7 +288,8 @@ test('unified-args', function (t) {
287288
'alpha.text: no issues found',
288289
'bravo.text: no issues found',
289290
'charlie' + sep + 'delta.text: no issues found',
290-
'charlie' + sep + 'echo.text: no issues found'
291+
'charlie' + sep + 'echo.text: no issues found',
292+
'delta.text: no issues found'
291293
].join('\n')
292294

293295
t.plan(1)
@@ -497,7 +499,62 @@ test('unified-args', function (t) {
497499
'--ext',
498500
'txt,text',
499501
'--ignore-pattern',
500-
'charlie/*,three/*.txt'
502+
'charlie/*,three/*.txt,delta.*'
503+
]).then(onsuccess, t.fail)
504+
505+
function onsuccess(result) {
506+
t.deepEqual(
507+
[result.stdout, strip(result.stderr)],
508+
['', expected],
509+
'should work'
510+
)
511+
}
512+
})
513+
514+
t.test('should support `--ignore-path`', function (t) {
515+
var expected = [
516+
'alpha.text: no issues found',
517+
'bravo.text: no issues found',
518+
'charlie' + sep + 'echo.text: no issues found',
519+
'delta.text: no issues found'
520+
].join('\n')
521+
522+
t.plan(1)
523+
524+
execa(bin, [
525+
'.',
526+
'--ext',
527+
'text',
528+
'--ignore-path',
529+
join('charlie', 'ignore')
530+
]).then(onsuccess, t.fail)
531+
532+
function onsuccess(result) {
533+
t.deepEqual(
534+
[result.stdout, strip(result.stderr)],
535+
['', expected],
536+
'should work'
537+
)
538+
}
539+
})
540+
541+
t.test('should support `--ignore-path-resolve-from cwd`', function (t) {
542+
var expected = [
543+
'alpha.text: no issues found',
544+
'bravo.text: no issues found',
545+
'charlie' + sep + 'echo.text: no issues found'
546+
].join('\n')
547+
548+
t.plan(1)
549+
550+
execa(bin, [
551+
'.',
552+
'--ext',
553+
'text',
554+
'--ignore-path',
555+
join('charlie', 'ignore'),
556+
'--ignore-path-resolve-from',
557+
'cwd'
501558
]).then(onsuccess, t.fail)
502559

503560
function onsuccess(result) {

0 commit comments

Comments
 (0)