时间:2021-07-01 10:21:17 帮助过:5人阅读
为了约定大家的代码风格,在社区中诞生了一些比较规范的代码风格规范:
JavaScript Standard Style
Airbnb JavaScript Style
ESLint 只是提供了工具和规则,如何配置这些规则完全取决于使用者。这里使用 Airbnb 配置来说明。
$ npm info "eslint-config-airbnb@latest" peerDependencies { eslint: '^4.19.1', 'eslint-plugin-import': '^2.12.0', 'eslint-plugin-jsx-a11y': '^6.0.3', 'eslint-plugin-react': '^7.9.1' } $ npx -v6.1.0$ npx install-peerdeps --dev eslint-config-airbnb+ eslint-config-airbnb@17.0.0+ eslint-plugin-jsx-a11y@6.1.1+ eslint-plugin-react@7.10.0+ eslint-plugin-import@2.13.0+ eslint@4.19.1SUCCESS eslint-config-airbnb and its peerDeps were installed successfully.
# 创建 package.json$ npm init -y $ eslint --init? How would you like to configure ESLint? Answer questions about your style ❯ Use a popular style guide Inspect your JavaScript file(s) ? Which style guide do you want to follow? Google ❯ Airbnb Standard ? Do you use React? No ? What format do you want your config file to be in? JSON + eslint-plugin-import@2.13.0+ eslint-config-airbnb-base@13.0.0
最后生成 .eslint.json
文件:
{ "extends": "airbnb-base"}
$ ./node_modules/.bin/eslint -v v4.19.1$ ./node_modules/.bin/eslint ./blog//Users/forwardNow/develop/work/study/blog/2018/08/test.js 35:1 warning Unexpected console statement no-console✖ 1 problem (0 errors, 1 warning)
"scripts": { "eslint": "./node_modules/.bin/eslint ./src/"},
搜索并安装 eslint 插件
配置 User Settings:
"editor.detectIndentation": false,"editor.tabSize": 2,"eslint.autoFixOnSave": true,
以上就是js代码风格是怎样的?JavaScript代码风格的介绍的详细内容,更多请关注Gxl网其它相关文章!