Skip to content

Commit

Permalink
[test] Forbid createStyles in ts source files
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Dec 29, 2020
1 parent 22cf61f commit a88b871
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit a88b871

Please sign in to comment.