Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support --no fix when linting with typescript plugin #1115

Merged
merged 3 commits into from
Apr 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion packages/@vue/cli-plugin-eslint/__tests__/eslintPlugin.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jest.setTimeout(30000)
jest.setTimeout(35000)

const path = require('path')
const { linkBin } = require('@vue/cli/lib/util/linkBin')
Expand Down Expand Up @@ -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(';')
})
4 changes: 0 additions & 4 deletions packages/@vue/cli-plugin-eslint/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(';')
})
2 changes: 1 addition & 1 deletion packages/@vue/cli-plugin-typescript/lib/tslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down