-
Notifications
You must be signed in to change notification settings - Fork 751
ci(lint): rule to detect index.ts imports in core #6518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I could not find a lint rule (or a configuration of a lint rule) to achieve this, so I just made one. I tried some things from eslint-plugin-import (namely no-cycles), but I was not happy with the results. This will prevent you from importing from index.ts files while working in packages/core/, which has been a source of annoying and hard to understand circular dependency issues. It only affects imports in core, and only in src/ dirctories that do not start with test/
|
c8817f2 to
abe6160
Compare
abe6160 to
042a307
Compare
| defaultOptions: [], | ||
| create(context) { | ||
| const filePath = context.physicalFilename | ||
| if (!filePath.match(/packages\/core\/src\/(?!test)/)) { |
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.
Is it possible to configure this at the top level in the .eslintrc.js file?
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.
Not that I have found. If you are referring to no-restricted-imports specifically, no because it only matches on the import string literal.
plugins/eslint-plugin-aws-toolkits/lib/rules/no-index-import.ts
Outdated
Show resolved
Hide resolved
| messageId: 'default', | ||
| // TODO: We can add a fixer to resolve the import for us. | ||
| // fix: (fixer) => { | ||
| // // somehow parse the exports of the imported index.ts file to get the actual export path, |
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'm guessing this isn't straightforward? Does ESLint allow you to access this information or would it involve manually reading the file?
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.
Eslint context doesn't seem to offer more than the file it is currently linting. The only thing I can think of is opening the file manually and load it into the ts lib to create an AST.
I could not find a lint rule (or a configuration of a lint rule) to achieve this, so I just made one. I tried some things from eslint-plugin-import (namely no-cycles), but I was not happy with the results.
This will prevent you from importing from index.ts files while working in packages/core/, which has been a source of annoying and hard to understand circular dependency issues. These files should be reserved for exporting to the subprojects only.
It only affects imports in core, and only in src/ directories that do not start with "test"
feature/xbranches will not be squash-merged at release time.