# @mlamp/eslint-config-mlt
基于 eslint-config-alloy 完成， 内置 base/react/typescript 配置，加上 mlt 自定义 配置，将 prettier 样式规则委托 prettier 进行管理。包中内置`.prettierrc.js`，在包的根目录中，仅供参考。
# 包安装 

npm 安装
```bash
npm install eslint-config-mlt --save-dev
```
yarn 安装
```bash
yarn add eslint-config-mlt --save-dev -W
```

# 项目中使用
在你的项目的根目录下创建一个 `.eslintrc.js` 文件，并将以下内容复制进去：

```js
module.exports = {
  extends: ['eslint-config-mlt']
};
```
# [配置项](http://hulu.voc.mlamp.cn/kaleidoscope/eslint-config-mlt)

参考项目 [eslint-config-alloy](https://github.com/AlloyTeam/eslint-config-alloy)

## 常见问题

### 在 VSCode 中使用

在 VSCode 中，默认 ESLint 并不能识别 `.ts` 或 `.tsx` 文件，需要在「文件 => 首选项 => 设置」里做如下配置：

```json
{
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact"
  ]
}
```

### 保存时自动修复 ESLint 错误

如果想要开启「保存时自动修复」的功能，你可以配置 `.vscode/settings.json`：

```json
{
  "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
}
```

### VSCode 中的 autoFixOnSave 没有效果

如果需要针对 `.ts` 和 `.tsx` 文件开启 ESLint 的 autoFix，则需要配置成：

```json
{
  "eslint.autoFixOnSave": true,
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    {
      "language": "typescript",
      "autoFix": true
    },
    {
      "language": "typescriptreact",
      "autoFix": true
    }
  ]
}
```

### 如何结合 Prettier 使用

eslint-config-alloy 从 v3 开始，已经不包含所有样式相关的规则了，故不需要引入 `eslint-config-prettier`。只需要安装 VSCode 插件`prettier` ，并在`.prettierrc.js`配置属性即可。
下面给出一个 `.prettierrc.js`配置，仅供参考：
```js
module.exports = {
    // 一行最多 100 字符
    printWidth: 100,
    // 使用 4 个空格缩进
    tabWidth: 4,
    // 不使用缩进符，而使用空格
    useTabs: false,
    // 行尾需要有分号
    semi: true,
    // 使用单引号
    singleQuote: true,
    // jsx 不使用单引号，而使用双引号
    jsxSingleQuote: false,
    // 末尾不需要逗号
    trailingComma: 'none',
    // 大括号内的首尾需要空格
    bracketSpacing: true,
    // jsx 标签的反尖括号需要换行
    jsxBracketSameLine: true,
    // 箭头函数，只有一个参数的时候，也需要括号
    arrowParens: 'always',
    // 每个文件格式化的范围是文件的全部内容
    rangeStart: 0,
    rangeEnd: Infinity,
    // 不需要写文件开头的 @prettier
    requirePragma: false,
    // 不需要自动在文件开头插入 @prettier
    insertPragma: false,
    // 使用默认的折行标准
    proseWrap: 'preserve',
    // 根据显示样式决定 html 要不要折行 ignore
    htmlWhitespaceSensitivity: 'strict',
    // 换行符使用 lf
    endOfLine: 'lf',

    // parser: 'typescript',

    overrides: [
        {
            files: ['*.json'],
            options: {
                parser: 'json',
                tabWidth: 4
            }
        },
        {
            files: '*.{css,sass,scss,less}',
            options: {
                parser: 'css',
                tabWidth: 4
            }
        },
        {
            files: '*.{ts,tsx}',
            options: {
                parser: 'typescript'
            }
        }
    ]
};
```




