-
Notifications
You must be signed in to change notification settings - Fork 18
Conversation
319d3a6
to
ba669f9
Compare
I'm not going to pretend to know what this is doing under the hood but adding a bunch of examples to a test suite would make me feel better about it working |
ba669f9
to
a33ac9a
Compare
@BPScott thanks for pointing that out. I added what would be a test for this fix. However, this new test is pulling from a fixture folder and we are already ignoring when I am going to need to go back and rework the |
a33ac9a
to
9c2ab63
Compare
Updates:
|
code: `import someThing from '../SomeOtherComponent/fixtures/SomeMockQuery/query.json';`, | ||
parserOptions, | ||
errors, | ||
}, |
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 feel like you are not testing the main thing you indicated this PR was to address
const pathParts = resolvedSource | ||
? pathSegmantsFromSource(resolvedSource) | ||
: pathSegmantsFromSource(importSource); | ||
const pathParts = pathSegmantsFromSource(importSource); |
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.
In my opinion, this is not the most useful way to fix this issue. I would rather you never reference the image source, and instead operate on the relative source from the root of the app. Otherwise, I don’t think you’ll ever be able to get this to actually reflect what we want to enforce
f7b5337
to
6a4bacb
Compare
@@ -11,51 +11,62 @@ const parserOptions = { | |||
const errors = [ | |||
{ | |||
type: 'ImportDeclaration', | |||
message: 'Strict component boundaries.', | |||
message: `Do not reach into an individual component's folder for nested modules. Import from the closest shared components folder instead.`, |
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.
cc @GoodForOneFare with regards to #122
Update:
|
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.
Nice, working on absolute paths feels like it protects against false-positives when people do odd things with convoluted relative paths (e.g this should now consistently pass both examples).
Can we add an extra three test cases:
- when a component imports a sibling component using a not the simplest relative path
- when a component's subcomponents import a sibling subcomponent
- when a subcomponent imports its parent's SCSS
The following tests should all pass:
{
code: `import {someThing} from '../../components/Bar';`,
parserOptions,
filename: fixtureFile('basic-app/app/components/Foo/index.js'),
},
{
code: `import {someThing} from '../Baz';`,
parserOptions,
filename: fixtureFile('basic-app/app/components/Foo/components/Bar/index.js'),
},
{
code: `import {someThing} from '../../Foo.scss';`,
parserOptions,
filename: fixtureFile('basic-app/app/components/Foo/components/Bar/index.js'),
}
6a4bacb
to
0a93872
Compare
@BPScott updated with the tests you posted. |
a700321
to
1a4afa1
Compare
…/eslint-plugin-shopify into prefer-explicit-relative-imports * 'prefer-explicit-relative-imports' of github.com:Shopify/eslint-plugin-shopify: review feedback prefer-explicit-local-imports v25.0.01 restoring prettier parser in the typescript config v25.0.0 Fixes strict-component-boundaries (#160) updating prettier config to enable the prettier/prettier rule # Conflicts: # README.md # docs/rules/prefer-explicit-local-imports.md # index.js # lib/config/rules/shopify.js
…fy into add-comments * 'add-comments' of github.com:Shopify/eslint-plugin-shopify: Adds `eslint-plugin-eslint-comments` v25.0.01 restoring prettier parser in the typescript config v25.0.0 Fixes strict-component-boundaries (#160) updating prettier config to enable the prettier/prettier rule v24.2.0 adding graphql config to index updating no-vague-titles rule to fix parsing issues in getMethodName v24.1.1 v24.1.0 adding eslint-plugin-graphql as dependency and new graphql config updating nvmrc version to match module node engine version spec # Conflicts: # CHANGELOG.md # lib/config/rules/eslint-comments.js # package.json # yarn.lock
This PR resolves false positives with strict-component-boundaries that were introduced with #140.
Fixes #156 #122 and #123
Problem:
The check for whether there is a component in the path was returning true if the path to a module included a pascal case word. In #140 this check changed from the ImportDeclaration source to the full path to the module on the users computer. Since
Shopify
is a pascal case word and in most cases there is at least one pascal case word in the full path as inUsers/your-username/path
, this was returning true in almost every ImportDeclaration.Fix:
The solution was to check the import source for the component in path check rather than the full path to the module source.
🎩 Instructions:
yarn add yalc -g
yalc publish
yalc add eslint-plugin-shopify