Skip to content

Commit

Permalink
fix: only enable TSLint when tslint.json exists
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Feb 12, 2018
1 parent 90fd33a commit 76d7f77
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ test('lint', async () => {
])

expect(pkg.scripts.lint).toBe(`vue-cli-service lint`)
expect(pkg.vue).toEqual({ lintOnSave: true })
expect(pkg.devDependencies).toHaveProperty('lint-staged')
expect(pkg.gitHooks).toEqual({ 'pre-commit': 'lint-staged' })
expect(pkg['lint-staged']).toEqual({
Expand All @@ -83,6 +82,20 @@ test('lint', async () => {
expect(files['tslint.json']).toBeTruthy()
})

test('lint with no lintOnSave', async () => {
const { pkg } = await generateWithPlugin([
{
id: 'ts',
apply: require('../generator'),
options: {
tsLint: true,
lintOn: ['commit']
}
}
])
expect(pkg.vue).toEqual({ lintOnSave: false })
})

test('compat with unit-mocha', async () => {
const { pkg } = await generateWithPlugin([
{
Expand Down
11 changes: 8 additions & 3 deletions packages/@vue/cli-plugin-typescript/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ module.exports = (api, {
api.extendPackage({
scripts: {
lint: 'vue-cli-service lint'
},
vue: {
lintOnSave: lintOn.includes('save')
}
})

if (!lintOn.includes('save')) {
api.extendPackage({
vue: {
lintOnSave: false
}
})
}

if (lintOn.includes('commit')) {
api.extendPackage({
devDependencies: {
Expand Down
3 changes: 2 additions & 1 deletion packages/@vue/cli-plugin-typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = (api, {
lintOnSave,
experimentalCompileTsWithBabel
}) => {
const fs = require('fs')
const useThreads = process.env.NODE_ENV === 'production' && parallel
const cacheDirectory = api.resolve('node_modules/.cache/cache-loader')

Expand Down Expand Up @@ -81,7 +82,7 @@ module.exports = (api, {
.plugin('fork-ts-checker')
.use(require('fork-ts-checker-webpack-plugin'), [{
vue: true,
tslint: lintOnSave !== false,
tslint: lintOnSave !== false && fs.existsSync(api.resolve('tslint.json')),
formatter: 'codeframe',
// https://github.com/TypeStrong/ts-loader#happypackmode-boolean-defaultfalse
checkSyntacticErrors: useThreads
Expand Down

0 comments on commit 76d7f77

Please sign in to comment.