LoginSignup
4
0

More than 5 years have passed since last update.

[ReactNative]未使用のstyleをESLintで検知したい

Last updated at Posted at 2018-10-18

背景

  • プロジェクトが大きくなっていくとstyleの管理が煩雑になり未使用のstyleが放置されがち
  • コンポーネントの粒度を小さく作れていれば気づけるかもしれないが現実はそうも行かない場面が多い
  • ESLintで検知できたら楽でいいなと思って調べた

やり方

npm i -D eslint eslint-plugin-react eslint-plugin-react-native
# or
yarn add -D eslint eslint-plugin-react eslint-plugin-react-native
  • ESLintの設定に以下の内容を追加
.eslintrc
{
  "env": {
    "react-native/react-native": true
  },
  "plugins": ["react", "react-native"],
  "rules": {
    "react-native/no-unused-styles": 2,
    "react-native/split-platform-components": 2,
    "react-native/no-inline-styles": 2,
    "react-native/no-color-literals": 2,
    "react-native/no-raw-text": 2
  }
}
  • 使われていないstyleを検知したいだけならno-unused-stylesだけでOK
  • エディタと連携していれば赤線がついてすぐに分かる!

スクリーンショット 2018-10-18 19.24.10.png

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0