0.0.16 • Published 2 years ago

eslint-plugin-pmd v0.0.16

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

eslint-plugin-pmd

eslint插件

1. Installation

You'll first need to install ESLint:

npm i eslint --save-dev

Next, install eslint-plugin-pmd:

npm install eslint-plugin-pmd --save-dev

2. Usage

Add pmd to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": [
        "pmd"
    ]
}

Then configure the rules you want to use under the rules section.

{
    "rules": {
        "pmd/rule-name": 2
    }
}

or use extends:

{
  extends: ['plugin:pmd/recommended'],
}

3. Supported Rules

3.1. pmd/valid-vue-comp-import

禁止从js文件中加载Vue组件

比如,

  1. 导入地址是js/ts文件
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,会被转换为:

import SomeComp from 'src/local-component/ui/pages/user/account-manage/xxx.vue';

注意上面的xxx.vue是从index.js中分析得到的原始文件路径。

  1. 导入一个目录,但目录存在index.js,这时候不管存不存在index.vue,uniapp转换都会失败
import SomeComp from 'src/local-component/ui/pages/user/account-manage';

可转换为:

import SomeComp from 'src/local-component/ui/pages/user/account-manage/xxx.vue';
  1. 具名导入
import {
  AComp,
  BComp,
  CComp,
  DComp,
} from './comp';

可转换为:

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';

3.2. pmd/no-plus-turn-number

禁止在vue的template中用+号转换字符串为数字

比如:

<ScheduleItem
  :child-id="+childId"
/>

如果加了--fix,会被转化成:

<ScheduleItem
  :child-id="parseInt(childId, 10)"
/>
0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago