Skip to content

Commit

Permalink
Change to include dotfiles by default
Browse files Browse the repository at this point in the history
Closes GH-55.
  • Loading branch information
wooorm committed Aug 17, 2023
1 parent 65da801 commit 2249314
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 28 deletions.
6 changes: 2 additions & 4 deletions doc/ignore.md
Expand Up @@ -47,10 +47,8 @@ directory instead, by setting
(default).

If paths or globs to directories are given to the engine, they will be searched
for matching files, but `node_modules` and hidden directories (those starting
with a dot, `.`, such as `.git`) are normally not searched.
Pass paths or globs to files or those directories to include files inside
`node_modules` and hidden directories.
for matching files, but `node_modules` are normally not searched.
Pass paths or globs to `node_modules` to include files inside them.

The format for ignore files is the same as [`.gitignore`][gitignore], so it’s
possible to pass a `.gitignore` in as [`ignorePath`][ignore-path].
Expand Down
3 changes: 1 addition & 2 deletions doc/options.md
Expand Up @@ -104,8 +104,7 @@ Directories and globs to directories can be given alongside
[`extensions`][extensions] to search directories for files matching an extension
(for example, `dir` to add `dir/readme.txt` and `dir/sub/history.text` if
`extensions` is `['txt', 'text']`).
This searching will not include `node_modules` or hidden directories (those
starting with a dot, `.`, like `.git`).
This searching will not include `node_modules`, but you can pass it explicitly.
* Type: `Array<string | URL | VFile>`
* Default: `[]`
Expand Down
6 changes: 1 addition & 5 deletions lib/finder.js
Expand Up @@ -267,11 +267,7 @@ function search(input, options, next) {

const part = base(file)

if (
options.nested &&
part &&
(part.charAt(0) === '.' || part === 'node_modules')
) {
if (options.nested && part && part === 'node_modules') {
return
}

Expand Down
7 changes: 6 additions & 1 deletion test/color.js
@@ -1,4 +1,5 @@
import assert from 'node:assert/strict'
import fs from 'node:fs/promises'
import test from 'node:test'
import {promisify} from 'node:util'
import {engine} from '../index.js'
Expand All @@ -11,10 +12,14 @@ const fixtures = new URL('fixtures/', import.meta.url)

test('color', async function (t) {
await t.test('should support color', async function () {
const cwd = new URL('empty/', fixtures)
const stderr = spy()

await fs.mkdir(cwd, {recursive: true})

const code = await run({
color: true,
cwd: new URL('empty/', fixtures),
cwd,
files: ['readme.md'],
processor: noop,
streamError: stderr.stream
Expand Down
6 changes: 5 additions & 1 deletion test/file-path.js
@@ -1,4 +1,5 @@
import assert from 'node:assert/strict'
import fs from 'node:fs/promises'
import {sep} from 'node:path'
import {PassThrough} from 'node:stream'
import test from 'node:test'
Expand Down Expand Up @@ -27,15 +28,18 @@ test('file-path', async function (t) {
})

await t.test('should support `filePath`', async function () {
const cwd = new URL('empty/', fixtures)
const stderr = spy()
const stdout = spy()
const stream = new PassThrough()
let index = 0

await fs.mkdir(cwd, {recursive: true})

send()

const code = await run({
cwd: new URL('empty/', fixtures),
cwd,
filePath: 'foo' + sep + 'bar.baz',
processor: noop,
streamError: stderr.stream,
Expand Down
2 changes: 0 additions & 2 deletions test/fixtures/hidden-directory/.fooignore

This file was deleted.

File renamed without changes.
Empty file.
50 changes: 48 additions & 2 deletions test/ignore.js
Expand Up @@ -89,14 +89,35 @@ test('ignore', async function (t) {
)
})

await t.test('should not look into hidden files', async function () {
await t.test('should look into hidden files', async function () {
const stderr = spy()

const code = await run({
cwd: new URL('hidden-directory/', fixtures),
extensions: ['txt'],
files: ['.'],
// No `ignoreName`.
processor: noop,
streamError: stderr.stream
})

assert.equal(code, 0)
assert.equal(
stderr(),
[
'.hidden' + sep + 'two.txt: no issues found',
'one.txt: no issues found',
''
].join('\n')
)
})

await t.test('should not look into `node_modules`', async function () {
const stderr = spy()

const code = await run({
cwd: new URL('node-modules-directory/', fixtures),
extensions: ['txt'],
files: ['.'],
processor: noop,
streamError: stderr.stream
})
Expand All @@ -105,6 +126,31 @@ test('ignore', async function (t) {
assert.equal(stderr(), 'one.txt: no issues found\n')
})

await t.test(
'should look into `node_modules` w/ explicit search',
async function () {
const stderr = spy()

const code = await run({
cwd: new URL('node-modules-directory/', fixtures),
extensions: ['txt'],
files: ['node_modules/', '.'],
processor: noop,
streamError: stderr.stream
})

assert.equal(code, 0)
assert.equal(
stderr(),
[
'node_modules' + sep + 'two.txt: no issues found',
'one.txt: no issues found',
''
].join('\n')
)
}
)

await t.test('should support no ignore files', async function () {
const stderr = spy()

Expand Down
34 changes: 29 additions & 5 deletions test/input.js
Expand Up @@ -3,6 +3,7 @@
*/

import assert from 'node:assert/strict'
import fs from 'node:fs/promises'
import {join, sep} from 'node:path'
import {PassThrough} from 'node:stream'
import test from 'node:test'
Expand Down Expand Up @@ -56,10 +57,13 @@ test('input', async function (t) {
})

await t.test('should not fail on unmatched given globs', async function () {
const cwd = new URL('empty/', fixtures)
const stderr = spy()

await fs.mkdir(cwd, {recursive: true})

const code = await run({
cwd: new URL('empty/', fixtures),
cwd,
files: ['.'],
processor: unified(),
streamError: stderr.stream
Expand All @@ -70,10 +74,13 @@ test('input', async function (t) {
})

await t.test('should report unfound given files', async function () {
const cwd = new URL('empty/', fixtures)
const stderr = spy()

await fs.mkdir(cwd, {recursive: true})

const code = await run({
cwd: new URL('empty/', fixtures),
cwd,
files: ['readme.md'],
processor: unified(),
streamError: stderr.stream
Expand Down Expand Up @@ -101,6 +108,7 @@ test('input', async function (t) {

const code = await run({
cwd: new URL('directory/', fixtures),
extensions: ['txt'],
files: ['empty/'],
processor: unified(),
streamError: stderr.stream
Expand Down Expand Up @@ -374,6 +382,8 @@ test('input', async function (t) {
const stderr = spy()
const cwd = new URL('empty/', fixtures)

await fs.mkdir(cwd, {recursive: true})

const code = await run({
cwd,
files: [
Expand Down Expand Up @@ -421,6 +431,8 @@ test('input', async function (t) {
const cwd = join('test', 'fixtures', 'empty')
const file = new VFile({value: 'foo'})

await fs.mkdir(cwd, {recursive: true})

const code = await run({
cwd,
files: [file],
Expand Down Expand Up @@ -523,9 +535,12 @@ test('input', async function (t) {
await t.test(
'should fail w/ `ignoreUnconfigured` and `rcPath`',
async function () {
const cwd = new URL('empty/', fixtures)
await fs.mkdir(cwd, {recursive: true})

try {
await run({
cwd: new URL('empty/', fixtures),
cwd,
files: ['.'],
ignoreUnconfigured: true,
processor: unified(),
Expand All @@ -545,9 +560,12 @@ test('input', async function (t) {
await t.test(
'should fail w/ `ignoreUnconfigured` and w/o `rcName`, `packageField`',
async function () {
const cwd = new URL('empty/', fixtures)
await fs.mkdir(cwd, {recursive: true})

try {
await run({
cwd: new URL('empty/', fixtures),
cwd,
files: ['.'],
ignoreUnconfigured: true,
processor: unified(),
Expand All @@ -566,9 +584,12 @@ test('input', async function (t) {
await t.test(
'should fail w/ `ignoreUnconfigured` and `detectConfig: false`',
async function () {
const cwd = new URL('empty/', fixtures)
await fs.mkdir(cwd, {recursive: true})

try {
await run({
cwd: new URL('empty/', fixtures),
cwd,
detectConfig: false,
files: ['.'],
ignoreUnconfigured: true,
Expand All @@ -593,6 +614,7 @@ test('input', async function (t) {
const code = await run({
cwd: new URL('config-ignore-unconfigured/', fixtures),
files: ['.'],
extensions: ['txt'],
ignoreUnconfigured: true,
processor: noop,
rcName: '.foorc',
Expand Down Expand Up @@ -633,6 +655,8 @@ test('input', async function (t) {
const cwd = new URL('empty/', fixtures)
const stderr = spy()

await fs.mkdir(cwd, {recursive: true})

const code = await run({
cwd,
files: [
Expand Down
2 changes: 2 additions & 0 deletions test/output.js
Expand Up @@ -358,6 +358,8 @@ test('output', async function (t) {
const targetFile = new URL('one.txt', cwd)
const stderr = spy()

await fs.mkdir(cwd, {recursive: true})

const code = await run({
cwd,
extensions: ['txt'],
Expand Down
19 changes: 13 additions & 6 deletions test/stdin.js
@@ -1,4 +1,5 @@
import assert from 'node:assert/strict'
import fs from 'node:fs/promises'
import {PassThrough} from 'node:stream'
import test from 'node:test'
import {promisify} from 'node:util'
Expand All @@ -11,16 +12,19 @@ const fixtures = new URL('fixtures/', import.meta.url)

test('stdin', async function (t) {
await t.test('should support stdin', async function () {
const stdout = spy()
const cwd = new URL('empty/', fixtures)
const stderr = spy()
const stdout = spy()
const stream = new PassThrough()
let index = 0

await fs.mkdir(cwd, {recursive: true})

setImmediate(send)

const code = await run({
cwd,
processor: noop,
cwd: new URL('empty/', fixtures),
streamIn: stream,
streamOut: stdout.stream,
streamError: stderr.stream
Expand All @@ -41,20 +45,23 @@ test('stdin', async function (t) {
})

await t.test('should not output if `out: false`', async function () {
const stdout = spy()
const cwd = new URL('empty/', fixtures)
const stderr = spy()
const stdout = spy()
const stream = new PassThrough()
let index = 0

await fs.mkdir(cwd, {recursive: true})

setImmediate(send)

const code = await run({
cwd,
out: false,
processor: noop,
cwd: new URL('empty/', fixtures),
streamIn: stream,
streamOut: stdout.stream,
streamError: stderr.stream,
out: false
streamError: stderr.stream
})

assert.equal(code, 0)
Expand Down

0 comments on commit 2249314

Please sign in to comment.