Skip to content

Commit 22defb2

Browse files
committed
Update: support eslint-disable in template
1 parent 92b76fc commit 22defb2

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

src/app-state.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export default class PlaygroundState {
158158
// Fix
159159
try {
160160
// At first, fix because `linter.verifyAndFix` does not accept SourceCode object.
161-
const ret = linter.verifyAndFix(this.code, config, "vue-eslint-demo.vue")
161+
const ret = linter.verifyAndFix(this.code, config)
162162
this.fixedCode = ret.output
163163
this.fixedMessages = ret.messages
164164
}
@@ -179,8 +179,7 @@ export default class PlaygroundState {
179179
// Cannot reuse until https://github.com/eslint/eslint/pull/8755 is merged.
180180
// linter.getSourceCode(), // Reuse the AST of the previous `linter.verifyAndFix`.
181181
this.code,
182-
config,
183-
"vue-eslint-demo.vue"
182+
config
184183
)
185184
}
186185
catch (err) {

src/app-state/eslint.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
11
import Linter from "eslint/lib/linter.js"
2-
import vueRules from "eslint-plugin-vue"
2+
import plugin from "eslint-plugin-vue"
33
import * as parser from "vue-eslint-parser"
44

55
// Initialize the linter
6-
const linter = new Linter()
7-
linter.defineParser("vue-eslint-parser", parser)
8-
linter.defineRules(vueRules)
6+
const verifyOptions = {
7+
filename: "vue-eslint-demo.vue",
8+
preprocess: plugin.processors[".vue"].preprocess,
9+
postprocess: plugin.processors[".vue"].postprocess,
10+
}
11+
const linter = new class extends Linter {
12+
/** Initialize this linter. */
13+
constructor() {
14+
super()
15+
this.defineParser("vue-eslint-parser", parser)
16+
for (const name of Object.keys(plugin.rules)) {
17+
this.defineRule(`vue/${name}`, plugin.rules[name])
18+
}
19+
}
20+
21+
/** @inheritdoc */
22+
verify(textOrSourceCode, config) {
23+
return super.verify(textOrSourceCode, config, verifyOptions)
24+
}
25+
26+
/** @inheritdoc */
27+
verifyAndFix(text, config) {
28+
return super.verifyAndFix(text, config, verifyOptions)
29+
}
30+
}()
931

1032
// Initialize the categories of rules.
1133
/** @type {{name:string,rules:{name:string,description:string,fixable:boolean}[]}[]} */

webpack.config.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@ ${
1717
.join("\n")
1818
}
1919
})
20-
`
20+
`
2121

2222
// Shim for `eslint-plugin-vue/lib/index.js`
2323
const ESLINT_PLUGIN_VUE_INDEX = `module.exports = {
24-
${
24+
rules: {${
2525
fs.readdirSync("node_modules/eslint-plugin-vue/lib/rules")
2626
.filter(filename => path.extname(filename) === ".js")
2727
.map(filename => {
2828
const ruleId = path.basename(filename, ".js")
29-
return ` "vue/${ruleId}": require("eslint-plugin-vue/lib/rules/${filename}"),`
29+
return ` "${ruleId}": require("eslint-plugin-vue/lib/rules/${filename}"),`
3030
})
3131
.join("\n")
3232
}
33+
},
34+
processors: {
35+
".vue": require("eslint-plugin-vue/lib/processor")
36+
}
3337
}`
3438

3539
// Shim for `src/versions.js`

0 commit comments

Comments
 (0)