Skip to content

Commit

Permalink
fix: node_modules packages were being recognized as local
Browse files Browse the repository at this point in the history
  • Loading branch information
javierbrea committed Jan 26, 2021
1 parent f77720a commit 0775c05
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
branches:
- master
- release
- release-v2.0.0-beta.2
- pre-release
pull_request:
jobs:
test:
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Removed
### BREAKING CHANGES

## [2.0.0-beta.3] - 2021-01-26

### Fixed
- fix: node_modules packages were being recognized as local

## [2.0.0-beta.2] - 2021-01-26

### Fixed
- feat: Add folder resolver-legacy-alias to npm package
- fix: Add folder resolver-legacy-alias to npm package

## [2.0.0-beta.1] - 2021-01-26

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-boundaries",
"version": "2.0.0-beta.2",
"version": "2.0.0-beta.3",
"description": "Eslint plugin checking architecture boundaries between elements",
"keywords": [
"eslint",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sonar.organization=javierbrea
sonar.projectKey=eslint-plugin-boundaries
sonar.projectVersion=2.0.0-beta.2
sonar.projectVersion=2.0.0-beta.3

sonar.javascript.file.suffixes=.js
sonar.sourceEncoding=UTF-8
Expand Down
16 changes: 10 additions & 6 deletions src/core/elementsInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ function isScoped(name) {

const externalModuleRegExp = /^\w/;
function isExternal(name, path) {
return !path && (externalModuleRegExp.test(name) || isScoped(name));
return (
(!path || (!!path && path.indexOf("node_modules") === 0)) &&
(externalModuleRegExp.test(name) || isScoped(name))
);
}

function elementCaptureValues(capture, captureSettings) {
Expand Down Expand Up @@ -145,15 +148,16 @@ function importInfo(source, context) {
const path = projectPath(resolve(source, context));
const isBuiltInModule = isBuiltIn(source, path);
const isExternalModule = isExternal(source, path);
const pathToUse = isExternalModule ? null : path;
return {
source,
path,
isIgnored: isIgnored(path, context.settings),
isLocal: !!path && !isBuiltInModule && !isExternalModule,
path: pathToUse,
isIgnored: !isExternalModule && isIgnored(pathToUse, context.settings),
isLocal: !isExternalModule && !isBuiltInModule,
isBuiltIn: isBuiltInModule,
isExternal: isExternalModule,
baseModule: baseModule(source, path),
...elementTypeAndParents(path, context.settings),
baseModule: baseModule(source, pathToUse),
...elementTypeAndParents(pathToUse, context.settings),
};
}

Expand Down
5 changes: 5 additions & 0 deletions test/rules/docs-examples/no-unknown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ ruleTester.run(RULE, rule, {
filename: absoluteFilePath("index.js"),
code: "import foo from './foo'",
},
// External dependencies can be imported
{
filename: absoluteFilePath("components/atoms/atom-a/AtomA.js"),
code: "import 'chalk'",
},
],
invalid: [
// Helpers can't import `foo.js` file because it is unknown
Expand Down
5 changes: 5 additions & 0 deletions test/rules/one-level/no-unknown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const test = (settings) => {
filename: absoluteFilePath("components/component-a/ComponentA.js"),
code: "import ComponentB from 'components/component-b'",
},
// External dependencies can be imported
{
filename: absoluteFilePath("components/component-a/ComponentA.js"),
code: "import 'chalk'",
},
],
invalid: [
// Not recognized type
Expand Down
5 changes: 5 additions & 0 deletions test/rules/two-levels/external.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ const test = (settings, options, { absoluteFilePath }) => {
code: "import React from 'react'",
options,
},
// External dependencies can be imported
{
filename: absoluteFilePath("modules/pages/page-a/PageA.js"),
code: "import 'chalk'",
},
],
invalid: [
// Helpers can't import react
Expand Down

0 comments on commit 0775c05

Please sign in to comment.