-
Notifications
You must be signed in to change notification settings - Fork 438
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
Introduce custom ESLint rules to apply and enforce new themed component selector convention #2865
Introduce custom ESLint rules to apply and enforce new themed component selector convention #2865
Conversation
82b630a
to
047528d
Compare
Still some e2e failures, but I'm pretty sure that those tests were already flaky |
ccbd5de
to
0876691
Compare
Hi @ybnd, |
The following cases are covered: - ThemedComponent wrapper selectors must not start with ds-themed- - Base component selectors must start with ds-base- - Themed component selectors must start with ds-themed- - The ThemedComponent wrapper must always be used in HTML - The ThemedComponent wrapper must be used in TypeScript _where appropriate_: - Required - Explicit usages (e.g. modal instantiation, routing modules, ...) - By.css selector queries (in order to align with the HTML rule) - Unchecked - Non-routing modules (to ensure the components can be declared) - ViewChild hooks (since they need to attach to the underlying component) All rules work with --fix to automatically migrate to the new convention This covers most of the codebase, but minor manual adjustment are needed afterwards
- ThemedComponent wrappers should always import their base component. This ensures that it's always enough to only import the wrapper when we use it. - This implies that all themeable components must be standalone → added rules to enforce this → updated usage rule to improve declaration/import handling
Fixes compile-time errors due to out-of-sync inputs and outputs between ThemedConfigurationSearchPageComponent and SearchComponent (note that this is was an existing problem in the source code that flew under the radar until we flipped the selector convention!)
The automatic migration made it so HTML always uses the `Themed*` component, and it must therefore be imported in all standalone components that use it. Afterwards, many unit tests fail because the removed imports no longer match up (can't inject `ThemeService`). While we could try to support this as part of the automatic migration, there are too many edge cases for this to be consistent.
`Themed*` components should be used in the actual codebase to ensure we retain theme support. However, in unit tests these components won't work without a fully-functional `ThemeService` & `Store`. For this reason, the lint plugin allows `ds-base-*` selectors in unit test templates.
0876691
to
a6e0930
Compare
@tdonohue @atarix83 I'm not super familiar with the Docker setup, but it seems like it involves a Added a condition to check whether the lint plugin sources are present before trying to build, let's see if that's enough 🤞 Edit: @artlowel pointed out that that wouldn't be cross-platform, so I changed it to "skip if failed" so we can avoid introducing a new Node dependency just for this one tiny thing. |
There is no cross-platform way to check if the file/directory exists that doesn't depend on adding another NodeJS dependency. This "skip if failed" approach is more noisy, but it should work everywhere.
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.
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.
@ybnd : I've tested this today in production mode (yarn build:prod; yarn serve:ssr
) on Windows 11. While it works for the dspace
theme, the custom
theme is broken. Here's what I see
There are a number of issues that are visible. The header no longer works, no ability to login or browse the site, much of the homepage content no longer displays, etc. Individual item pages are no better.
This doesn't appear to be a caching issue on my end, as after checkout of this PR I ran the following:
yarn clean
yarn install
yarn build:prod
yarn serve:ssr
I also attempted a hard reload in the browser in case this is a CSS issue.
I'll note that with the custom
theme enabled, there are SSR errors that occur such as this one:
ERROR TypeError: Cannot read properties of undefined (reading 'onDestroy')
at Object.ɵɵpipe (C:\dspace-angular\dist\server\main.js:1:4326830)
at template (C:\dspace-angular\dist\server\1210.js:1:3854)
at executeTemplate (C:\dspace-angular\dist\server\main.js:1:4182823)
at renderView (C:\dspace-angular\dist\server\main.js:1:4198373)
at renderComponent (C:\dspace-angular\dist\server\main.js:1:4198106)
at renderChildComponents (C:\dspace-angular\dist\server\main.js:1:4198794)
at renderView (C:\dspace-angular\dist\server\main.js:1:4198836)
at ComponentFactory.create (C:\dspace-angular\dist\server\main.js:1:4235830)
at R3ViewContainerRef.createComponent (C:\dspace-angular\dist\server\main.js:1:4239623)
at Object.next (C:\dspace-angular\dist\server\main.js:1:2265629)
Finally, not all of the new yarn
commands are working for me on Windows. Here's what works and what doesn't:
yarn build:lint
- Succeedsyarn test:lint
- FAILS. I get two errors in thedspace-angular\lint\test\fixture\src\test.ts
file.1) TypeScript rules themed-component-usages invalid disallow direct usages of base class Message: Error: Can't infer project-absolute TS/resource path from: C:\dspace-angular\lint\test\fixture\src\test.ts Occurred while linting C:\dspace-angular\lint\test\fixture\src\test.ts:2 Rule: "themed-component-usages" 2) TypeScript rules themed-component-usages invalid disallow direct usages of base class, keep other imports Message: Error: Can't infer project-absolute TS/resource path from: C:\dspace-angular\lint\test\fixture\src\test.ts Occurred while linting C:\dspace-angular\lint\test\fixture\src\test.ts:2 Rule: "themed-component-usages"
yarn test:lint:nobuild
- FAILS with the same two errors (obviously)yarn lint
- FAILS. I get 97 lint errors in thecustom
theme. All of them say something like "Unthemed version of themable component should have a selector starting with 'ds-base-'". Maybe this is why the "custom" theme is not working for me?yarn lint:nobuild
- FAILS (same asyarn lint
obviously)yarn lint-fix
- Succeeds. It fixes all 97 errors above, but changes 97 files in the "custom" theme in the same way. Here's an example of thediff
change (changedds-themed-admin-sidebar
tods-base-themed-admin-sidebar
):--- a/src/themes/custom/app/admin/admin-sidebar/admin-sidebar.component.ts +++ b/src/themes/custom/app/admin/admin-sidebar/admin-sidebar.component.ts @@ -15,7 +15,7 @@ import { AdminSidebarComponent as BaseComponent } from '../../../../../app/admin * Component representing the admin sidebar */ @Component({ - selector: 'ds-themed-admin-sidebar', + selector: 'ds-base-themed-admin-sidebar'
yarn docs:lint
- Succeeds, but changes all line endings in the/docs/lint/**
subdirectories to CRLF instead of LF. (This is not a serious issue...it's something we could live with if we had to)
While the overall code looks reasonable to me, this doesn't seem to be fully functional (at least not on Windows).
@ybnd : Apologies, I've since discovered that some of the bugs that I've run into are not the cause of this PR. The Unfortunately though, that makes it difficult to fully test this PR until that ticket is fixed. In the meantime though, all the yarn script failures on Windows obviously seem specific to this PR. |
Hi @ybnd, |
This is part of the themed-component-usages rule; Themed* components already import the base component, we don't need to import both anymore. You'll see that all of these changes are also reflected in the base component. Double-checked and this doesn't compromise the fixes from DSpace#2984
@tdonohue couldn't make Monday, hopefully today is still ok timing-wise. |
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.
👍 Thanks @ybnd ! I've retested this today and all the yarn scripts now work on Windows. I've also verified that theming is working as normal & I can still do things like configure a different theme per community/collection and the custom
and dspace
themes both work.
I'll merge this, but I'm also flagging it as needs documentation
. I think this needs to have basic docs created in the Upgrading DSpace documentation as it seems like sites should now run yarn lint --fix
whenever they upgrade? I may need your help with updating these docs so that they are accurate/complete. But if you'd rather provide the details on this PR, then I can copy them into the docs.
References
Add references/links to any related issues or PRs. These may include:
Description
This PR introduces custom ESLint plugins as a means of automatically migrating to the new themed component selector convention proposed in #2845, as well as enforcing this convention moving forward.
Furthermore, these plugins can be leveraged in future PRs to create more rules for DSpace Angular in particular.
Note that this PR also enables linting for our Cypress tests, since they are affected by the selector change (most of the changes there are indentation/import order).
Instructions for Reviewers
TIMING=1 yarn run eslint . --quiet
dspace-angular-ts/themed-component-usages
rule is the most impactful -- it may be useful to optimize it further, but it won't have as much as an effect as Optimize linting performance by disabling "heavy" warning rules #2864Are the messages sufficiently clear?
yarn lint --fix
. The manual interventions can be found in the subsequent commitsdspace
andcustom
themesyarn
scripts work there as well (they have already been tested on MacOS and Linux).Instructions for fork developers
After upgrading your fork to DSpace 8.0, run
yarn lint --quiet --fix
ThemedComponent
wrapperFuture work
I've already worked on similar ESLint rules in a separate project; if we decide to merge this PR it may be useful to port them to the "internal" lint plugin:
@listableObjectComponent
of as observableOf
)And moving forward there are many other DSpace-isms that we could write rules for
ThemedComponent
wrappers match the base component exactlyChecklist
This checklist provides a reminder of what we are going to look for when reviewing your PR. You need not complete this checklist prior to creating your PR (draft PRs are always welcome). If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!
yarn lint
yarn check-circ-deps
)package.json
), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.