search
HomeDevelopment ToolssublimeSublimeText3 configures react syntax verification

SublimeText3 is a cross-platform code editor software. SublimeText3 can both write code and edit text. It is an essential tool for programmers. The following column sublime usage tutorial will introduce you to the SublimeText3 configuration of react syntax verification. I hope it will be helpful to friends in need!

SublimeText3 configures react syntax verification

1. Install nodejs

2. Open the terminal and install the eslint verification package and react verification plug-in package :

npm install -g eslint
npm install -g eslint-plugin-react

3. Install the plug-in in Sublime:

SublimeLinter
SublimeLinter-contrib-eslint

4. Run eslint --init

Configure the initialization file according to the prompts and generate the .json format

5. Configure .eslintrc

.eslintrc.json

{
        "plugins": [
                // "react",
                "html"
        ],
        "env": {
                "node": true,
                "jquery": true,
                "es6": true,
                "browser": true
        },
        "globals": {
                "angular": false
        },
        "parser": "babel-eslint",
        "rules": {
                //官方文档 http://eslint.org/docs/rules/
                //参数:0 关闭,1 警告,2 错误
                // "quotes": [0, "single"],                  //建议使用单引号
                // "no-inner-declarations": [0, "both"],     //不建议在{}代码块内部声明变量或函数
                "no-extra-boolean-cast": 1, //多余的感叹号转布尔型
                "no-extra-semi": 1, //多余的分号
                "no-extra-parens": 0, //多余的括号
                "no-empty": 1, //空代码块
 
                //使用前未定义
                "no-use-before-define": [
                        0,
                        "nofunc"
                ],
 
                "complexity": [0, 10], //圈复杂度大于*
 
                //定义数组或对象最后多余的逗号
                "comma-dangle": [
                        0,
                        "never"
                ],
 
                // 不允许对全局变量赋值,如 window = 'abc'
                "no-global-assign": ["error", {
                        // 定义例外
                        // "exceptions": ["Object"]
                }],
                "no-var": 0, //用let或const替代var
                "no-const-assign": 2, //不允许const重新赋值
                "no-class-assign": 2, //不允许对class重新赋值
                "no-debugger": 1, //debugger 调试代码未删除
                "no-console": 0, //console 未删除
                "no-constant-condition": 2, //常量作为条件
                "no-dupe-args": 2, //参数重复
                "no-dupe-keys": 2, //对象属性重复
                "no-duplicate-case": 2, //case重复
                "no-empty-character-class": 2, //正则无法匹配任何值
                "no-invalid-regexp": 2, //无效的正则
                "no-func-assign": 2, //函数被赋值
                "valid-typeof": 1, //无效的类型判断
                "no-unreachable": 2, //不可能执行到的代码
                "no-unexpected-multiline": 2, //行尾缺少分号可能导致一些意外情况
                "no-sparse-arrays": 1, //数组中多出逗号
                "no-shadow-restricted-names": 2, //关键词与命名冲突
                "no-undef": 1, //变量未定义
                "no-unused-vars": 1, //变量定义后未使用
                "no-cond-assign": 2, //条件语句中禁止赋值操作
                "no-native-reassign": 2, //禁止覆盖原生对象
                "no-mixed-spaces-and-tabs": 0,
 
 
 
                //代码风格优化 --------------------------------------
                "no-irregular-whitespace": 0,
                "no-else-return": 0, //在else代码块中return,else是多余的
                "no-multi-spaces": 0, //不允许多个空格
 
                //object直接量建议写法 : 后一个空格前面不留空格
                "key-spacing": [
                        0,
                        {
                                "beforeColon": false,
                                "afterColon": true
                        }
                ],
 
                "block-scoped-var": 1, //变量应在外部上下文中声明,不应在{}代码块中
                "consistent-return": 1, //函数返回值可能是不同类型
                "accessor-pairs": 1, //object getter/setter方法需要成对出现
 
                //换行调用对象方法  点操作符应写在行首
                "dot-location": [
                        1,
                        "property"
                ],
                "no-lone-blocks": 1, //多余的{}嵌套
                "no-labels": 1, //无用的标记
                "no-extend-native": 1, //禁止扩展原生对象
                "no-floating-decimal": 1, //浮点型需要写全 禁止.1 或 2.写法
                "no-loop-func": 1, //禁止在循环体中定义函数
                "no-new-func": 1, //禁止new Function(...) 写法
                "no-self-compare": 1, //不允与自己比较作为条件
                "no-sequences": 1, //禁止可能导致结果不明确的逗号操作符
                "no-throw-literal": 1, //禁止抛出一个直接量 应是Error对象
 
                //不允return时有赋值操作
                "no-return-assign": [
                        1,
                        "always"
                ],
 
                //不允许重复声明
                "no-redeclare": [
                        1,
                        {
                                "builtinGlobals": true
                        }
                ],
 
                //不执行的表达式
                "no-unused-expressions": [
                        0,
                        {
                                "allowShortCircuit": true,
                                "allowTernary": true
                        }
                ],
                "no-useless-call": 1, //无意义的函数call或apply
                "no-useless-concat": 1, //无意义的string concat
                "no-void": 1, //禁用void
                "no-with": 1, //禁用with
                "space-infix-ops": 0, //操作符前后空格
 
                //jsdoc
                "valid-jsdoc": [
                        0,
                        {
                                "requireParamDescription": true,
                                "requireReturnDescription": true
                        }
                ],
 
                //标记未写注释
                "no-warning-comments": [
                        1,
                        {
                                "terms": [
                                        "todo",
                                        "fixme",
                                        "any other term"
                                ],
                                "location": "anywhere"
                        }
                ],
                "curly": 0 //if、else、while、for代码块用{}包围
        }
}

The above is the detailed content of SublimeText3 configures react syntax verification. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:segmentfault. If there is any infringement, please contact admin@php.cn delete
How to run the code in sublime?How to run the code in sublime?Mar 06, 2025 am 11:36 AM

This article explains how to execute code in Sublime Text using external tools and build systems. It details creating language-specific build systems (e.g., Python, C , JavaScript) via JSON files, and running code via Ctrl B. While Sublime Text

Is sublime free?Is sublime free?Mar 06, 2025 am 11:29 AM

Sublime Text is a freemium code editor offering full functionality for free, albeit with occasional license prompts. The article discusses its licensing model, feature limitations (primarily the prompts), and paid-version benefits (primarily removin

How to compile and run java code in sublimeHow to compile and run java code in sublimeMar 06, 2025 am 11:35 AM

This article guides Java developers on configuring Sublime Text for compiling and running Java code. It details setting up a custom build system (JavaC.sublime-build) to handle compilation and execution, emphasizing JDK installation and PATH environ

How to run sublime code C languageHow to run sublime code C languageMar 06, 2025 am 11:33 AM

This article explains how to run C code in Sublime Text. It emphasizes that Sublime Text needs an external compiler (like GCC) and a build system (a .sublime-build file) to compile and execute C code. The process involves installing a compiler, defi

Sublime Set encoding formatSublime Set encoding formatMar 06, 2025 am 11:25 AM

This article explains Sublime Text's per-file encoding handling, lacking a global default. It emphasizes UTF-8 as the best practice for consistency and broad compatibility, advising users to explicitly save files with the chosen encoding and levera

What is sublime for? What is sublime software?What is sublime for? What is sublime software?Mar 06, 2025 am 11:30 AM

Sublime Text is a fast, customizable cross-platform text editor popular with developers. Its key features include multiple selections, Goto Anything, a command palette, and extensive plugin support. While free to use, a license removes nag screens a

Sublime test installation tutorialSublime test installation tutorialMar 06, 2025 am 11:37 AM

This tutorial guides Sublime Text installation on Windows, package management (using Package Control or manual methods), and interface customization (themes, keybindings, settings, plugins). It addresses the common issue of setting up and personali

sublime column modesublime column modeMar 06, 2025 am 11:24 AM

This article explains Sublime Text's powerful built-in column selection feature. It details activation methods (Alt/Option key mouse drag), selection manipulation using the mouse and keyboard shortcuts, and clarifies that dedicated plugins aren't

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools