mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-03-13 12:40:18 -05:00
fix(eslint): fix --no-fix flag when linting with typescript plugin (#1115)
This commit is contained in:
committed by
Evan You
parent
65ee2fad24
commit
83171e4029
@@ -1,4 +1,4 @@
|
||||
jest.setTimeout(30000)
|
||||
jest.setTimeout(35000)
|
||||
|
||||
const path = require('path')
|
||||
const { linkBin } = require('@vue/cli/lib/util/linkBin')
|
||||
@@ -90,3 +90,33 @@ test('should work', async () => {
|
||||
|
||||
await donePromise
|
||||
})
|
||||
|
||||
test('should not fix with --no-fix option', async () => {
|
||||
const project = await create('eslint-nofix', {
|
||||
plugins: {
|
||||
'@vue/cli-plugin-babel': {},
|
||||
'@vue/cli-plugin-eslint': {
|
||||
config: 'airbnb',
|
||||
lintOn: 'commit'
|
||||
}
|
||||
}
|
||||
})
|
||||
const { read, write, run } = project
|
||||
// should've applied airbnb autofix
|
||||
const main = await read('src/main.js')
|
||||
expect(main).toMatch(';')
|
||||
// remove semicolons
|
||||
const updatedMain = main.replace(/;/g, '')
|
||||
await write('src/main.js', updatedMain)
|
||||
|
||||
// lint with no fix should fail
|
||||
try {
|
||||
await run('vue-cli-service lint --no-fix')
|
||||
} catch (e) {
|
||||
expect(e.code).toBe(1)
|
||||
expect(e.failed).toBeTruthy()
|
||||
}
|
||||
|
||||
// files should not have been fixed
|
||||
expect(await read('src/main.js')).not.toMatch(';')
|
||||
})
|
||||
|
||||
@@ -7,10 +7,6 @@ module.exports = function lint (args = {}, api) {
|
||||
const { log, done } = require('@vue/cli-shared-utils')
|
||||
|
||||
const files = args._ && args._.length ? args._ : ['src', 'tests', '*.js']
|
||||
if (args['no-fix']) {
|
||||
args.fix = false
|
||||
delete args['no-fix']
|
||||
}
|
||||
const config = Object.assign({}, options, {
|
||||
fix: true,
|
||||
cwd
|
||||
|
||||
@@ -32,3 +32,38 @@ test('should work', async () => {
|
||||
// test if tslint is fixing vue files properly
|
||||
expect(lintedApp).toBe(app)
|
||||
})
|
||||
|
||||
test('should not fix with --no-fix option', async () => {
|
||||
const project = await create('ts-lint-nofix', {
|
||||
plugins: {
|
||||
'@vue/cli-plugin-typescript': {
|
||||
tsLint: true
|
||||
}
|
||||
}
|
||||
})
|
||||
const { read, write, run } = project
|
||||
const main = await read('src/main.ts')
|
||||
expect(main).toMatch(';')
|
||||
const app = await read('src/App.vue')
|
||||
expect(main).toMatch(';')
|
||||
// remove semicolons
|
||||
const updatedMain = main.replace(/;/g, '')
|
||||
await write('src/main.ts', updatedMain)
|
||||
// for Vue file, only remove semis in script section
|
||||
const updatedApp = app.replace(/<script(.|\n)*\/script>/, $ => {
|
||||
return $.replace(/;/g, '')
|
||||
})
|
||||
await write('src/App.vue', updatedApp)
|
||||
|
||||
// lint with no fix should fail
|
||||
try {
|
||||
await run('vue-cli-service lint --no-fix')
|
||||
} catch (e) {
|
||||
expect(e.code).toBe(1)
|
||||
expect(e.failed).toBeTruthy()
|
||||
}
|
||||
|
||||
// files should not have been fixed
|
||||
expect(await read('src/main.ts')).not.toMatch(';')
|
||||
expect((await read('src/App.vue')).match(/<script(.|\n)*\/script>/)[1]).not.toMatch(';')
|
||||
})
|
||||
|
||||
@@ -8,7 +8,7 @@ module.exports = function lint (args = {}, api, silent) {
|
||||
const vueCompiler = require('vue-template-compiler')
|
||||
|
||||
const options = {
|
||||
fix: !args['no-fix'],
|
||||
fix: args['fix'] !== false,
|
||||
formatter: args.format || 'codeFrame',
|
||||
formattersDirectory: args['formatters-dir'],
|
||||
rulesDirectory: args['rules-dir']
|
||||
|
||||
Reference in New Issue
Block a user