-
Notifications
You must be signed in to change notification settings - Fork 18
[strict-component-boundaries] Exclude fixtures folder #117
[strict-component-boundaries] Exclude fixtures folder #117
Conversation
There was a problem hiding this 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) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isANotFixtureDirectory
=> isNotAFixtureDirectory
@cartogram Do we have any other file extensions that we want to exclude, |
@@ -39,3 +40,9 @@ function hasComponentDirectoryInPath(pathParts) { | |||
function hasAnotherComponentInPath(pathParts) { | |||
return Boolean(pathParts.filter((part) => part === pascalCase(part)).length); | |||
} | |||
|
|||
function isASupportedFileType(pathParts) { |
There was a problem hiding this comment.
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']; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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';`, |
There was a problem hiding this comment.
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) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isASupportedFileType
=> isSupportedFileType
@alexandcote LGTM, did you want to do a patch release? |
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) |
@lemonmade okay, that makes sense to me... didn't realize there were other places where we would be storing |
4b53a88
to
fe34449
Compare
@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); |
There was a problem hiding this comment.
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';`, |
There was a problem hiding this comment.
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).
Ok, I dig more into this and I found a lot of issue with this rules.
This trigger a lint error because
I only list some of them. I think it will be really hard to handle all those case. |
@alexandcote We want to prevent all of those except the first one. |
We should actually be able to solve the first one, too. Using |
@alexandcote let me know if you need help wrapping this up. |
9e87f84
to
5a262ab
Compare
5a262ab
to
6d7584a
Compare
Ready for 👀 |
@alexandcote additions LGTM. 🚢 |
Fix #116
We now exclude the
fixtures
folder. Maybe we should exclude everything inside tests instead?