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

[strict-component-boundaries] Exclude fixtures folder #117

Merged
merged 6 commits into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed
* `plugin:shopify/flow` now disables rules checked by Flow's static analyzer. ([#135](https://github.com/Shopify/eslint-plugin-shopify/pull/135))
* `plugin:shopify/prettier` and `plugin:shopify/typescript-prettier` defer missing semicolon rules to a project´s `.prettierrc`. ([#135](https://github.com/Shopify/eslint-plugin-shopify/pull/135))
* Updated `strict-component-boundaries` to exclude fixture imports([#117](https://github.com/Shopify/eslint-plugin-shopify/pull/117))

### Changed
* Namespaced `prefer-pascal-case-enums` and `prefer-singular-enums` under `typescript`. ([#141](https://github.com/Shopify/eslint-plugin-shopify/pull/141))
Expand Down
20 changes: 17 additions & 3 deletions lib/rules/strict-component-boundaries.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ module.exports = {
}

if (
(hasAnotherComponentInPath(pathParts) && pathParts.length > 1) ||
(hasComponentDirectoryInPath(pathParts) && pathParts.length > 2)
isInvalidFixtureDirectory(pathParts) &&
((hasAnotherComponentInPath(pathParts) && pathParts.length > 1) ||
(hasComponentDirectoryInPath(pathParts) && pathParts.length > 2))
) {
context.report({
node,
Expand All @@ -54,7 +55,20 @@ 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] !== '.');
}

function isInvalidFixtureDirectory(pathParts) {
const fixtureIndex = pathParts.indexOf('fixtures');

if (fixtureIndex === -1) {
return true;
}

const pathBeforeFixture = pathParts.slice(0, fixtureIndex);
return (
hasComponentDirectoryInPath(pathBeforeFixture) ||
hasAnotherComponentInPath(pathBeforeFixture)
);
}
14 changes: 14 additions & 0 deletions tests/lib/rules/strict-component-boundaries.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ ruleTester.run('strict-component-boundaries', rule, {
parserOptions,
filename: fixtureFile('basic-app/app/sections/MySection/MySection.js'),
},
{
code: `import someThing from '../fixtures/SomeMockQuery/query.json';`,
parserOptions,
},
],
invalid: [
{
Expand All @@ -53,5 +57,15 @@ ruleTester.run('strict-component-boundaries', rule, {
parserOptions,
errors,
},
{
code: `import someThing from '../SomeComponent/fixtures/SomeMockQuery/query.json';`,
parserOptions,
errors,
},
{
code: `import someThing from './components/SomeComponent/fixtures/SomeMockQuery/query.json';`,
parserOptions,
errors,
},
],
});