您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Intellij插件:带React的AirBnB ESLint

Intellij插件:带React的AirBnB ESLint

JetBrains(想法,Webstorm)设置_File>设置>插件>浏览存储库…>搜索:eslint>安装

重新启动WebStorm_

文件>设置>语言和框架> JavaScript>代码质量工具>ESLint

之后,它应该像这样工作:

在此处输入图片说明

ESLint配置ESLint不附带配置。您必须创建自己的或使用 预设:

npm install --save-dev eslint-config-airbnb eslint

然后在您的.eslintrc中

{
  "extends": "airbnb"
}

您还可以从预设中有选择地禁用/修改某些规则(0-禁用规则,1-警告,2-错误):

{
  'extends': 'airbnb',
  'rules': {
    'indent': [2, 'tab', { 'SwitchCase': 1, 'VariableDeclarator': 1 }],
    'react/prop-types': 0,
    'react/jsx-indent-props': [2, 'tab'],
  }
}

阅读:关闭特定行的eslint规则。

如果您不想使用airbnb config(最受欢迎的javascript样式指南),则可以创建自己的配置。这是react的说明:如何在AtomEditor 上为React 配置ESLint

要创建自己的预设,您必须创建名为eslint-config-mynamenpm软件包,然后使用'extends': 'myname', http://eslint.org/docs/developer-guide/shareable-configs

您可以使用命令行检查eslint是否有效:

./node_modules/.bin/eslint .

不过,您可以在.eslintignore中排除某些文件认情况下不包括node_modules):

bundle.js

还有一个–fix用于eslint 的开关。

.editorconfigESLint的好伴侣是editorconfig。这是在JetBrains产品中使用的示例:

root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true


# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,jsx,html,sass}]
charset = utf-8
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true

# don't use {} for single extension. This won't work: [*.{css}]
[*.css]
indent_style = space
indent_size = 2

I also have a github repository which already has these files sethttps://github.com/rofrol/react-starter-kit/

Based on this https://www.themarketingtechnologist.co/how-to-get-airbnbs- javascript-code-style-working-in-webstorm/

More here https://www.jetbrains.com/webstorm/help/using-javascript-code- quality-tools.html

其他 2022/1/1 18:15:15 有444人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶