温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

atom中eslint的配置以及使用方法

发布时间:2021-06-17 11:36:14 来源:亿速云 阅读:245 作者:chen 栏目:软件技术

本篇内容主要讲解“atom中eslint的配置以及使用方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“atom中eslint的配置以及使用方法”吧!

下载aotm插件 linter-eslint

https://github.com/AtomLinter/linter-eslint

需要设置如下:

  • Install locally to your project eslint and the plugin

    • $ npm i --save-dev eslint [eslint-plugins]

  • Install globally eslint and plugins

    • Activate Use Global Eslint package option

    • (Optional) Set Global Node Path with $ npm config get prefix

    • $ npm i -g eslint [eslint-plugins]

提供了一些插件,可自行下载(ps: 版本差异会导致部分插件报错)

  • eslint-config-airbnb

  • eslint-plugin-import

  • eslint-plugin-jsx-a11y

  • eslint-plugin-react

  • eslint-plugin-html (可解析html中的脚本, 最新的版本v4跟早期eslint有冲突)

然后在项目下
$ eslint --init


使用以下注释,关闭提示。

/* eslint-disable */

使用eslintignore 忽略特定的文件和目录

创建一个 .eslintignore 文件,添加需要过滤的文件夹,或者文件

 build/*
 app/lib/*

命令行使用 --ignore-path

$ eslint --ignore-path .eslintignore --fix app/*

路径是相对于 .eslintignore 的位置或当前工作目录

更多查看 http://eslint.cn/docs/user-guide/configuring

基础配置:

module.exports = {
    parser: 'babel-eslint',

    "env": {
        "browser": true,
        "commonjs": true,
        "es6": true
    },

    // 以当前目录为根目录,不再向上查找 .eslintrc.js
    root: true,

    // 禁止使用 空格 和 tab 混合缩进
    "extends": "eslint:recommended",

    globals: {
        // 这里填入你的项目需要的全局变量
        // jQuery: false,
        $: false,
        wx: false,
    },
    
    // eslint-plugin-html 开启
    "plugins": [
        "html"
    ],

    "parserOptions": {
        "ecmaFeatures": {
            "jsx": false
        },
        "sourceType": "module"
    },

    "rules": {
        "indent": ["error", 'tab'],

        "linebreak-style": ["error","unix"],

        "quotes": ["error","single"],

        "semi": ["error","always"],

        "semi": ["error","always"],

        "arrow-spacing": ["error", { "before": true, "after": true }],

        "no-unused-vars": "off", //禁止提示没有使用的变量,或者函数

        "block-spacing": "error",

        "no-console": "off", //可以使用console

        "keyword-spacing": ["error", { "before": true }] //强制关键字周围空格的一致性

    }
};

到此,相信大家对“atom中eslint的配置以及使用方法”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI