Skip to content
Permalink
Browse files

πŸ› fix no-unpublished-(require|import) false positive (fixes #126)

  • Loading branch information...
mysticatea committed Jan 4, 2019
1 parent e2fc482 commit 679752b7ef9b98a7a4171589e6b66312e2c2ff96
Showing with 31 additions and 5 deletions.
  1. +13 βˆ’4 lib/util/get-npmignore.js
  2. +12 βˆ’0 tests/fixtures/no-unpublished/issue126/package.json
  3. +6 βˆ’1 tests/lib/rules/no-unpublished-require.js
@@ -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()
}

/**
@@ -0,0 +1,12 @@
{
"private": true,
"name": "test",
"version": "0.0.0",
"files": [
"lib",
"!test.js"
],
"devDependencies": {
"bbb": "0.0.0"
}
}
@@ -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: [
{

0 comments on commit 679752b

Please sign in to comment.
You can’t perform that action at this time.