forked from vuejs/vue-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support using ESLint to lint TypeScript
- Loading branch information
Showing
20 changed files
with
255 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
module.exports = { | ||
extensions: ['.js', '.vue'], | ||
parserOptions: { | ||
parser: require.resolve('babel-eslint') | ||
}, | ||
globals: ['process'], | ||
rules: { | ||
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', | ||
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off' | ||
module.exports = api => { | ||
const options = { | ||
extensions: ['.js', '.vue'], | ||
globals: ['process'], | ||
rules: { | ||
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', | ||
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off' | ||
} | ||
} | ||
|
||
if (api.hasPlugin('typescript')) { | ||
options.extensions.push('.ts') | ||
} else { | ||
options.parserOptions = { | ||
parser: require.resolve('babel-eslint') | ||
} | ||
} | ||
|
||
return options | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/@vue/cli-plugin-typescript/__tests__/tsPluginESLint.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
jest.setTimeout(10000) | ||
|
||
const create = require('@vue/cli-test-utils/createTestProject') | ||
|
||
test('should work', async () => { | ||
const project = await create('ts-lint', { | ||
plugins: { | ||
'@vue/cli-plugin-eslint': { | ||
config: 'prettier' | ||
}, | ||
'@vue/cli-plugin-typescript': { | ||
classComponent: 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 | ||
await run('vue-cli-service lint') | ||
expect(await read('src/main.ts')).toMatch(';') | ||
|
||
const lintedApp = await read('src/App.vue') | ||
expect(lintedApp).toMatch(';') | ||
// test if ESLint is fixing vue files properly | ||
expect(lintedApp).toBe(app) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/@vue/cli-plugin-typescript/generator/template/tslint.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<%_ if (options.lint) { _%> | ||
<%_ if (options.tsLint) { _%> | ||
{ | ||
"defaultSeverity": "warning", | ||
"extends": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__tests__/ | ||
__mocks__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @vue/eslint-config-typescript | ||
|
||
> eslint-config-typescript for vue-cli |
Oops, something went wrong.