Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
cartogram committed Aug 4, 2018
1 parent 5156b13 commit 287915b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
29 changes: 14 additions & 15 deletions lib/rules/strict-component-boundaries.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ module.exports = {
return {
ImportDeclaration(node) {
const importSource = node.source.value;
const pathParts = importSource
.split('/')
.filter((part) => part[0] !== '.');
const resolvedSource = resolve(importSource, context);
const pathParts = resolvedSource
? pathSegmantsFromSource(resolvedSource)
: pathSegmantsFromSource(importSource);

if (inNodeModules(importSource, context)) {
if (isCoreModule(resolvedSource) || inNodeModules(pathParts)) {
return;
}

Expand All @@ -38,18 +39,12 @@ module.exports = {
},
};

function inNodeModules(importSource, context) {
const resolvedSource = resolve(importSource, context);

if (resolvedSource === null) {
return true;
}

if (!resolvedSource) {
return false;
}
function isCoreModule(resolvedSource) {
return resolvedSource === null;
}

return resolvedSource.match(/node_modules/);
function inNodeModules(pathParts) {
return Boolean(pathParts.filter((part) => part === 'node_modules').length);
}

function hasComponentDirectoryInPath(pathParts) {
Expand All @@ -59,3 +54,7 @@ function hasComponentDirectoryInPath(pathParts) {
function hasAnotherComponentInPath(pathParts) {
return Boolean(pathParts.filter((part) => part === pascalCase(part)).length);
}

function pathSegmantsFromSource(source) {
return source.split('/').filter((part) => part[0] !== '.');
}

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

8 changes: 3 additions & 5 deletions tests/lib/rules/strict-component-boundaries.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const {RuleTester} = require('eslint');
const {fixtureFile} = require('../../utilities');
const rule = require('../../../lib/rules/strict-component-boundaries');

const ruleTester = new RuleTester();
Expand Down Expand Up @@ -26,12 +27,9 @@ ruleTester.run('strict-component-boundaries', rule, {
parserOptions,
},
{
code: `import fs from 'fs';`,
parserOptions,
},
{
code: `import eslint from 'eslint';`,
code: `import {getDisplayName} from '@shopify/react-utilities/components';`,
parserOptions,
filename: fixtureFile('basic-app/app/sections/MySection/MySection.js'),
},
],
invalid: [
Expand Down

0 comments on commit 287915b

Please sign in to comment.