Skip to content

Commit 76d7f77

Browse files
committed
fix: only enable TSLint when tslint.json exists
1 parent 90fd33a commit 76d7f77

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

Diff for: packages/@vue/cli-plugin-typescript/__tests__/tsGenerator.spec.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ test('lint', async () => {
7272
])
7373

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

85+
test('lint with no lintOnSave', async () => {
86+
const { pkg } = await generateWithPlugin([
87+
{
88+
id: 'ts',
89+
apply: require('../generator'),
90+
options: {
91+
tsLint: true,
92+
lintOn: ['commit']
93+
}
94+
}
95+
])
96+
expect(pkg.vue).toEqual({ lintOnSave: false })
97+
})
98+
8699
test('compat with unit-mocha', async () => {
87100
const { pkg } = await generateWithPlugin([
88101
{

Diff for: packages/@vue/cli-plugin-typescript/generator/index.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,17 @@ module.exports = (api, {
5050
api.extendPackage({
5151
scripts: {
5252
lint: 'vue-cli-service lint'
53-
},
54-
vue: {
55-
lintOnSave: lintOn.includes('save')
5653
}
5754
})
5855

56+
if (!lintOn.includes('save')) {
57+
api.extendPackage({
58+
vue: {
59+
lintOnSave: false
60+
}
61+
})
62+
}
63+
5964
if (lintOn.includes('commit')) {
6065
api.extendPackage({
6166
devDependencies: {

Diff for: packages/@vue/cli-plugin-typescript/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = (api, {
33
lintOnSave,
44
experimentalCompileTsWithBabel
55
}) => {
6+
const fs = require('fs')
67
const useThreads = process.env.NODE_ENV === 'production' && parallel
78
const cacheDirectory = api.resolve('node_modules/.cache/cache-loader')
89

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

0 commit comments

Comments
 (0)