eslint插件
npm install eslint-plugin-pmdeslint插件
You'll first need to install ESLint:
``sh`
npm i eslint --save-dev
Next, install eslint-plugin-pmd:
`sh`
npm install eslint-plugin-pmd --save-dev
Add pmd to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:
`json`
{
"plugins": [
"pmd"
]
}
Then configure the rules you want to use under the rules section.
`json`
{
"rules": {
"pmd/rule-name": 2
}
}
or use extends:
`json`
{
extends: ['plugin:pmd/recommended'],
}
禁止从js文件中加载Vue组件
比如,
1. 导入地址是js/ts文件
`js
import SomeComp from 'src/local-component/ui/pages/user/account-manage/index.js';
// 或者省略了js/ts文件后缀
import SomeComp from 'src/local-component/ui/pages/user/account-manage/index';
`
如果加了--fix,会被转换为:
`js`
import SomeComp from 'src/local-component/ui/pages/user/account-manage/xxx.vue';
注意上面的xxx.vue是从index.js中分析得到的原始文件路径。
2. 导入一个目录,但目录存在index.js,这时候不管存不存在index.vue,uniapp转换都会失败
`js`
import SomeComp from 'src/local-component/ui/pages/user/account-manage';
可转换为:
`js`
import SomeComp from 'src/local-component/ui/pages/user/account-manage/xxx.vue';
3. 具名导入
`js`
import {
AComp,
BComp,
CComp,
DComp,
} from './comp';
可转换为:
`js`
import AComp from 'src/local-component/module/tip-match/tip-match-schedule-tree-new/comp/a.vue';
import BComp from 'src/local-component/module/tip-match/tip-match-schedule-tree-new/comp/b.vue';
import CComp from 'src/local-component/module/tip-match/tip-match-schedule-tree-new/comp/c.vue';
import DComp from 'src/local-component/module/tip-match/tip-match-schedule-tree-new/comp/d.vue';
禁止在vue的template中用+号转换字符串为数字
比如:
`html`
/>
如果加了--fix,会被转化成:
`html``
/>