Skip to content

Commit

Permalink
code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Mar 2, 2023
1 parent 2d503cc commit ef3f0fb
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ be escaped or unescaped.
Un-escape a glob string that may contain some escaped characters.

If the `windowsPathsNoEscape` option is used, then square-brace
escapes are removed, but not backslash escapes. For example, it
escapes are removed, but not backslash escapes. For example, it
will turn the string `'[*]'` into `*`, but it will not turn
`'\\*'` into `'*'`, because `\` is a path separator in
`windowsPathsNoEscape` mode.
Expand Down
6 changes: 4 additions & 2 deletions src/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@ export abstract class GlobUtil<O extends GlobWalkerOpts = GlobWalkerOpts> {
this.matchEmit(e.fullpath() + mark)
} else {
const rel = e.relative()
const pre = this.opts.dotRelative && !rel.startsWith('..' + this.#sep)
? '.' + this.#sep : ''
const pre =
this.opts.dotRelative && !rel.startsWith('..' + this.#sep)
? '.' + this.#sep
: ''
this.matchEmit(!rel && mark ? '.' + mark : pre + rel + mark)
}
}
Expand Down
27 changes: 15 additions & 12 deletions test/dot-relative.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import t from 'tap'
import { Glob } from '../'
import { bashResults } from './bash-results'
import {resolve, sep} from 'path'
import { resolve, sep } from 'path'

const pattern = 'a/b/**'
process.chdir(__dirname + '/fixtures')
Expand Down Expand Up @@ -39,19 +39,22 @@ for (const mark of marks) {
}
})

t.test('does not prefix with ./ unless dotRelative is true', async t => {
const g = new Glob(pattern, {})
const results = await g.walk()
t.test(
'does not prefix with ./ unless dotRelative is true',
async t => {
const g = new Glob(pattern, {})
const results = await g.walk()

t.equal(
results.length,
bashResults[pattern].length,
'must match all files'
)
for (const m of results) {
t.ok(mark && m === '.' + sep || !m.startsWith('.' + sep))
t.equal(
results.length,
bashResults[pattern].length,
'must match all files'
)
for (const m of results) {
t.ok((mark && m === '.' + sep) || !m.startsWith('.' + sep))
}
}
})
)
})
}

Expand Down
13 changes: 9 additions & 4 deletions test/escape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ for (const pattern of Object.keys(bashResults)) {
t.notOk(hasMagic(escape(pattern)), `escape(${pattern})`)
const pp = escape(pattern)
const pw = escape(pattern, {
windowsPathsNoEscape: true
windowsPathsNoEscape: true,
})
t.notOk(hasMagic(pp, { platform: 'linux' }), 'no magic after posix escape')
t.notOk(hasMagic(pw, { platform: 'win32', windowsPathsNoEscape: true }),
'no magic after windows escape')
t.notOk(
hasMagic(pp, { platform: 'linux' }),
'no magic after posix escape'
)
t.notOk(
hasMagic(pw, { platform: 'win32', windowsPathsNoEscape: true }),
'no magic after windows escape'
)
const up = unescape(pp)
const uw = unescape(pw, { windowsPathsNoEscape: true })
t.equal(up, pattern, 'unescaped posix pattern returned')
Expand Down
6 changes: 3 additions & 3 deletions test/url-cwd.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import t from 'tap'
import {pathToFileURL} from 'url'
import {Glob} from '../'
import { pathToFileURL } from 'url'
import { Glob } from '../'

t.test('can use file url as cwd option', t => {
const fileURL = pathToFileURL(process.cwd())
const fileURLString = String(fileURL)
const ps = new Glob('.', { cwd: process.cwd()})
const ps = new Glob('.', { cwd: process.cwd() })
const pu = new Glob('.', { cwd: fileURL })
const pus = new Glob('.', { cwd: fileURLString })
t.equal(ps.cwd, process.cwd())
Expand Down

0 comments on commit ef3f0fb

Please sign in to comment.