@agds/eslint-config-js

1.0.8 • Public • Published

logo

@agds/eslint-config-js

版本 :1.0.8

agds的js eslint配置,支持js、json、markdown的js代码

快速开始

安装

npm i -D @agds/eslint-config-js

引入

// .eslintrc.js
module.exports = {
    extends: [
        '@agds/js',
    ],
};

添加lint脚本

package.jsonscripts下添加lint命令;

{
  "scripts": {
    "lint": "eslint --ext .js,.json,.md src",
    "lint:fix": "eslint --ext .js,.json,.md src --fix"
  }
}

基于lint-staged提供增量lint脚本

  • 安装lint-staged
    npm i -D lint-staged
    
  • package.json中添加pkg['lint-staged']脚本
    {
      "lint-staged": {
        "src/**/*.{js,json,md}": [
          "eslint --fix"
        ]
      }
    }

使用yorkie在git声明周期内检测代码格式

  • 安装yorkie
    npm i -D yorkie
    
  • package.json中添加pkg.gitHooks脚本
    {
      "gitHooks": {
        "pre-commit": "lint-staged"
      }
    }

配置源码

const { FastPath, FastFs } = require('@agds/node-utils');
const cwdBabelConfigPath = FastPath.getCwdPath('./babel.config.js');
const hasCwdBabelConfg = FastFs.getPathStatSync(cwdBabelConfigPath);
module.exports = {
    env: {
        commonjs: true,
        es2021: true,
        node: true,
    },
    extends: [
        'standard',
        'plugin:markdown/recommended',
    ],
    plugins: [
        'json-format',
    ],
    settings: {
        'json/sort-package-json': false,
        'json/json-with-comments-files': [],
        'json/ignore-files': [],
    },
    parser: hasCwdBabelConfg ? '@babel/eslint-parser' : undefined,
    parserOptions: {
        ecmaVersion: 12,
        babelOptions: {
            configFile: hasCwdBabelConfg ? cwdBabelConfigPath : undefined,
        },
    },
    rules: {
        indent: ['error', 4, { SwitchCase: 1 }],
        semi: ['error', 'always'],
        'comma-dangle': ['error', 'always-multiline'],
        'space-before-function-paren': [
            'error',
            { anonymous: 'always', named: 'never', asyncArrow: 'always' },
        ],
    },
    overrides: [
        {
            files: ['**/*.md/*.{js,json}', 'docs/**', 'test/**'],
            rules: {
                'no-console': 'off',
                'import/no-unresolved': 'off',
                'no-undef': 'off',
                'no-unused-expressions': 'off',
                'no-unused-vars': 'off',
                'padded-blocks': 'off',
                'eol-last': 'off',
            },
        },
    ],
};

许可证

MIT License Copyright (c) 2021 锦阳

请维护者喝杯咖啡

加入钉钉群讨论或加入开发

Readme

Keywords

Package Sidebar

Install

npm i @agds/eslint-config-js

Weekly Downloads

2

Version

1.0.8

License

MIT

Unpacked Size

8.2 kB

Total Files

4

Last publish

Collaborators

  • chujunyang