@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.json
的scripts
下添加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 锦阳