项目作者: bhuvnesh93

项目描述 :
Eslint & Prettier Installation in React Native
高级语言: JavaScript
项目地址: git://github.com/bhuvnesh93/eslint-prettier-example.git
创建时间: 2020-07-25T16:49:53Z
项目社区:https://github.com/bhuvnesh93/eslint-prettier-example

开源协议:

下载


eslint-prettier-example

Code style

We use eslint and prettier for code formatting and linting.

ESLint

ESLint Setup

yarn add eslint -D

yarn add eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react-native -D

Prettier

Update .eslintrc.js with following lines

  1. {
  2. "extends": [
  3. "airbnb"
  4. ]
  5. }

Prettier Setup

yarn add prettier eslint-config-prettier eslint-plugin-prettier -D

Update .eslintrc.js with following lines

  1. module.exports = {
  2. root: true,
  3. extends: ['airbnb', 'prettier', 'prettier/react'],
  4. parser: 'babel-eslint',
  5. rules: {
  6. 'import/prefer-default-export': 0,
  7. 'class-methods-use-this': 0,
  8. 'no-console': 0,
  9. 'no-plusplus': 'off',
  10. 'no-param-reassign': 0,
  11. 'global-require': 0,
  12. 'react/prop-types': 0,
  13. 'react/jsx-props-no-spreading': 0,
  14. 'no-unused-expressions': 0,
  15. 'import/extensions': 0,
  16. 'no-use-before-define': ['error', { variables: false }],
  17. 'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
  18. 'import/no-cycle': [0, { maxDepth: 1 }],
  19. 'react/jsx-filename-extension': [
  20. 1,
  21. {
  22. extensions: ['.js', '.jsx'],
  23. },
  24. ],
  25. 'prettier/prettier': [
  26. 'error',
  27. {
  28. bracketSpacing: true,
  29. jsxBracketSameLine: true,
  30. singleQuote: true,
  31. printWidth: 100,
  32. trailingComma: 'es5',
  33. tabWidth: 2,
  34. semi: true,
  35. },
  36. ],
  37. },
  38. env: {
  39. jest: true,
  40. },
  41. plugins: ['prettier'],
  42. };

Update .prettierrc.js with following lines

  1. module.exports = {
  2. bracketSpacing: true,
  3. jsxBracketSameLine: true,
  4. singleQuote: true,
  5. printWidth: 100,
  6. trailingComma: 'es5',
  7. tabWidth: 2,
  8. semi: true
  9. };

Note : You can modify the configuration according to requirement.