diff --git a/packages/@vue/cli-plugin-eslint/__tests__/eslintPlugin.spec.js b/packages/@vue/cli-plugin-eslint/__tests__/eslintPlugin.spec.js index a4012f7162..627a07b3ce 100644 --- a/packages/@vue/cli-plugin-eslint/__tests__/eslintPlugin.spec.js +++ b/packages/@vue/cli-plugin-eslint/__tests__/eslintPlugin.spec.js @@ -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(';') +}) diff --git a/packages/@vue/cli-plugin-eslint/lint.js b/packages/@vue/cli-plugin-eslint/lint.js index a8a21b2b24..51183de74a 100644 --- a/packages/@vue/cli-plugin-eslint/lint.js +++ b/packages/@vue/cli-plugin-eslint/lint.js @@ -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 diff --git a/packages/@vue/cli-plugin-typescript/__tests__/tsPluginTSLint.spec.js b/packages/@vue/cli-plugin-typescript/__tests__/tsPluginTSLint.spec.js index a4b0d8b0c9..10c1245c75 100644 --- a/packages/@vue/cli-plugin-typescript/__tests__/tsPluginTSLint.spec.js +++ b/packages/@vue/cli-plugin-typescript/__tests__/tsPluginTSLint.spec.js @@ -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(//, $ => { + 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(//)[1]).not.toMatch(';') +}) diff --git a/packages/@vue/cli-plugin-typescript/lib/tslint.js b/packages/@vue/cli-plugin-typescript/lib/tslint.js index 5929f0ee4d..6a7a7009be 100644 --- a/packages/@vue/cli-plugin-typescript/lib/tslint.js +++ b/packages/@vue/cli-plugin-typescript/lib/tslint.js @@ -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']