Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c9daf2d

Browse files
Update rules update script
1 parent 9c2d146 commit c9daf2d

File tree

5 files changed

+105
-107
lines changed

5 files changed

+105
-107
lines changed

‎README.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ Write `.eslintrc.*` file to configure rules. See also: http://eslint.org/docs/us
3737
- ✒️ the mark of a fixable rule.
3838

3939
<!--RULES_TABLE_START-->
40-
### Possible Errors
4140

42-
| | Rule ID | Description |
43-
|:---|:--------|:------------|
44-
| ⭐️ | [no-invalid-template-root](./docs/rules/no-invalid-template-root.md) | disallow invalid template root. |
41+
### Possible Errors
42+
43+
| | Rule ID | Description |
44+
|:---|:--------|:------------|
45+
| ⭐️ | [no-invalid-template-root](./docs/rules/no-invalid-template-root.md) | disallow invalid template root. |
4546
| ⭐️ | [no-invalid-v-bind](./docs/rules/no-invalid-v-bind.md) | disallow invalid v-bind directives. |
4647
| ⭐️ | [no-invalid-v-cloak](./docs/rules/no-invalid-v-cloak.md) | disallow invalid v-cloak directives. |
4748
| ⭐️ | [no-invalid-v-else-if](./docs/rules/no-invalid-v-else-if.md) | disallow invalid v-else-if directives. |
@@ -57,23 +58,26 @@ Write `.eslintrc.*` file to configure rules. See also: http://eslint.org/docs/us
5758
| ⭐️ | [no-invalid-v-text](./docs/rules/no-invalid-v-text.md) | disallow invalid v-text directives. |
5859
| ⭐️ | [no-parsing-error](./docs/rules/no-parsing-error.md) | disallow parsing errors in `<template>`. |
5960

60-
### Best Practices
6161

62-
| | Rule ID | Description |
63-
|:---|:--------|:------------|
64-
| ⭐️✒️ | [html-end-tags](./docs/rules/html-end-tags.md) | enforce end tag style. |
62+
### Best Practices
63+
64+
| | Rule ID | Description |
65+
|:---|:--------|:------------|
66+
| ⭐️✒️ | [html-end-tags](./docs/rules/html-end-tags.md) | enforce end tag style. |
6567
| ⭐️✒️ | [html-no-self-closing](./docs/rules/html-no-self-closing.md) | disallow self-closing elements. |
68+
| ⭐️ | [jsx-uses-vars](./docs/rules/jsx-uses-vars.md) | Prevent variables used in JSX to be marked as unused |
6669
| ⭐️ | [no-confusing-v-for-v-if](./docs/rules/no-confusing-v-for-v-if.md) | disallow confusing `v-for` and `v-if` on the same element. |
6770
| ⭐️ | [no-duplicate-attributes](./docs/rules/no-duplicate-attributes.md) | disallow duplicate arguments. |
6871
| ⭐️ | [no-textarea-mustache](./docs/rules/no-textarea-mustache.md) | disallow mustaches in `<textarea>`. |
6972
| ⭐️ | [require-component-is](./docs/rules/require-component-is.md) | require `v-bind:is` of `<component>` elements. |
7073
| ⭐️ | [require-v-for-key](./docs/rules/require-v-for-key.md) | require `v-bind:key` with `v-for` directives. |
7174

72-
### Stylistic Issues
7375

74-
| | Rule ID | Description |
75-
|:---|:--------|:------------|
76-
| | [html-quotes](./docs/rules/html-quotes.md) | enforce quotes style of HTML attributes. |
76+
### Stylistic Issues
77+
78+
| | Rule ID | Description |
79+
|:---|:--------|:------------|
80+
| | [html-quotes](./docs/rules/html-quotes.md) | enforce quotes style of HTML attributes. |
7781
| ✒️ | [v-bind-style](./docs/rules/v-bind-style.md) | enforce v-bind directive style. |
7882
| ✒️ | [v-on-style](./docs/rules/v-on-style.md) | enforce v-on directive style. |
7983

‎config/recommended.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,4 @@
11
module.exports = {
22
extends: require.resolve('./base.js'),
3-
4-
rules: {
5-
'vue/html-end-tags': 'error',
6-
'vue/html-no-self-closing': 'error',
7-
'vue/html-quotes': 'off',
8-
'vue/no-confusing-v-for-v-if': 'error',
9-
'vue/no-duplicate-attributes': 'error',
10-
'vue/no-invalid-template-root': 'error',
11-
'vue/no-invalid-v-bind': 'error',
12-
'vue/no-invalid-v-cloak': 'error',
13-
'vue/no-invalid-v-else-if': 'error',
14-
'vue/no-invalid-v-else': 'error',
15-
'vue/no-invalid-v-for': 'error',
16-
'vue/no-invalid-v-html': 'error',
17-
'vue/no-invalid-v-if': 'error',
18-
'vue/no-invalid-v-model': 'error',
19-
'vue/no-invalid-v-on': 'error',
20-
'vue/no-invalid-v-once': 'error',
21-
'vue/no-invalid-v-pre': 'error',
22-
'vue/no-invalid-v-show': 'error',
23-
'vue/no-invalid-v-text': 'error',
24-
'vue/no-parsing-error': 'error',
25-
'vue/no-textarea-mustache': 2,
26-
'vue/require-component-is': 'error',
27-
'vue/require-v-for-key': 'error',
28-
'vue/v-bind-style': 'off',
29-
'vue/v-on-style': 'off'
30-
},
3+
rules: require.resolve('./recommended-rules.js'),
314
};

‎lib/recommended-rules.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* IMPORTANT!
3+
* This file has been automatically generated,
4+
* in order to update it's content execute "npm run update"
5+
*/
6+
module.exports = {
7+
"html-end-tags": "error",
8+
"html-no-self-closing": "error",
9+
"html-quotes": "off",
10+
"jsx-uses-vars": "error",
11+
"no-confusing-v-for-v-if": "error",
12+
"no-duplicate-attributes": "error",
13+
"no-invalid-template-root": "error",
14+
"no-invalid-v-bind": "error",
15+
"no-invalid-v-cloak": "error",
16+
"no-invalid-v-else-if": "error",
17+
"no-invalid-v-else": "error",
18+
"no-invalid-v-for": "error",
19+
"no-invalid-v-html": "error",
20+
"no-invalid-v-if": "error",
21+
"no-invalid-v-model": "error",
22+
"no-invalid-v-on": "error",
23+
"no-invalid-v-once": "error",
24+
"no-invalid-v-pre": "error",
25+
"no-invalid-v-show": "error",
26+
"no-invalid-v-text": "error",
27+
"no-parsing-error": "error",
28+
"no-textarea-mustache": "error",
29+
"require-component-is": "error",
30+
"require-v-for-key": "error",
31+
"v-bind-style": "off",
32+
"v-on-style": "off"
33+
}

‎package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
"description": "Official ESLint plugin for Vue.js",
55
"main": "lib/index.js",
66
"scripts": {
7-
"start": "npm run test:simple -- --watch --growl",
7+
"start": "npm run update && npm run test:simple -- --watch --growl",
88
"test:base": "mocha tests --recursive",
99
"test:simple": "npm run test:base -- --reporter nyan",
1010
"test": "nyc npm run test:base",
1111
"lint": "eslint .",
1212
"pretest": "npm run lint",
1313
"preversion": "npm test",
14-
"postversion": "git push --follow-tags"
14+
"postversion": "git push --follow-tags",
15+
"update": "node ./tools/update-rules.js"
1516
},
1617
"files": [
1718
"lib"

‎tools/update-rules.js

Lines changed: 52 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -16,81 +16,68 @@ const path = require("path")
1616
// Main
1717
//------------------------------------------------------------------------------
1818

19-
const ROOT = path.resolve(__dirname, "../lib/rules")
20-
const README = path.resolve(__dirname, "../README.md")
21-
const RULES_JS = path.resolve(__dirname, "../lib/rules.js")
22-
const RECOMMENDED_JSON = path.resolve(__dirname, "../lib/recommended.json")
19+
const root = path.resolve(__dirname, "../lib/rules")
20+
const readmeFile = path.resolve(__dirname, "../README.md")
21+
const recommendedRulesFile = path.resolve(__dirname, "../lib/recommended-rules.js")
22+
const categories = ["Possible Errors", "Best Practices", "Stylistic Issues"]
23+
const tablePlaceholder = /<!--RULES_TABLE_START-->[\s\S]*<!--RULES_TABLE_END-->/
24+
const readmeContent = fs.readFileSync(readmeFile, "utf8")
25+
2326
const STAR = "⭐️"
2427
const PEN = "✒️"
25-
const CATEGORIES = ["Possible Errors", "Best Practices", "Stylistic Issues"]
26-
const TABLE_PLACE_HOLDER = /<!--RULES_TABLE_START-->[\s\S]*<!--RULES_TABLE_END-->/
27-
28-
const ruleNames = fs.readdirSync(ROOT)
29-
.filter(file => path.extname(file) === ".js")
30-
.map(file => path.basename(file, ".js"))
3128

32-
const rules = new Map(
33-
ruleNames.map(name => [
34-
name,
35-
require(path.join(ROOT, name)),
36-
])
37-
)
29+
const rules = fs.readdirSync(root)
30+
.filter(file => path.extname(file) === ".js")
31+
.map(file => path.basename(file, ".js"))
32+
.map(fileName => [
33+
fileName,
34+
require(path.join(root, fileName)),
35+
])
3836

39-
const RULE_TABLE = CATEGORIES.map(category => `### ${category}
37+
const rulesTableContent = categories.map(category => `
38+
### ${category}
4039
41-
| | Rule ID | Description |
42-
|:---|:--------|:------------|
43-
${
44-
Array.from(rules.entries())
45-
.filter(entry => entry[1].meta.docs.category === category)
46-
.map(entry => {
47-
const name = entry[0]
48-
const meta = entry[1].meta
49-
const mark = `${meta.docs.recommended ? STAR : ""}${meta.fixable ? PEN : ""}`
50-
const link = `[${name}](./docs/rules/${name}.md)`
51-
const description = meta.docs.description || "(no description)"
52-
return `| ${mark} | ${link} | ${description} |`
53-
})
54-
.join("\n")
55-
}
40+
| | Rule ID | Description |
41+
|:---|:--------|:------------|
42+
${
43+
rules
44+
.filter(entry => entry[1].meta.docs.category === category)
45+
.map(entry => {
46+
const name = entry[0]
47+
const meta = entry[1].meta
48+
const mark = `${meta.docs.recommended ? STAR : ""}${meta.fixable ? PEN : ""}`
49+
const link = `[${name}](./docs/rules/${name}.md)`
50+
const description = meta.docs.description || "(no description)"
51+
return `| ${mark} | ${link} | ${description} |`
52+
})
53+
.join("\n")
54+
}
5655
`).join("\n")
5756

58-
const RULES_JS_CONTENT = `/**
59-
* @author Toru Nagashima
60-
* @copyright 2017 Toru Nagashima. All rights reserved.
61-
* See LICENSE file in root directory for full license.
62-
*/
63-
"use strict"
64-
65-
module.exports = {
66-
${ruleNames.map(name => ` "${name}": require("./rules/${name}"),`).join("\n")}
67-
}
68-
`
57+
const recommendedRules = rules.reduce((obj, entry) => {
58+
const name = entry[0]
59+
const recommended = entry[1].meta.docs.recommended
60+
const status = recommended ? 'error' : 'off'
61+
obj[name] = status;
62+
return obj;
63+
}, {});
6964

70-
const recommendedConf = {
71-
parser: "vue-eslint-parser",
72-
env: {es6: true},
73-
rules: Array.from(rules.entries())
74-
.reduce((obj, entry) => {
75-
const name = entry[0]
76-
const recommended = entry[1].meta.docs.recommended
77-
obj[`vue/${name}`] = recommended ? "error" : "off"
78-
return obj
79-
}, {}),
80-
}
65+
const recommendedRulesContent = `/*
66+
* IMPORTANT!
67+
* This file has been automatically generated,
68+
* in order to update it's content execute "npm run update"
69+
*/
70+
module.exports = ${JSON.stringify(recommendedRules, null, 2)}`
8171

8272
fs.writeFileSync(
83-
README,
84-
fs.readFileSync(README, "utf8").replace(
85-
TABLE_PLACE_HOLDER,
86-
`<!--RULES_TABLE_START-->\n${RULE_TABLE}\n<!--RULES_TABLE_END-->`
87-
)
88-
)
89-
fs.writeFileSync(
90-
RULES_JS,
91-
RULES_JS_CONTENT
73+
readmeFile,
74+
readmeContent.replace(
75+
tablePlaceholder,
76+
`<!--RULES_TABLE_START-->\n${rulesTableContent}\n<!--RULES_TABLE_END-->`
77+
)
9278
)
79+
9380
fs.writeFileSync(
94-
RECOMMENDED_JSON,
95-
JSON.stringify(recommendedConf,null,4)
81+
recommendedRulesFile,
82+
recommendedRulesContent
9683
)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /