sublime配置ESLint_Linting React/JSX and ES6 Javascript with Eslint in Sublime Text 3
2017-11-24 20:59
597 查看
A few weeks ago, I wrote a blog on how to setup
ST3 for React dev. Since then, I learned more about react development, I started to use eslint. Jslint is great but it does not support JSX. We need a linter that can be integrated with ST3 and show live linting result while coding. This is where eslint comes
in.
You can install it either globally or locally. I installed it globally:
The only hiccup to start using eslint is its stunning numbers of configurable options available. I have included a.eslintrc
file to get your started(Just copy and paste this code your your .eslintrc file). The majority of this file is based on this
example and this
project. I added/modified the following:
Enable JSX linting via eslint-plugin-react
Enable ES6 syntax
Enable ES6 module import and export
Use single quote instead of double quote around strings (you can always change this by replacing
A note about eslint's syntax, eslint use 0, 1 and 2 to represent:
0 - disable the rule
1 - display warning when a rule is violated
2 - display error when a rule is violated
You can always look
up a eslint setting here.
Make sure SublimeLinter3 is
installed first.
Install SublimeLinter-eslint
Make sure you have a .eslintrc file in your current project's root folder. Open up the project folder in sublime and wait for a few seconds for eslinter to kick in.
If you also have sublime-jshint installed, you want to disable it otherwise both jshint and eslint will lint your project. To do this, inside ST3, save your project by (Project -> Save project as ...). This will create a .sublime-project file, inside this file,
put the following config inside:
This config tells SublimeLinter to:
disable jshint
tell eslint to ignore your
Whenever you modify the .eslintrc file, it will NOT take
effect unless your restart ST3.
Also, when ST3 is opened, it will not respond to any user input for a few seconds because eslint is working in the background linting your files.
来源:http://cheng.logdown.com/posts/2015/09/15/linting-react-jsx-and-es6-javascript-with-eslint
ST3 for React dev. Since then, I learned more about react development, I started to use eslint. Jslint is great but it does not support JSX. We need a linter that can be integrated with ST3 and show live linting result while coding. This is where eslint comes
in.
Install eslint
You can install it either globally or locally. I installed it globally:npm install -g eslint eslint-plugin-react
The only hiccup to start using eslint is its stunning numbers of configurable options available. I have included a.eslintrc
file to get your started(Just copy and paste this code your your .eslintrc file). The majority of this file is based on this
example and this
project. I added/modified the following:
Enable JSX linting via eslint-plugin-react
Enable ES6 syntax
Enable ES6 module import and export
Use single quote instead of double quote around strings (you can always change this by replacing
"quotes": [1, "single"]with
"quotes": [1, "double"]. Just search for the
quoteskeyword.
A note about eslint's syntax, eslint use 0, 1 and 2 to represent:
0 - disable the rule
1 - display warning when a rule is violated
2 - display error when a rule is violated
You can always look
up a eslint setting here.
Enable eslint in Sublime Text 3 (ST3)
Make sure SublimeLinter3 isinstalled first.
Install SublimeLinter-eslint
Make sure you have a .eslintrc file in your current project's root folder. Open up the project folder in sublime and wait for a few seconds for eslinter to kick in.
[Optional] Disable jshint in ST3
If you also have sublime-jshint installed, you want to disable it otherwise both jshint and eslint will lint your project. To do this, inside ST3, save your project by (Project -> Save project as ...). This will create a .sublime-project file, inside this file,put the following config inside:
{ "SublimeLinter":{ "linters":{ "eslint":{ "excludes":[ "dist/*", "node_modules/*" ] }, "jshint":{ "@disable":true } } } }
This config tells SublimeLinter to:
disable jshint
tell eslint to ignore your
distand
node_modulesfolder
Note
Whenever you modify the .eslintrc file, it will NOT takeeffect unless your restart ST3.
Also, when ST3 is opened, it will not respond to any user input for a few seconds because eslint is working in the background linting your files.
来源:http://cheng.logdown.com/posts/2015/09/15/linting-react-jsx-and-es6-javascript-with-eslint
相关文章推荐
- [React] Linting React JSX with ESLint (in ES6)
- [Javascript] Linting JavaScript with ESLint
- Trigger a button click with JavaScript on the Enter key in a text box
- [Javascript] Classify text into categories with machine learning in Natural
- [Javascript] Classify JSON text data with machine learning in Natural
- vue项目eslint环境配置与vscode配置eslint
- Working With Code Snippets In Sublime Text
- ESLint可共享配置发布,团队自定义ESLint规则新鲜出炉
- Trigger a button click with JavaScript on the Enter key in a text box
- ESLint系列:ESLint入门安装及简单配置
- [Javascript] Identify and Deal with NaN in JavaScript
- node.js在windows下的安装与配置(附sublime-text的配置)
- Shiro配置错误之“Error creating bean with name 'securityManager' defined in class path resource”
- time synchronization in html page with javascript
- JS. How to replace html element with another element/text, represented in string?
- quick-cocos2dx 那些事儿 (二):开发环境sublime text 3.0的配置过程
- First steps in text mining with R
- sublime text 安装配置
- [sublime-text2]review-in-browser
- Use Refresh() function right in WebGrid with javascript