ts/js语法检测集成
npm install @autobest-ui/eslint-plugin --save-dev
- 创建
.eslintrc.js
文件 - 引入依赖
module.exports = {
root: true,
extends: ['plugin:@autobest-ui/recommended']
};
写法为extends: ['plugin:@autobest-ui/recommended']
,该方式是前端要求的正式ts/js写法。要求比较严格,主要应用在复杂、频繁维护项目中。
写法为extends: ['plugin:@autobest-ui/compromised']
,该方式主要应用在DEMO性质、快速开发的项目中。
{
"extends": "@autobest-ui/eslint-plugin/tsconfig-common.json"
}
新增@autobest-ui/line-element-whitespace
, 处理三种情况
- 文本后有行元素或其他行元素, 例如:
-
text<span>xxxx</span>
=>text <span>xxxx</span>
-
text{'xxxx'}
=>text {'xxxx'}
-
- 行元素后有文本或其他行元素, 例如:
-
<span>xxxx</span>text
=><span>xxxx</span> text
-
<span>xxxx</span><span>xxxx</span>
=><span>xxxx</span> <span>xxxx</span>
或<span>xxxx</span>{' '}<span>xxxx</span>
-
<span>xxxx</span>{'xxxx'}
=><span>xxxx</span> {'xxxx'}
-
- 模版字符串后有文本或其他行元素, 例如:
-
{'xxxx'}<span>xxxx</span>
=>{'xxxx'} <span>xxxx</span>
-
{'xxxx'}xxxx
=>{'xxxx'} xxxx
-
{'xxxx'}{'xxxx'}
=>{'xxxx'} {'xxxx'}
-
注意: 有些情况下,我们是不能加空格的,比如英文文字后的句号('.'),感叹号, 逗号, 双引号等特殊情况.下面列举了如下所有情况
// 常用的行元素有下列情况, 其他inline标签(如:sup)用法比较特殊,暂不检测
const InlineTagNames = ['span', 'strong', 'b', 'a', 'i', 'del', 'small', 'em', 'label', 'var'];
// 特殊文本字符, 这种情况下文本与标签之间可以不用空格
// 特殊文字在末尾的情况
const SpecialTextLastCharRegList = [
/"$/,
/'$/,
/<$/,
/>$/,
/\$$/,
/\($/,
/\)$/,
/\[$/,
/]$/,
/\{$/,
/}$/,
/® $/,
/:$/
];
// 特殊文字在头部的情况
const SpecialTextFirstCharRegList = [
/^"/,
/^'/,
/^</,
/^>/,
/^,/,
/^\./,
/^\$/,
/^!/,
/^;/,
/^\(/,
/^\)/,
/^\[/,
/^]/,
/^\{/,
/^}/,
/^® /,
/^:/
];
新增@autobest-ui/full-width-punctuation
, 处理代码中使用了中文字符的问题
自动将“”‘’,。;:!?
替换成""'',.;:!?
注:对于元素文本内容的“”‘’
会替换成"
和'
- 打开
Setting => Eslint
- 选择Automatic Eslint configuration radio即可