diff --git a/.eslintrc.js b/.eslintrc.js index b339f68e23d2ff..b6f5be1d6cf185 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,5 +1,10 @@ const path = require('path'); +const forbidCreateStylesMessage = + 'Use `as const` assertions instead. ' + + '`createStyles` will lead to inlined, at-compile-time-resolved type-imports. ' + + 'See https://github.com/microsoft/TypeScript/issues/36097#issuecomment-578324386 for more information'; + module.exports = { root: true, // So parent files don't get applied globals: { @@ -227,12 +232,53 @@ module.exports = { }, { files: ['*.tsx'], + excludedFiles: '*.spec.tsx', + rules: { + // WARNING: If updated, make sure these rules are merged with `no-restricted-imports` (#ts-source-files) + 'no-restricted-imports': [ + 'error', + { + patterns: [ + // Allow deeper imports for TypeScript types. TODO? + '@material-ui/*/*/*/*', + // Macros are fine since they're transpiled into something else + '!@material-ui/utils/macros/*.macro', + ], + }, + ], + 'react/prop-types': 'off', + }, + }, + // Files used for generating TypeScript declaration files (#ts-source-files) + { + files: ['**/packages/**/src/**/*.tsx'], + excludedFiles: '*.spec.tsx', rules: { 'no-restricted-imports': [ 'error', { - // Allow deeper imports for TypeScript types. TODO? - patterns: ['@material-ui/*/*/*/*', '!@material-ui/utils/macros/*.macro'], + paths: [ + { + name: '@material-ui/core/styles', + importNames: ['createStyles'], + message: forbidCreateStylesMessage, + }, + { + name: '@material-ui/styles', + importNames: ['createStyles'], + message: forbidCreateStylesMessage, + }, + { + name: '@material-ui/styles/createStyles', + message: forbidCreateStylesMessage, + }, + ], + patterns: [ + // Allow deeper imports for TypeScript types. TODO? + '@material-ui/*/*/*/*', + // Macros are fine since they're transpiled into something else + '!@material-ui/utils/macros/*.macro', + ], }, ], 'react/prop-types': 'off',