Skip to content

Commit

Permalink
Merge pull request #145 from kaelzhang/7.0.0
Browse files Browse the repository at this point in the history
7.0.0
  • Loading branch information
kaelzhang authored Dec 23, 2024
2 parents d88109f + 079e1b0 commit bc4e324
Show file tree
Hide file tree
Showing 10 changed files with 466 additions and 243 deletions.
39 changes: 24 additions & 15 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
// http://eslint.org/docs/user-guide/configuring

const rules = {
'no-underscore-dangle': ['error', {
allowAfterThis: true,
enforceInMethodNames: false,
// node-ignore only
allow: ['_rules', '_test']
}],

'operator-linebreak': 0,

indent: ['error', 2, {
MemberExpression: 0,

// Eslint bug
ignoreComments: true
}]
}

if (process.platform === 'win32') {
// Ignore linebreak-style on Windows, due to a bug of eslint
rules['linebreak-style'] = 0
}

module.exports = {
// Uses `require.resolve` to support npm linked eslint-config
extends: require.resolve('eslint-config-ostai'),
root: true,
rules: {
'no-underscore-dangle': ['error', {
allowAfterThis: true,
enforceInMethodNames: false,
// node-ignore only
allow: ['_rules', '_test']
}],

indent: ['error', 2, {
MemberExpression: 0,

// Eslint bug
ignoreComments: true
}]
}
rules
}
6 changes: 3 additions & 3 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ on: [push]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [20.x]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
103 changes: 63 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,15 @@
<table><thead>
<tr>
<th>Linux</th>
<th>OS X</th>
<th>Windows</th>
<th>Coverage</th>
<th>Downloads</th>
</tr>
</thead><tbody><tr>
<td colspan="2" align="center">
<a href="https://github.com/kaelzhang/node-ignore/actions/workflows/nodejs.yml">
<img
src="https://github.com/kaelzhang/node-ignore/actions/workflows/nodejs.yml/badge.svg"
alt="Build Status" /></a>
</td>
<td align="center">
<a href="https://ci.appveyor.com/project/kaelzhang/node-ignore">
<img
src="https://ci.appveyor.com/api/projects/status/github/kaelzhang/node-ignore?branch=master&svg=true"
alt="Windows Build Status" /></a>
</td>
<td align="center">
<a href="https://codecov.io/gh/kaelzhang/node-ignore">
<img
src="https://codecov.io/gh/kaelzhang/node-ignore/branch/master/graph/badge.svg"
alt="Coverage Status" /></a>
</td>
<td align="center">
<a href="https://www.npmjs.org/package/ignore">
<img
src="http://img.shields.io/npm/dm/ignore.svg"
alt="npm module downloads per month" /></a>
</td>
</tr></tbody></table>
| Linux / MacOS / Windows | Coverage | Downloads |
| ----------------------- | -------- | --------- |
| [![build][bb]][bl] | [![coverage][cb]][cl] | [![downloads][db]][dl] |

[bb]: https://github.com/kaelzhang/node-ignore/actions/workflows/nodejs.yml/badge.svg
[bl]: https://github.com/kaelzhang/node-ignore/actions/workflows/nodejs.yml

[cb]: https://codecov.io/gh/kaelzhang/node-ignore/branch/master/graph/badge.svg
[cl]: https://codecov.io/gh/kaelzhang/node-ignore

[db]: http://img.shields.io/npm/dm/ignore.svg
[dl]: https://www.npmjs.org/package/ignore

# ignore

Expand Down Expand Up @@ -124,9 +102,11 @@ ig.filter(['.abc\\a.js', '.abc\\d\\e.js'])

## .add(pattern: string | Ignore): this
## .add(patterns: Array<string | Ignore>): this
## .add({pattern: string, mark?: string}): this since 7.0.0

- **pattern** `String | Ignore` An ignore pattern string, or the `Ignore` instance
- **patterns** `Array<String | Ignore>` Array of ignore patterns.
- **pattern** `string | Ignore` An ignore pattern string, or the `Ignore` instance
- **patterns** `Array<string | Ignore>` Array of ignore patterns.
- **mark?** `string` Pattern mark, which is used to associate the pattern with a certain marker, such as the line no of the `.gitignore` file. Actually it could be an arbitrary string and is optional.

Adds a rule or several rules to the current manager.

Expand Down Expand Up @@ -218,7 +198,11 @@ Then the `paths` might be like this:

#### 2. filenames and dirnames

`node-ignore` does NO `fs.stat` during path matching, so for the example below:
`node-ignore` does NO `fs.stat` during path matching, so `node-ignore` treats
- `foo` as a file
- **`foo/` as a directory**

For the example below:

```js
// First, we add a ignore pattern to ignore a directory
Expand Down Expand Up @@ -271,25 +255,64 @@ Creates a filter function which could filter an array of paths with `Array.proto
Returns `function(path)` the filter function.
## .test(pathname: Pathname) since 5.0.0
## .test(pathname: Pathname): TestResult
> New in 5.0.0
Returns `TestResult`
```ts
// Since 5.0.0
interface TestResult {
ignored: boolean
// true if the `pathname` is finally unignored by some negative pattern
unignored: boolean
// The `IgnoreRule` which ignores the pathname
rule?: IgnoreRule
}

// Since 7.0.0
interface IgnoreRule {
// The original pattern
pattern: string
// Whether the pattern is a negative pattern
negative: boolean
// Which is used for other packages to build things upon `node-ignore`
mark?: string
}
```

- `{ignored: true, unignored: false}`: the `pathname` is ignored
- `{ignored: false, unignored: true}`: the `pathname` is unignored
- `{ignored: false, unignored: false}`: the `pathname` is never matched by any ignore rules.

## .checkIgnore(pattern) since 6.1.0
## .checkIgnore(target: string): TestResult

> new in 7.0.0
Debugs gitignore / exclude files, which is equivalent to `git check-ignore -v`. Usually this method is used for other packages to implement the function of `git check-ignore -v` upon `node-ignore`

- **target** `string` the target to test.

> new in 6.1.0
Returns `TestResult`

```js
ig.add({
pattern: 'foo/*',
mark: '60'
})

const {
ignored,
rule
} = checkIgnore('foo/')

if (ignored) {
console.log(`.gitignore:${result}:${rule.mark}:${rule.pattern} foo/`)
}

// .gitignore:60:foo/* foo/
```

Please pay attention that this method does not have a strong built-in cache mechanism.

Expand Down
22 changes: 0 additions & 22 deletions appveyor.yml

This file was deleted.

Loading

0 comments on commit bc4e324

Please sign in to comment.