This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add rule no-this-in-async-data
- Loading branch information
Showing
4 changed files
with
155 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* @fileoverview Prevent using this in asyncData | ||
* @author Clark Du | ||
*/ | ||
'use strict' | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Requirements | ||
// ------------------------------------------------------------------------------ | ||
|
||
var rule = require('../no-this-in-async-data') | ||
|
||
var RuleTester = require('eslint').RuleTester | ||
|
||
const parserOptions = { | ||
ecmaVersion: 2018, | ||
sourceType: 'module' | ||
} | ||
|
||
// ------------------------------------------------------------------------------ | ||
// Tests | ||
// ------------------------------------------------------------------------------ | ||
|
||
var ruleTester = new RuleTester() | ||
ruleTester.run('no-this-in-async-data', rule, { | ||
|
||
valid: [ | ||
{ | ||
filename: 'test.vue', | ||
code: ` | ||
export default { | ||
...foo, | ||
asyncData() { | ||
} | ||
} | ||
`, | ||
parserOptions | ||
} | ||
], | ||
|
||
invalid: [ | ||
{ | ||
filename: 'test.vue', | ||
code: ` | ||
export default { | ||
...foo, | ||
asyncData() { | ||
if(this.$route.path === 'foo') {} | ||
} | ||
} | ||
`, | ||
errors: [{ | ||
message: 'Unexpected this in asyncData.', | ||
type: 'Identifier' | ||
}], | ||
parserOptions | ||
}, | ||
{ | ||
filename: 'test.vue', | ||
code: ` | ||
export default { | ||
...foo, | ||
async asyncData() { | ||
if(this.$route.path === 'foo') {} | ||
} | ||
} | ||
`, | ||
errors: [{ | ||
message: 'Unexpected this in asyncData.', | ||
type: 'Identifier' | ||
}], | ||
parserOptions | ||
}, | ||
{ | ||
filename: 'test.vue', | ||
code: ` | ||
export default { | ||
...foo, | ||
asyncData: () => { | ||
if(this.$route.path === 'foo') {} | ||
} | ||
} | ||
`, | ||
errors: [{ | ||
message: 'Unexpected this in asyncData.', | ||
type: 'Identifier' | ||
}], | ||
parserOptions | ||
}, | ||
{ | ||
filename: 'test.vue', | ||
code: ` | ||
export default { | ||
...foo, | ||
asyncData: function test() { | ||
if(this.$route.path === 'foo') {} | ||
} | ||
} | ||
`, | ||
errors: [{ | ||
message: 'Unexpected this in asyncData.', | ||
type: 'Identifier' | ||
}], | ||
parserOptions | ||
} | ||
] | ||
}) |
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 @@ | ||
module.exports = require('eslint-plugin-vue/lib/utils') |