当前位置: 代码网 > it编程>开发工具>Eclipse > 浅谈atom中eslint的配置和使用方法

浅谈atom中eslint的配置和使用方法

2025年03月30日 Eclipse 我要评论
本篇文章给大家介绍一下eslint & atom 配合使用。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。【相关推荐:《atom》】下载aotm插件 linter-eslin

本篇文章给大家介绍一下eslint & atom 配合使用。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

浅谈atom中eslint的配置和使用方法

【相关推荐:《atom》】

下载aotm插件 linter-eslinthttps://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
    • $ npm i -g eslint [eslint-plugins]
    • activate use global eslint package option
    • (optional) set global node path with $ npm config get prefix

提供了一些插件,可自行下载(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!!

以上就是浅谈atom中eslint的配置和使用方法的详细内容,更多请关注代码网其它相关文章!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com