mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-03-13 12:40:18 -05:00
This commit is contained in:
committed by
Haoqun Jiang
parent
fccb1143e5
commit
364f28f6d7
@@ -88,3 +88,28 @@ test('should ignore issues in node_modules', async () => {
|
||||
await run('vue-cli-service lint')
|
||||
expect(await read('node_modules/bad.ts')).toMatch(updatedMain)
|
||||
})
|
||||
|
||||
test('should be able to fix mixed line endings', async () => {
|
||||
const project = await create('ts-lint-mixed-line-endings', {
|
||||
plugins: {
|
||||
'@vue/cli-plugin-typescript': {
|
||||
tsLint: true
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const { write, run } = project
|
||||
|
||||
const b64 = 'PHRlbXBsYXRlPjwvdGVtcGxhdGU+DQoNCjxzY3JpcHQgbGFuZz0idHMiPg0KZXhwb3J0IGRlZmF1bHQgY2xhc3MgVGVzdCAgew0KICBnZXQgYXNzaWduZWUoKSB7DQogICAgdmFyIGl0ZW1zOnt0ZXh0OnN0cmluZzsgdmFsdWU6c3RyaW5nIHwgbnVtYmVyIHwgbnVsbH1bXSA9IFtdOw0KICAgIHJldHVybiBpdGVtczsNCiAgfQ0KDQp9DQo8L3NjcmlwdD4NCg0K'
|
||||
const buf = Buffer.from(b64, 'base64')
|
||||
|
||||
await write('src/bad.vue', buf)
|
||||
|
||||
// Try twice to fix the file.
|
||||
// For now, it will fail the first time, which corresponds to the behaviour of tslint.
|
||||
try {
|
||||
await run('vue-cli-service lint -- src/bad.vue')
|
||||
} catch (e) { }
|
||||
|
||||
await run('vue-cli-service lint -- src/bad.vue')
|
||||
})
|
||||
|
||||
@@ -29,6 +29,7 @@ module.exports = function lint (args = {}, api, silent) {
|
||||
if (isVueFile(file)) {
|
||||
const parts = vueFileCache.get(path.normalize(file))
|
||||
if (parts) {
|
||||
parts.content = content;
|
||||
const { before, after } = parts
|
||||
content = `${before}\n${content.trim()}\n${after}`
|
||||
}
|
||||
@@ -42,12 +43,19 @@ module.exports = function lint (args = {}, api, silent) {
|
||||
}
|
||||
|
||||
const parseTSFromVueFile = file => {
|
||||
|
||||
// If the file has already been cached, don't read the file again. Use the cache instead.
|
||||
if (vueFileCache.has(file)) {
|
||||
return vueFileCache.get(file).content;
|
||||
}
|
||||
|
||||
const content = fs.readFileSync(file, 'utf-8')
|
||||
const { script } = vueCompiler.parseComponent(content, { pad: 'line' })
|
||||
if (script && /^tsx?$/.test(script.lang)) {
|
||||
vueFileCache.set(file, {
|
||||
before: content.slice(0, script.start),
|
||||
after: content.slice(script.end)
|
||||
after: content.slice(script.end),
|
||||
content: script.content,
|
||||
})
|
||||
return script
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user