Skip to content

Commit 385d80e

Browse files
author
test
committed
fix: fix support of the --no-fix option for linting with the typescript plugin (#1112)
1 parent bcd92b1 commit 385d80e

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

packages/@vue/cli-plugin-typescript/__tests__/tsPluginTSLint.spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,38 @@ test('should work', async () => {
3232
// test if tslint is fixing vue files properly
3333
expect(lintedApp).toBe(app)
3434
})
35+
36+
test('should not fix with --no-fix option', async () => {
37+
const project = await create('ts-lint-nofix', {
38+
plugins: {
39+
'@vue/cli-plugin-typescript': {
40+
tsLint: true
41+
}
42+
}
43+
})
44+
const { read, write, run } = project
45+
const main = await read('src/main.ts')
46+
expect(main).toMatch(';')
47+
const app = await read('src/App.vue')
48+
expect(main).toMatch(';')
49+
// remove semicolons
50+
const updatedMain = main.replace(/;/g, '')
51+
await write('src/main.ts', updatedMain)
52+
// for Vue file, only remove semis in script section
53+
const updatedApp = app.replace(/<script(.|\n)*\/script>/, $ => {
54+
return $.replace(/;/g, '')
55+
})
56+
await write('src/App.vue', updatedApp)
57+
58+
// lint with no fix should fail
59+
try {
60+
await run('vue-cli-service lint --no-fix')
61+
} catch (e) {
62+
expect(e.code).toBe(1)
63+
expect(e.failed).toBeTruthy()
64+
}
65+
66+
// files should not have been fixed
67+
expect(await read('src/main.ts')).not.toMatch(';')
68+
expect((await read('src/App.vue')).match(/<script(.|\n)*\/script>/)[1]).not.toMatch(';')
69+
})

packages/@vue/cli-plugin-typescript/lib/tslint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports = function lint (args = {}, api, silent) {
88
const vueCompiler = require('vue-template-compiler')
99

1010
const options = {
11-
fix: !args['no-fix'],
11+
fix: args['fix'] !== false,
1212
formatter: args.format || 'codeFrame',
1313
formattersDirectory: args['formatters-dir'],
1414
rulesDirectory: args['rules-dir']

0 commit comments

Comments
 (0)