Skip to content

Commit

Permalink
feat: include and exclude rules
Browse files Browse the repository at this point in the history
  • Loading branch information
chibing.fy committed Mar 2, 2022
1 parent e12fcf9 commit feec505
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
20 changes: 20 additions & 0 deletions packages/gogocode-plugin-element/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ gogocode -s ./src -t gogocode-plugin-element -o ./src-out

另外,由于是静态的代码转换,可能你的代码里会有些我们没想到的写法导致转换出乱子,转换后请做好人工比对和测试!发现转换的问题可以[提交](https://github.com/thx/gogocode/issues)给我们。

## 指定应用规则

添加参数 `-p include-rules=xxx,yyy`,举例只应用 `calendar``popover` 规则:

```bash
gogocode -s ./src -t gogocode-plugin-element -o ./src-out -p include-rules=calendar,popover
```

规则名称请参看 [rules.js](./src/rules.js) 里面的 `name` 字段。

## 排除应用规则


添加参数 `-p exclude-rules=xxx,yyy`,举例只排除 `calendar``popover` 规则:

```bash
gogocode -s ./src -t gogocode-plugin-element -o ./src-out -p exclude-rules=calendar,popover
```

规则名称请参看 [rules.js](./src/rules.js) 里面的 `name` 字段。
# 联系我们
如果你在使用过程中遇到其他问题可以通过如下方式联系我们:

Expand Down
13 changes: 6 additions & 7 deletions packages/gogocode-plugin-element/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ const transform = function (fileInfo, api, options) {
? $(sourceCode, { parseOptions: { language: 'vue' } })
: $(sourceCode);

const rulesToBeApplied = options.rule ? rules.filter(rule => rule.name === options.rule) : rules

const includeRules = options['include-rules'] ? options['include-rules'].split(',') : rules.map(r => r.name);
const excludeRules = options['exclude-rules'] ? options['exclude-rules'].split(',') : [];

const rulesToBeApplied = rules.filter(r => includeRules.includes(r.name) && !excludeRules.includes(r.name));

if(!rulesToBeApplied.length) {
throw Error(`rule:${options.rule} not found`);
}

if(options.rule) {
console.log(`applying rule: ${options.rule}`);
throw Error(`No valid rule found.`);
}

const outAst = rulesToBeApplied.reduce((ast, ruleCfg) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/gogocode-plugin-element/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gogocode-plugin-element",
"version": "0.0.2",
"version": "0.0.3",
"description": "",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit feec505

Please sign in to comment.