Skip to content

Commit

Permalink
Finish all vue rules
Browse files Browse the repository at this point in the history
  • Loading branch information
xcatliu committed May 27, 2019
1 parent fd9a18f commit f030ad1
Show file tree
Hide file tree
Showing 53 changed files with 776 additions and 20 deletions.
7 changes: 3 additions & 4 deletions index.js
Expand Up @@ -13,7 +13,7 @@
* eslint ^5.15.3
* eslint-plugin-react ^7.12.4
* eslint-plugin-vue ^5.2.2
* vue-eslint-parser ^6.0.3
* vue-eslint-parser ^5.0.0
* babel-eslint ^10.0.1
* @typescript-eslint/eslint-plugin ^1.9.0
*
Expand Down Expand Up @@ -869,7 +869,7 @@ module.exports = {
*/
'array-element-newline': 'off',
/**
* 代码块如果在一行内,那么大括号内的首尾必须有空格,比如 function () { alert('Hello') }
* 代码块如果在一行内,那么大括号内的首尾必须有空格
* @category Stylistic Issues
* @fixable
*/
Expand Down Expand Up @@ -897,7 +897,6 @@ module.exports = {
/**
* 对象的最后一个属性末尾必须有逗号
* @category Stylistic Issues
* @reason 没必要限制
* @fixable
*/
'comma-dangle': 'off',
Expand Down Expand Up @@ -1454,7 +1453,7 @@ module.exports = {
*/
'space-in-parens': ['error', 'never'],
/**
* 操作符左右必须有空格,比如 let sum = 1 + 2;
* 操作符左右必须有空格
* @category Stylistic Issues
* @fixable
*/
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Expand Up @@ -83,5 +83,10 @@
"ts-node": "^7.0.1",
"typescript": "^3.4.5",
"vue-eslint-parser": "^5.0.0"
},
"greenkeeper": {
"ignore": [
"ts-node"
]
}
}
2 changes: 1 addition & 1 deletion react.js
Expand Up @@ -13,7 +13,7 @@
* eslint ^5.15.3
* eslint-plugin-react ^7.12.4
* eslint-plugin-vue ^5.2.2
* vue-eslint-parser ^6.0.3
* vue-eslint-parser ^5.0.0
* babel-eslint ^10.0.1
* @typescript-eslint/eslint-plugin ^1.9.0
*
Expand Down
11 changes: 7 additions & 4 deletions scripts/build.ts
Expand Up @@ -90,7 +90,10 @@ class Builder {
this.buildEslintrcMeta() +
this.namespaceEslintrcContent
.replace(/extends:.*]/, "extends: ['./index.js']")
.replace(/(,\s*rules: {([\s\S]*?)})?\s*};/, `,rules:{$2,${this.rulesContent}}};`);
.replace(/(,\s*rules: {([\s\S]*?)})?\s*};/, (_match, _p1, p2) => {
const rules = p2 ? `${p2},${this.rulesContent}` : this.rulesContent;
return `,rules:{${rules}}};`;
});

this.writeWithPrettier(path.resolve(__dirname, `../${this.namespace}.js`), eslintrcContent);
}
Expand Down Expand Up @@ -224,7 +227,7 @@ class Builder {
}

const builder = new Builder();
// builder.build('index');
// builder.build('react');
// builder.build('vue');
builder.build('index');
builder.build('react');
builder.build('vue');
builder.build('typescript');
2 changes: 1 addition & 1 deletion test/index/block-spacing/.eslintrc.js
@@ -1,7 +1,7 @@
module.exports = {
rules: {
/**
* 代码块如果在一行内,那么大括号内的首尾必须有空格,比如 function () { alert('Hello') }
* 代码块如果在一行内,那么大括号内的首尾必须有空格
* @category Stylistic Issues
* @fixable
*/
Expand Down
1 change: 0 additions & 1 deletion test/index/comma-dangle/.eslintrc.js
Expand Up @@ -3,7 +3,6 @@ module.exports = {
/**
* 对象的最后一个属性末尾必须有逗号
* @category Stylistic Issues
* @reason 没必要限制
* @fixable
*/
'comma-dangle': 'off'
Expand Down
2 changes: 1 addition & 1 deletion test/index/space-infix-ops/.eslintrc.js
@@ -1,7 +1,7 @@
module.exports = {
rules: {
/**
* 操作符左右必须有空格,比如 let sum = 1 + 2;
* 操作符左右必须有空格
* @category Stylistic Issues
* @fixable
*/
Expand Down
10 changes: 10 additions & 0 deletions test/vue/array-bracket-spacing/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
rules: {
/**
* 数组的括号内的前后禁止有空格
* @category Uncategorized
* @fixable
*/
'vue/array-bracket-spacing': ['error', 'never']
}
};
16 changes: 16 additions & 0 deletions test/vue/arrow-spacing/.eslintrc.js
@@ -0,0 +1,16 @@
module.exports = {
rules: {
/**
* 箭头函数的箭头前后必须有空格
* @category Uncategorized
* @fixable
*/
'vue/arrow-spacing': [
'error',
{
before: true,
after: true
}
]
}
};
10 changes: 10 additions & 0 deletions test/vue/attributes-order/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
rules: {
/**
* 标签属性必须按规则排序
* @category Minimizing Arbitrary Choices and Cognitive Overhead
* @fixable
*/
'vue/attributes-order': 'error'
}
};
10 changes: 10 additions & 0 deletions test/vue/block-spacing/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
rules: {
/**
* 代码块如果在一行内,那么大括号内的首尾必须有空格
* @category Uncategorized
* @fixable
*/
'vue/block-spacing': ['error', 'always']
}
};
11 changes: 11 additions & 0 deletions test/vue/brace-style/.eslintrc.js
@@ -0,0 +1,11 @@
module.exports = {
rules: {
/**
* if 与 else 的大括号风格必须一致
* @category Uncategorized
* @reason else 代码块可能前面需要有一行注释
* @fixable
*/
'vue/brace-style': 'off'
}
};
10 changes: 10 additions & 0 deletions test/vue/camelcase/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
rules: {
/**
* 变量名必须是 camelcase 风格的
* @category Uncategorized
* @reason 很多 api 或文件名都不是 camelcase
*/
'vue/camelcase': 'off'
}
};
10 changes: 10 additions & 0 deletions test/vue/comma-dangle/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
rules: {
/**
* 约束自定义标签的命名规则
* @category Uncategorized
* @fixable
*/
'vue/component-name-in-template-casing': 'off'
}
};
9 changes: 9 additions & 0 deletions test/vue/comment-directive/.eslintrc.js
@@ -0,0 +1,9 @@
module.exports = {
rules: {
/**
* 支持在模版中使用 eslint-disable-next-line 等注释
* @category Enabling Correct ESLint Parsing
*/
'vue/comment-directive': 'error'
}
};
10 changes: 10 additions & 0 deletions test/vue/component-name-in-template-casing/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
rules: {
/**
* 对象的最后一个属性末尾必须有逗号
* @category Uncategorized
* @fixable
*/
'vue/comma-dangle': 'off'
}
};
10 changes: 10 additions & 0 deletions test/vue/dot-location/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
rules: {
/**
* 链式调用的时候,点号必须放在第二行开头处,禁止放在第一行结尾处
* @category Uncategorized
* @fixable
*/
'vue/dot-location': ['error', 'property']
}
};
16 changes: 16 additions & 0 deletions test/vue/eqeqeq/.eslintrc.js
@@ -0,0 +1,16 @@
module.exports = {
rules: {
/**
* 必须使用 === 或 !==,禁止使用 == 或 !=,与 null 比较时除外
* @category Uncategorized
* @fixable
*/
'vue/eqeqeq': [
'error',
'always',
{
null: 'ignore'
}
]
}
};
10 changes: 10 additions & 0 deletions test/vue/html-closing-bracket-newline/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
rules: {
/**
* 模版中开始标签的反尖括号必须换行
* @category Improving Readability
* @fixable
*/
'vue/html-closing-bracket-newline': 'error'
}
};
10 changes: 10 additions & 0 deletions test/vue/html-closing-bracket-spacing/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
rules: {
/**
* 模版中开始标签的反尖括号前禁止有空格,自闭和标签前必须有空格
* @category Improving Readability
* @fixable
*/
'vue/html-closing-bracket-spacing': 'error'
}
};
10 changes: 10 additions & 0 deletions test/vue/html-indent/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
rules: {
/**
* 模版中使用 4 个空格缩进
* @category Improving Readability
* @fixable
*/
'vue/html-indent': ['error', 4]
}
};
17 changes: 17 additions & 0 deletions test/vue/key-spacing/.eslintrc.js
@@ -0,0 +1,17 @@
module.exports = {
rules: {
/**
* 对象字面量中冒号前面禁止有空格,后面必须有空格
* @category Uncategorized
* @fixable
*/
'vue/key-spacing': [
'error',
{
beforeColon: false,
afterColon: true,
mode: 'strict'
}
]
}
};
16 changes: 16 additions & 0 deletions test/vue/keyword-spacing/.eslintrc.js
@@ -0,0 +1,16 @@
module.exports = {
rules: {
/**
* 关键字前后必须有空格
* @category Uncategorized
* @fixable
*/
'vue/keyword-spacing': [
'error',
{
before: true,
after: true
}
]
}
};
9 changes: 9 additions & 0 deletions test/vue/match-component-file-name/.eslintrc.js
@@ -0,0 +1,9 @@
module.exports = {
rules: {
/**
* 组件名称必须和文件名一致
* @category Uncategorized
*/
'vue/match-component-file-name': 'off'
}
};
10 changes: 10 additions & 0 deletions test/vue/multiline-html-element-content-newline/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
rules: {
/**
* 多行内容或多行标签时,内容前必须换行
* @category Improving Readability
* @fixable
*/
'vue/multiline-html-element-content-newline': 'error'
}
};
10 changes: 10 additions & 0 deletions test/vue/mustache-interpolation-spacing/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
rules: {
/**
* 模版内 mustache 大括号内前后禁止有空格
* @category Improving Readability
* @fixable
*/
'vue/mustache-interpolation-spacing': ['error', 'never']
}
};
10 changes: 10 additions & 0 deletions test/vue/no-boolean-default/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
rules: {
/**
* 禁止给布尔值 props 添加默认值
* @category Uncategorized
* @fixable
*/
'vue/no-boolean-default': 'off'
}
};
10 changes: 10 additions & 0 deletions test/vue/no-deprecated-scope-attribute/.eslintrc.js
@@ -0,0 +1,10 @@
module.exports = {
rules: {
/**
* 禁止用已废弃的 scope 属性
* @category Uncategorized
* @fixable
*/
'vue/no-deprecated-scope-attribute': 'error'
}
};
9 changes: 9 additions & 0 deletions test/vue/no-empty-pattern/.eslintrc.js
@@ -0,0 +1,9 @@
module.exports = {
rules: {
/**
* 禁止解构中出现空 {} 或 []
* @category Uncategorized
*/
'vue/no-empty-pattern': 'error'
}
};

0 comments on commit f030ad1

Please sign in to comment.