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

Conversation

alexandcote
Copy link
Contributor

Fix #116

We now exclude the fixtures folder. Maybe we should exclude everything inside tests instead?

Copy link
Contributor

@cartogram cartogram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexandcote thanks for working on this! The test looks good, but what about adding a check for imports with json extensions instead? We are never going to want this rule to flag json imports because they will never be a component.

(hasAnotherComponentInPath(pathParts) && pathParts.length > 1) ||
(hasComponentDirectoryInPath(pathParts) && pathParts.length > 2)
isANotFixtureDirectory(pathParts) &&
((hasAnotherComponentInPath(pathParts) && pathParts.length > 1) ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isANotFixtureDirectory => isNotAFixtureDirectory

@alexandcote
Copy link
Contributor Author

alexandcote commented Jul 20, 2018

@cartogram Do we have any other file extensions that we want to exclude, scss, json, svg, etc.. ?

@@ -39,3 +40,9 @@ function hasComponentDirectoryInPath(pathParts) {
function hasAnotherComponentInPath(pathParts) {
return Boolean(pathParts.filter((part) => part === pascalCase(part)).length);
}

function isASupportedFileType(pathParts) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isASupportedFileType => isSupportedFileType

@@ -39,3 +40,9 @@ function hasComponentDirectoryInPath(pathParts) {
function hasAnotherComponentInPath(pathParts) {
return Boolean(pathParts.filter((part) => part === pascalCase(part)).length);
}

function isASupportedFileType(pathParts) {
const unSupportedType = ['.json', '.svg', '.scss'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there is a reason not to, just keep the .json for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, can you add .graphql

parserOptions,
},
{
code: `import someThing from '../NameOfTheQuery/mock-query.scss';`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are also bad practice so its weird to me they are valid. As I commented above, I think we just keep the .json one to allow for fixtures but I'd rather not loosen this rule more than needed.

@@ -19,8 +19,9 @@ module.exports = {
.filter((part) => part[0] !== '.');

if (
(hasAnotherComponentInPath(pathParts) && pathParts.length > 1) ||
(hasComponentDirectoryInPath(pathParts) && pathParts.length > 2)
isASupportedFileType(pathParts) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isASupportedFileType => isSupportedFileType

@cartogram
Copy link
Contributor

@alexandcote LGTM, did you want to do a patch release?

@lemonmade
Copy link
Member

IMO excluding the fixtures folder is more appropriate here. Some components could easily have assets we don’t want people reaching for (i.e., our emoji picker has a json file for th emoji definition; components have their own private sass files, etc)

@cartogram
Copy link
Contributor

@lemonmade okay, that makes sense to me... didn't realize there were other places where we would be storing json next to a component.

@alexandcote alexandcote force-pushed the exclude-fixtures-strict-component-boundaries branch from 4b53a88 to fe34449 Compare July 25, 2018 14:22
@alexandcote
Copy link
Contributor Author

@lemonmade / @cartogram 👀

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

function isNotAFixtureDirectory(pathParts) {
return Boolean(pathParts.filter((part) => part === 'fixtures').length === 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the Boolean()

@@ -25,6 +25,10 @@ ruleTester.run('strict-component-boundaries', rule, {
code: `import {someThing} from '../OtherComponent';`,
parserOptions,
},
{
code: `import someThing from '../OtherComponent/fixtures/mock-query.json';`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this should be caught, but ../fixtures/OtherComponent/foo.json should not (this means reaching up into another component, and getting its fixture, which doesn't seem right).

@alexandcote
Copy link
Contributor Author

alexandcote commented Jul 25, 2018

Ok, I dig more into this and I found a lot of issue with this rules.

  1. We should probably be able to include everything from an external library like:
import {Subscription} from 'apollo-client/util/Observable';

This trigger a lint error because Observable is PascalCase.

  1. You may need a folder in the GraphQL folder to structure your queries:
import something from '../graphql/SomeMockQuery/Query.graphql'
  1. Tests can need child component:
import MyComponent from '../components/MyComponent'
import MyComponent from '../components/MyComponent/MyComponent'
  1. You may need types from another component :
import {MyType} from 'components/MyComponent/types'
import {MyType} from '../MyComponent/types'
  1. You may need types from a graphql query of another component :
import {MyType} from 'components/MyComponent/types'
  1. You may prefer to use the absolute path:
sections/MyComponent/MyComponent.tsx

import {MyComponent} from 'sections/MyComponent/components'

I only list some of them. I think it will be really hard to handle all those case.
So my question is what we really want to prevent with strict-component-boundaries

@cartogram
Copy link
Contributor

@alexandcote We want to prevent all of those except the first one.

@lemonmade
Copy link
Member

We should actually be able to solve the first one, too. Using resolve from the eslint-module-utils package to get the fully resolved path for a module (see example). That will let us tell if it is in node modules or part of the real project.

@cartogram
Copy link
Contributor

@alexandcote let me know if you need help wrapping this up.

@alexandcote alexandcote force-pushed the exclude-fixtures-strict-component-boundaries branch from 9e87f84 to 5a262ab Compare August 15, 2018 14:09
@alexandcote alexandcote force-pushed the exclude-fixtures-strict-component-boundaries branch from 5a262ab to 6d7584a Compare August 15, 2018 14:10
@alexandcote
Copy link
Contributor Author

Ready for 👀

@cartogram
Copy link
Contributor

@alexandcote additions LGTM. 🚢

@alexandcote alexandcote merged commit 5b56b2e into master Aug 21, 2018
@alexandcote alexandcote deleted the exclude-fixtures-strict-component-boundaries branch August 21, 2018 21:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive with strict-component-boundaries and fixtures
3 participants