-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[core] Migrate from tslint to eslint #40020
[core] Migrate from tslint to eslint #40020
Conversation
Netlify deploy previewhttps://deploy-preview-40020--material-ui.netlify.app/ Bundle size report |
Regarding the original issue: #19413 (comment) Are these requirements solved? Or outdated? |
@Janpot I think those rules are still active in Regarding --- a/packages/mui-material/src/Box/Box.spec.tsx
+++ b/packages/mui-material/src/Box/Box.spec.tsx
@@ -1,8 +1,8 @@
import * as React from 'react';
import { Box as SystemBox, createBox } from '@mui/system';
import { expectType } from '@mui/types';
-import Box from '@mui/material/Box';
import { createTheme } from '@mui/material/styles';
+import Box from './Box';
function ThemeValuesCanBeSpread() {
<Box And after running:
I do get the following error:
So, in this migration branch, I attempted to shift this rule to ESLint using the // no relative imports in TypeScript spec files
{
files: ['packages/*/{src,test}/**/*.spec.{ts,tsx}'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: ['.*'],
},
],
},
} However, this resulted in errors for other spec files:
How can we solve this? I'm wondering if there's a ts configuration option to detect this instead of relying on ESLint. As for the Additionally, considering the discovery of other TSLint rules that seem to be active by default, such as I would not have been able to find them without it being explicitly set in the tslint.json config. Also, I referred to this list. Edit: I discovered that all rules marked as |
Looks like the linter is correct - these imports shouldn't be relative according to our rules. However, I don't really see a point in enforcing package-style imports, as paths are rewritten in tests anyway to point to local files. Does this bring any value other than enforcing a convention?
If they are available, sure. One thing to note is that some ESLint rules may be very slow - for example the deprecation rule you mentioned is unusable (I tried it in #38087)
IMO we don't need to have a perfect 1-1 migration between these linters. If we ever spot a pattern that should be discouraged, we can update the config. Let's try to do most of them if possible, but I don't think it's worth spending days on figuring out all the TSLint rules equivalents. |
I agree, that's also not my intention. But we need to make sure we don't drop useful rules. And if we drop them in the context of a certain trade-off, it could be interesting to document that trade-off in the PR. |
I am not sure. Might be just a convention. Sure, I'll check out some helpful rules. Also note that tslint was enabled only for spec files ( |
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.
Ok, so to understand the spirit of why this linter was enabled was to:
- Make sure we are not testing deprecated behavior
- Make sure we import the library by bare specifier in tests.
My take on it would be:
- When new features are deprecated, we should write new tests and keep the old ones. Then remove the old tests wwhen the old behavior is removed. I'm not sure the deprecated rule is very helpful in this process.
- I only find this useful if it means we also rely on default module resolution, but the way it's currently set up is that the bare specifier is an alias for the relative module. I don't see how it adds much value, first thing the bundler does is replace the bare specifier with the relative one.
Ok, we can move forward with this 👍
We had cases in the past where tests would depend on private API. By importing from the barrel index, we force that tests to not rely on private API (even if it doesn't use the exact same code path as developer experiences, the current aliasing system is good enough for that purpose). In any case, I won't miss |
I like that. One solution could be to move the test folder outside of the package folder and into its own workspace (or, I guess, all tests across packages gathered in one workspace). Another advantage of that is that this setup brings us closer to being able to test the actual built package. One drawback would be that tests are less colocated with the implementation. |
But I'm not aware we had issues with the current import setup, the import logic seems to have been close enough so far. |
We're unable to replicate the current Besides that, we have regularly issues with our current setup, e.g. importing the zero config runtime in the docs, or internal packages in X, or in the setup up of most static analysis tools. but that's out of scope for this PR. |
Closes #19413
Should also unblock #38780.
Tried using recommended rules with
@typescript-eslint/recommended
but it throws 2534 errors, so not using it.