Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eslint 配合 atom #14

Open
aototo opened this issue Nov 21, 2017 · 1 comment
Open

eslint 配合 atom #14

aototo opened this issue Nov 21, 2017 · 1 comment

Comments

@aototo
Copy link
Owner

aototo commented Nov 21, 2017

下载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
    • $ 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

http://eslint.cn/docs/user-guide/configuring 中文文档


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

/* 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: {
        // 这里填入你的项目需要的全局变量
        $: true,
    },
    
    // 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 }] //强制关键字周围空格的一致性

    }
};
@calpa
Copy link

calpa commented Dec 1, 2017

请注意 Atom 拼写

@aototo aototo changed the title eslint 配合 aotm eslint 配合 atom Mar 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants