0

For certain folders I would like to enable StyleSheet.create() whereas for other folder I would like to disallow them.

Now I figured out how to override ESLint rules per folder, but how do I disallow StyleSheet.create()?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Z0q
  • 1,689
  • 3
  • 28
  • 57

1 Answers1

0

A way that I used is to restrict the import of StyleSheet. It is even possible to provide a message with the ESLint warning.

enter image description here

"no-restricted-imports": ["warn", {
  "paths": [
    {
      "name": "react-native",
      "importNames": ["StyleSheet"],
      "message": "Please import StyleSheet only in *.styles.ts files within the components folder."
    }
  ],
}],

Then for the override:

overrides: [
  {
    files: [
      'app/components/**/*.styles.ts',
    ],
    rules: {
      "no-restricted-imports": ["error", {}]
    }
  }
],
Z0q
  • 1,689
  • 3
  • 28
  • 57