RNX's ESLint config, for a better code style.
RNX’s ESLint config, for a better code style.
this
;if
(参考);PropTypes.object
;在项目根目录下执行:
npm install eslint-config-rnx --save-dev
.eslintrc
文件指定使用 RNX 编码规范。在项目根目录下创建 .eslintrc
文件。
{
// 使用 RNX 编码规范
extends: 'eslint-config-rnx',
}
使 Atom 支持 eslint 规范检查。
# 安装 linter 插件
apm install linter
# 安装 linter-eslint 插件
apm install linter-eslint
使 VS Code 支持 eslint 规范检查。
安装插件 ESLint
主要为使 tab 键符合编码规范的同时不至于影响 Atom 中的其他项目。
使 Atom 支持 editorconfig。
apm install editorconfig
.editorconfig
文件配置缩进(使用双空格缩进)。在项目根目录下创建 .editorconfig
文件。
root = true
[*.js]
indent_style = space
indent_size = 2
在项目根目录下执行:
./node_modules/.bin/eslint <filename/directory>
如果安装了 Atom 插件,那么自动运行,并在 Atom 下方显示实时状态。
.editorconfig
不是实时生效的,你需要重启 Atom 后才能生效;.eslintrc
也不是实时生效的,你需要在 Atom 中运行 linter: lint
命令或者重新打开待检测文件才能生效;Linter Eslint: Fix File
命令可以让 Atom 自动完成简单的格式化操作。