Skip to content

Commit

Permalink
Fix: no-unpublished-* had been handling files of package.json wit…
Browse files Browse the repository at this point in the history
…h wrong way (fixes #23)
  • Loading branch information
mysticatea committed Feb 1, 2016
1 parent 0bb7ab6 commit e9ef104
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/util/get-npmignore.js
Expand Up @@ -21,7 +21,7 @@ var getPackageJson = require("./get-package-json");
//------------------------------------------------------------------------------

var cache = new Cache();
var TAIL_SLASH = /\/+$/;
var SLASH_AT_BEGIN_END = /(?:^\/+|\/+$)/g;
var PARENT_RELATIVE_PATH = /^\.\./;
var NEVER_IGNORED = /^(?:readme\.[^\.]*|(?:licen[cs]e|changes|changelog|history)(?:\.[^\.]*)?)$/i;

Expand Down Expand Up @@ -107,8 +107,9 @@ function parseWhiteList(files) {
var file = files[i];

if (typeof file === "string") {
file = "/" + file.replace(SLASH_AT_BEGIN_END, "");
ignore.addPattern("!" + file);
ignore.addPattern("!" + file.replace(TAIL_SLASH, "") + "/**");
ignore.addPattern("!" + file + "/**");
}
}

Expand Down
Empty file.
13 changes: 13 additions & 0 deletions tests/lib/rules/no-unpublished-import.js
Expand Up @@ -124,6 +124,12 @@ ruleTester.run("no-unpublished-import", rule, {
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"}
},
{
filename: fixture("3/src/pub/test.js"),
code: "import bbb from 'bbb';",
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"}
},

// `convertPath` option.
{
Expand Down Expand Up @@ -246,6 +252,13 @@ ruleTester.run("no-unpublished-import", rule, {
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"}
},
{
filename: fixture("3/pub/test.js"),
code: "import a from '../src/pub/a.js';",
ecmaFeatures: {modules: true},
parserOptions: {sourceType: "module"},
errors: ["\"../src/pub/a.js\" is not published."]
},

{
filename: fixture("1/test.js"),
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/no-unpublished-require.js
Expand Up @@ -109,6 +109,11 @@ ruleTester.run("no-unpublished-require", rule, {
code: "require('../package.json');",
env: {node: true}
},
{
filename: fixture("3/src/pub/test.js"),
code: "require('bbb');",
env: {node: true}
},

// `convertPath` option.
{
Expand Down Expand Up @@ -250,6 +255,12 @@ ruleTester.run("no-unpublished-require", rule, {
env: {node: true},
errors: ["\"../test\" is not published."]
},
{
filename: fixture("3/pub/test.js"),
code: "require('../src/pub/a.js');",
env: {node: true},
errors: ["\"../src/pub/a.js\" is not published."]
},

{
filename: fixture("1/test.js"),
Expand Down

0 comments on commit e9ef104

Please sign in to comment.