Skip to content

Commit

Permalink
🐛 fix no-unpublished-(require|import) false positive (fixes #126)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jan 4, 2019
1 parent e2fc482 commit 679752b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
17 changes: 13 additions & 4 deletions lib/util/get-npmignore.js
Expand Up @@ -84,17 +84,26 @@ function parseWhiteList(files) {
}

const ig = ignore()
const igN = ignore()
let hasN = false

for (const file of files) {
if (typeof file === "string" && file) {
const prefix = file.startsWith("!") ? "!" : ""
const body = file.replace(SLASH_AT_BEGIN_AND_END, "")
ig.add(`${prefix}/${body}`)
ig.add(`${prefix}/${body}/**`)
if (file.startsWith("!")) {
igN.add(`${body}`)
igN.add(`${body}/**`)
hasN = true
} else {
ig.add(`/${body}`)
ig.add(`/${body}/**`)
}
}
}

return ig.createFilter()
return hasN
? or(ig.createFilter(), not(igN.createFilter()))
: ig.createFilter()
}

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/fixtures/no-unpublished/issue126/package.json
@@ -0,0 +1,12 @@
{
"private": true,
"name": "test",
"version": "0.0.0",
"files": [
"lib",
"!test.js"
],
"devDependencies": {
"bbb": "0.0.0"
}
}
7 changes: 6 additions & 1 deletion tests/lib/rules/no-unpublished-require.js
Expand Up @@ -240,10 +240,15 @@ ruleTester.run("no-unpublished-require", rule, {

// Negative patterns in files field.
{
code: "require('bbb');",
code: "require('bbb'); //XXX",
filename: fixture("negative-in-files/lib/__test__/index.js"),
env: { node: true },
},
{
code: "require('bbb'); //XXX",
filename: fixture("issue126/lib/test.js"),
env: { node: true },
},
],
invalid: [
{
Expand Down

0 comments on commit 679752b

Please sign in to comment.