This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+127
View File
@@ -0,0 +1,127 @@
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [1.0.0](https://github.com/nuxt/eslint-plugin-nuxt/compare/v0.5.2...v1.0.0) (2020-05-12)
### Features
* upgrade eslint to v7 ([c57a3de](https://github.com/nuxt/eslint-plugin-nuxt/commit/c57a3de0aaa71d33b09a1710d6b5c7ce478f71e3))
### Bug Fixes
* nuxt/require-func-head doesnt work with factories ([5480fd0](https://github.com/nuxt/eslint-plugin-nuxt/commit/5480fd0d8eda0d6a5794548d60d3d84db8cbf86e)), closes [#94](https://github.com/nuxt/eslint-plugin-nuxt/issues/94)
* remove require-func-head from recommend ([580ffa2](https://github.com/nuxt/eslint-plugin-nuxt/commit/580ffa26fa533c6e2cef2330965609ca879b118d)), closes [#93](https://github.com/nuxt/eslint-plugin-nuxt/issues/93)
### [0.5.2](https://github.com/nuxt/eslint-plugin-nuxt/compare/v0.5.1...v0.5.2) (2020-03-20)
### Bug Fixes
* enable no-this-in-fetch only for nuxt < 2.12 ([66fc2e0](https://github.com/nuxt/eslint-plugin-nuxt/commit/66fc2e0f517865b3bf160eb096a5c81f788b33af))
### [0.5.1](https://github.com/nuxt/eslint-plugin-nuxt/compare/v0.5.0...v0.5.1) (2020-02-09)
### Features
* **rule:** add require-func-head in recommended ([#62](https://github.com/nuxt/eslint-plugin-nuxt/issues/62)) ([7d0926f](https://github.com/nuxt/eslint-plugin-nuxt/commit/7d0926f4a73bbd3c91496f7ab8e0fc232f38d423))
### Bug Fixes
* correct category for no-timing-in-fetch-data ([bbf6ce9](https://github.com/nuxt/eslint-plugin-nuxt/commit/bbf6ce985b0e40c1c9450fd3b3a7188d3a7a214a))
## [0.5.0](https://github.com/nuxt/eslint-plugin-nuxt/compare/v0.4.3...v0.5.0) (2019-11-09)
### Features
* upgrade eslint-plugin-vue to v6 ([ecf42f2](https://github.com/nuxt/eslint-plugin-nuxt/commit/ecf42f2))
## [0.4.3](https://github.com/nuxt/eslint-plugin-nuxt/compare/v0.4.0...v0.4.3) (2019-03-12)
### Bug Fixes
* incompatible version of vue-eslint-parser ([9bb12ae](https://github.com/nuxt/eslint-plugin-nuxt/commit/9bb12ae))
## [0.4.2](https://github.com/nuxt/eslint-plugin-nuxt/compare/v0.4.0...v0.4.2) (2019-02-21)
### Bug Fixes
* use filename instead of full path ([4c62a37](https://github.com/nuxt/eslint-plugin-nuxt/commit/4c62a37))
<a name="0.3.0"></a>
# [0.3.0](https://github.com/nuxt/eslint-plugin-nuxt/compare/v0.2.0...v0.3.0) (2018-12-19)
### Bug Fixes
* not-null check for hooks ([daa93f3](https://github.com/nuxt/eslint-plugin-nuxt/commit/daa93f3))
### Features
* add no-env-in-hooks ([bdcc9ec](https://github.com/nuxt/eslint-plugin-nuxt/commit/bdcc9ec))
<a name="0.2.0"></a>
# [0.2.0](https://github.com/nuxt/eslint-plugin-nuxt/compare/v0.1.3...v0.2.0) (2018-12-10)
### Features
* add no-env-in-mounted ([0037b34](https://github.com/nuxt/eslint-plugin-nuxt/commit/0037b34))
* move ssr to base ([8f408dd](https://github.com/nuxt/eslint-plugin-nuxt/commit/8f408dd))
<a name="0.1.3"></a>
## [0.1.3](https://github.com/nuxt/eslint-plugin-nuxt/compare/v0.1.2...v0.1.3) (2018-12-10)
<a name="0.1.2"></a>
## [0.1.2](https://github.com/nuxt/eslint-plugin-nuxt/compare/v0.1.1...v0.1.2) (2018-12-10)
### Bug Fixes
* rule not found ([c63f657](https://github.com/nuxt/eslint-plugin-nuxt/commit/c63f657))
* undefined value in nuxt/no-env-in-context ([17cb2d9](https://github.com/nuxt/eslint-plugin-nuxt/commit/17cb2d9))
<a name="0.1.1"></a>
## [0.1.1](https://github.com/nuxt/eslint-plugin-nuxt/compare/v0.1.0...v0.1.1) (2018-12-10)
### Bug Fixes
* wrong index file ([c50e96f](https://github.com/nuxt/eslint-plugin-nuxt/commit/c50e96f))
<a name="0.1.0"></a>
# 0.1.0 (2018-12-10)
### Features
* add base config ([bf0759a](https://github.com/nuxt/eslint-plugin-nuxt/commit/bf0759a))
* **rule:** add no-globals-in-created ([d8736e9](https://github.com/nuxt/eslint-plugin-nuxt/commit/d8736e9))
* add no-env-in-context ([71b09e9](https://github.com/nuxt/eslint-plugin-nuxt/commit/71b09e9))
* add no-this-in-fetch ([fe4d381](https://github.com/nuxt/eslint-plugin-nuxt/commit/fe4d381))
* add no-timing-in-fetch-data ([2945b70](https://github.com/nuxt/eslint-plugin-nuxt/commit/2945b70))
* add rule no-this-in-async-data ([9a56aae](https://github.com/nuxt/eslint-plugin-nuxt/commit/9a56aae))
* init no-this-in-async-data ([e23f4ed](https://github.com/nuxt/eslint-plugin-nuxt/commit/e23f4ed))
* init no-this-in-fetch ([4bf0385](https://github.com/nuxt/eslint-plugin-nuxt/commit/4bf0385))
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Xin (Clark) Du <clark.duxin@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+111
View File
@@ -0,0 +1,111 @@
# eslint-plugin-nuxt
[![Standard JS][standard-js-src]][standard-js-href]
[![Circle CI][circle-ci-src]][circle-ci-href]
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[standard-js-src]: https://flat.badgen.net/badge/code%20style/standard/green
[standard-js-href]: https://standardjs.com
[circle-ci-src]: https://flat.badgen.net/circleci/github/nuxt/eslint-plugin-nuxt
[circle-ci-href]: https://circleci.com/gh/nuxt/eslint-plugin-nuxt
[codecov-src]: https://flat.badgen.net/codecov/c/github/nuxt/eslint-plugin-nuxt
[codecov-href]: https://codecov.io/gh/nuxt/eslint-plugin-nuxt
[npm-version-src]: https://flat.badgen.net/npm/v/eslint-plugin-nuxt/latest
[npm-version-href]: https://npmjs.com/package/eslint-plugin-nuxt
[npm-downloads-src]: https://flat.badgen.net/npm/dt/eslint-plugin-nuxt
[npm-downloads-href]: https://npmjs.com/package/eslint-plugin-nuxt
:sparkles: ESLint plugin for Nuxt.js
## :cd: Installation
You'll first need to install [ESLint](http://eslint.org):
```sh
$ npm i eslint --save-dev
success Saved 1 new dependencies
```
Next, install `eslint-plugin-nuxt`:
```sh
$ npm install eslint-plugin-nuxt --save-dev
success Saved 1 new dependencies
```
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-nuxt` globally.
## :rocket: Usage
Add `nuxt` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
1. Use our preset to extend recommended defaults:
```json
{
"extends": [
"plugin:nuxt/recommended"
]
}
```
2. Or specify individual rules manually:
```json
{
"plugins": [
"nuxt"
],
"rules": {
"nuxt/rule-name": 2
}
}
```
## :gear: Configs
This plugin provides four predefined configs:
- `plugin:nuxt/base` - Settings and rules to enable correct ESLint parsing
- `plugin:nuxt/recommended` - Above, plus rules to enforce subjective community defaults to ensure consistency
## :bulb: Rules
<!--RULES_TABLE_START-->
### Base Rules
```json
{
"extends": "plugin:nuxt/base"
}
```
| | Rule ID | Description |
|:---|:--------|:------------|
| | [nuxt/no-env-in-context](./docs/rules/no-env-in-context.md) | Disallow `context.isServer/context.isClient` in `asyncData/fetch/nuxtServerInit` |
| | [nuxt/no-env-in-hooks](./docs/rules/no-env-in-hooks.md) | Disallow `process.server/process.client` in client only Vue lifecycle hooks like: `mounted, beforeMount, updated...` |
| | [nuxt/no-globals-in-created](./docs/rules/no-globals-in-created.md) | Disallow `window/document` in `created/beforeCreate` |
| | [nuxt/no-this-in-fetch-data](./docs/rules/no-this-in-fetch-data.md) | Disallow `this` in `asyncData/fetch` |
| | [nuxt/no-cjs-in-config](./docs/rules/no-cjs-in-config.md) | Disallow `require/modules.exports/exports` in `nuxt.config.js` |
### Recommended Rules
Include all the below rules, as well as all priority rules in above categories, with:
```json
{
"extends": "plugin:nuxt/recommended"
}
```
| | Rule ID | Description |
|:---|:--------|:------------|
| | [nuxt/no-timing-in-fetch-data](./docs/rules/no-timing-in-fetch-data.md) | Disallow `setTimeout/setInterval` in `asyncData/fetch` |
### Other Rules
| | Rule ID | Description |
|:---|:--------|:------------|
| | [nuxt/require-func-head](./docs/rules/require-func-head.md) | Enforce `head` property in component to be a function. |
+24
View File
@@ -0,0 +1,24 @@
module.exports = {
parser: require.resolve('vue-eslint-parser'),
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
jsx: true
}
},
env: {
browser: true,
es6: true
},
plugins: [
'nuxt'
],
rules: {
'nuxt/no-env-in-context': 'error',
'nuxt/no-env-in-hooks': 'error',
'nuxt/no-globals-in-created': 'error',
'nuxt/no-this-in-fetch-data': 'error',
'nuxt/no-cjs-in-config': 'error'
}
}
+6
View File
@@ -0,0 +1,6 @@
module.exports = {
extends: require.resolve('./base.js'),
rules: {
'nuxt/no-timing-in-fetch-data': 'error'
}
}
+18
View File
@@ -0,0 +1,18 @@
module.exports = {
rules: {
'no-env-in-context': require('./rules/no-env-in-context'),
'no-env-in-hooks': require('./rules/no-env-in-hooks'),
'no-globals-in-created': require('./rules/no-globals-in-created'),
'no-this-in-fetch-data': require('./rules/no-this-in-fetch-data'),
'no-timing-in-fetch-data': require('./rules/no-timing-in-fetch-data'),
'no-cjs-in-config': require('./rules/no-cjs-in-config'),
'require-func-head': require('./rules/require-func-head')
},
configs: {
base: require('./configs/base'),
recommended: require('./configs/recommended')
},
processors: {
'.vue': require('./processors')
}
}
View File
+1
View File
@@ -0,0 +1 @@
module.exports = require('eslint-plugin-vue/lib/processor')
View File
+103
View File
@@ -0,0 +1,103 @@
/**
* @fileoverview Disallow `require/modules.exports/exports` in `nuxt.config.js`
* @author Xin Du <clark.duxin@gmail.com>
*/
'use strict'
const path = require('path')
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description:
'disallow commonjs module api `require/modules.exports/exports` in `nuxt.config.js`',
category: 'base'
},
messages: {
noCjs: 'Unexpected {{cjs}}, please use {{esm}} instead.'
}
},
create (context) {
// variables should be defined here
const options = context.options[0] || {}
const configFile = options.file || 'nuxt.config.js'
let isNuxtConfig = false
// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------
return {
Program (node) {
const filename = path.basename(context.getFilename())
if (filename === configFile) {
isNuxtConfig = true
}
},
MemberExpression: function (node) {
if (!isNuxtConfig) {
return
}
// module.exports
if (node.object.name === 'module' && node.property.name === 'exports') {
context.report({
node,
messageId: 'noCjs',
data: {
cjs: 'module.exports',
esm: 'export default'
}
})
}
// exports.
if (node.object.name === 'exports') {
const isInScope = context.getScope()
.variables
.some(variable => variable.name === 'exports')
if (!isInScope) {
context.report({
node,
messageId: 'noCjs',
data: {
cjs: 'exports',
esm: 'export default'
}
})
}
}
},
CallExpression: function (call) {
const module = call.arguments[0]
if (
!isNuxtConfig ||
context.getScope().type !== 'module' ||
!['ExpressionStatement', 'VariableDeclarator'].includes(call.parent.type) ||
call.callee.type !== 'Identifier' ||
call.callee.name !== 'require' ||
call.arguments.length !== 1 ||
module.type !== 'Literal' ||
typeof module.value !== 'string'
) {
return
}
context.report({
node: call.callee,
messageId: 'noCjs',
data: {
cjs: 'require',
esm: 'import'
}
})
}
}
}
}
+83
View File
@@ -0,0 +1,83 @@
/**
* @fileoverview disallow `context.isServer/context.isClient` in `asyncData/fetch/nuxtServerInit`
* @author Xin Du <clark.duxin@gmail.com>
*/
'use strict'
const utils = require('../utils')
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description:
'disallow `context.isServer/context.isClient` in `asyncData/fetch/nuxtServerInit`',
category: 'base'
},
messages: {
noEnv: 'Unexpected {{env}} in {{funcName}}.'
}
},
create (context) {
// variables should be defined here
const forbiddenNodes = []
const options = context.options[0] || {}
const ENV = ['isServer', 'isClient']
const HOOKS = new Set(['asyncData', 'fetch'].concat(options.methods || []))
// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------
return {
MemberExpression (node) {
const propertyName = node.computed ? node.property.value : node.property.name
if (propertyName && ENV.includes(propertyName)) {
forbiddenNodes.push({ name: propertyName, node })
}
},
...utils.executeOnVue(context, obj => {
for (const funcName of HOOKS) {
const func = utils.getFunctionWithName(obj, funcName)
const param = func && func.value ? func.value.params && func.value.params[0] : false
if (param) {
if (param.type === 'ObjectPattern') {
for (const prop of param.properties) {
if (prop.key && prop.key.name && ENV.includes(prop.key.name)) {
context.report({
node: prop,
messageId: 'noEnv',
data: {
env: prop.key.name,
funcName
}
})
}
}
} else {
for (const { name, node: child } of forbiddenNodes) {
if (utils.isInFunction(func, child)) {
if (param.name === child.object.name) {
context.report({
node: child,
messageId: 'noEnv',
data: {
env: name,
funcName
}
})
}
}
}
}
}
}
})
}
}
}
+68
View File
@@ -0,0 +1,68 @@
/**
* @fileoverview disallow process.server and process.client in the following lifecycle hooks: beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy and destroyed
* @author Xin Du <clark.duxin@gmail.com>
*/
'use strict'
const utils = require('../utils')
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description:
'disallow process.server and process.client in the following lifecycle hooks: beforeMount, mounted, beforeUpdate, updated, activated, deactivated, beforeDestroy and destroyed',
category: 'base'
},
messages: {
noEnv: 'Unexpected {{name}} in {{funcName}}.'
}
},
create (context) {
// variables should be defined here
const forbiddenNodes = []
const options = context.options[0] || {}
const ENV = ['server', 'client']
const HOOKS = new Set(['beforeMount', 'mounted', 'beforeUpdate', 'updated', 'activated', 'deactivated', 'beforeDestroy', 'destroyed'].concat(options.methods || []))
// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------
return {
MemberExpression (node) {
const objectName = node.object.name
if (objectName === 'process') {
const propertyName = node.computed ? node.property.value : node.property.name
if (propertyName && ENV.includes(propertyName)) {
forbiddenNodes.push({ name: 'process.' + propertyName, node })
}
}
},
...utils.executeOnVue(context, obj => {
for (const funcName of HOOKS) {
const func = utils.getFunctionWithName(obj, funcName)
if (func) {
for (const { name, node: child } of forbiddenNodes) {
if (utils.isInFunction(func, child)) {
context.report({
node: child,
messageId: 'noEnv',
data: {
name,
funcName
}
})
}
}
}
}
})
}
}
}
+70
View File
@@ -0,0 +1,70 @@
/**
* @fileoverview disallow `window/document` in `created/beforeCreate`
* @author Xin Du <clark.duxin@gmail.com>
*/
'use strict'
const utils = require('../utils')
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description: 'disallow `window/document` in `created/beforeCreate`',
category: 'base'
},
messages: {
noGlobals: 'Unexpected {{name}} in {{funcName}}.'
}
},
create (context) {
const forbiddenNodes = []
const options = context.options[0] || {}
const HOOKS = new Set(
['created', 'beforeCreate'].concat(options.methods || [])
)
const GLOBALS = ['window', 'document']
function isGlobals (name) {
return GLOBALS.includes(name)
}
return {
MemberExpression (node) {
if (!node.object) return
const name = node.object.name
if (isGlobals(name)) {
forbiddenNodes.push({ name, node })
}
},
VariableDeclarator (node) {
if (!node.init) return
const name = node.init.name
if (isGlobals(name)) {
forbiddenNodes.push({ name, node })
}
},
...utils.executeOnVue(context, obj => {
for (const { funcName, name, node } of utils.getFunctionWithChild(obj, HOOKS, forbiddenNodes)) {
context.report({
node,
messageId: 'noGlobals',
data: {
name,
funcName
}
})
}
})
}
}
}
+90
View File
@@ -0,0 +1,90 @@
/**
* @fileoverview disallow `this` in `asyncData/fetch`
* @author Xin Du <clark.duxin@gmail.com>
*/
'use strict'
const satisfies = require('semver/ranges/intersects')
const utils = require('../utils')
const resolver = require('../utils/resolver')
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description: 'disallow `this` in `asyncData/fetch`',
category: 'base'
},
messages: {
noThis: 'Unexpected this in {{funcName}}.'
}
},
create (context) {
// variables should be defined here
const forbiddenNodes = new Map()
const options = context.options[0] || {}
const HOOKS = new Set(
['asyncData'].concat(options.methods || [])
)
const { version } = resolver
// new fetch API can use `this` since 2.12.0
if (version && satisfies(version, '<2.12.0')) {
HOOKS.add('fetch')
}
let nodeUsingThis = []
// ----------------------------------------------------------------------
// Helpers
// ----------------------------------------------------------------------
function enterFunction () {
nodeUsingThis = []
}
function exitFunction (node) {
if (nodeUsingThis.length > 0) {
forbiddenNodes.set(node, nodeUsingThis)
}
}
function markThisUsed (node) {
nodeUsingThis.push(node)
}
// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------
return {
FunctionExpression: enterFunction,
'FunctionExpression:exit': exitFunction,
ArrowFunctionExpression: enterFunction,
'ArrowFunctionExpression:exit': exitFunction,
ThisExpression: markThisUsed,
Super: markThisUsed,
...utils.executeOnVue(context, obj => {
for (const funcName of HOOKS) {
const prop = utils.getFunctionWithName(obj, funcName)
if (prop && forbiddenNodes.has(prop.value)) {
for (const node of forbiddenNodes.get(prop.value)) {
context.report({
node: node,
messageId: 'noThis',
data: {
funcName
}
})
}
}
}
})
}
}
}
+70
View File
@@ -0,0 +1,70 @@
/**
* @fileoverview disallow `setTimeout/setInterval` in `asyncData/fetch`
* @author Xin Du <clark.duxin@gmail.com>
*/
'use strict'
const utils = require('../utils')
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description: 'disallow `setTimeout/setInterval` in `asyncData/fetch`',
category: 'recommended'
},
messages: {
noTiming: 'Unexpected {{name}} in {{funcName}}.'
}
},
create (context) {
const forbiddenNodes = []
const options = context.options[0] || {}
const HOOKS = new Set(
['fetch', 'asyncData'].concat(options.methods || [])
)
const TIMING = ['setTimeout', 'setInterval']
function isTiming (name) {
return TIMING.includes(name)
}
return {
CallExpression (node) {
if (!node.callee) return
const name = node.callee.name
if (isTiming(name)) {
forbiddenNodes.push({ name, node })
}
},
VariableDeclarator (node) {
if (!node.init) return
const name = node.init.name
if (isTiming(name)) {
forbiddenNodes.push({ name, node })
}
},
...utils.executeOnVue(context, obj => {
for (const { funcName, name, node } of utils.getFunctionWithChild(obj, HOOKS, forbiddenNodes)) {
context.report({
node,
messageId: 'noTiming',
data: {
name,
funcName
}
})
}
})
}
}
}
+55
View File
@@ -0,0 +1,55 @@
/**
* @fileoverview enforce component's head property to be a function.
* @author Xin Du <clark.duxin@gmail.com>
*/
'use strict'
const utils = require('../utils')
// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
module.exports = {
meta: {
docs: {
description: "enforce component's head property to be a function",
category: 'recommended'
},
fixable: 'code',
messages: {
head: '`head` property in component must be a function.'
}
},
create (context) {
const sourceCode = context.getSourceCode()
return utils.executeOnVueComponent(context, (obj) => {
obj.properties
.filter(p =>
p.type === 'Property' &&
p.key.type === 'Identifier' &&
p.key.name === 'head' &&
p.value.type !== 'FunctionExpression' &&
p.value.type !== 'ArrowFunctionExpression' &&
p.value.type !== 'Identifier' &&
p.value.type !== 'CallExpression'
)
.forEach(p => {
context.report({
node: p,
messageId: 'head',
fix (fixer) {
const tokens = utils.getFirstAndLastTokens(p.value, sourceCode)
return [
fixer.insertTextBefore(tokens.first, 'function() {\nreturn '),
fixer.insertTextAfter(tokens.last, ';\n}')
]
}
})
})
})
}
}
+71
View File
@@ -0,0 +1,71 @@
const utils = require('eslint-plugin-vue/lib/utils')
module.exports = Object.assign(
{
getProperty (node, name, condition) {
return node.properties.find(
p => p.type === 'Property' && name === utils.getStaticPropertyName(p.key) && condition(p)
)
},
getProperties (node, names) {
return node.properties.filter(
p => p.type === 'Property' && (!names.size || names.has(utils.getStaticPropertyName(p.key)))
)
},
getFunctionWithName (rootNode, name) {
return this.getProperty(
rootNode,
name,
item => item.value.type === 'ArrowFunctionExpression' || item.value.type === 'FunctionExpression'
)
},
isInFunction (func, child) {
if (func.value.type === 'FunctionExpression') {
if (
child &&
child.loc.start.line >= func.value.loc.start.line &&
child.loc.end.line <= func.value.loc.end.line
) {
return true
}
}
},
* getFunctionWithChild (rootNode, funcNames, childNodes) {
const funcNodes = this.getProperties(rootNode, funcNames)
for (const func of funcNodes) {
for (const { name, node: child } of childNodes) {
const funcName = utils.getStaticPropertyName(func.key)
if (!funcName) continue
if (this.isInFunction(func, child)) {
yield { name, node: child, func, funcName }
}
}
}
},
isOpenParen (token) {
return token.type === 'Punctuator' && token.value === '('
},
isCloseParen (token) {
return token.type === 'Punctuator' && token.value === ')'
},
getFirstAndLastTokens (node, sourceCode) {
let first = sourceCode.getFirstToken(node)
let last = sourceCode.getLastToken(node)
// If the value enclosed by parentheses, update the 'first' and 'last' by the parentheses.
while (true) {
const prev = sourceCode.getTokenBefore(first)
const next = sourceCode.getTokenAfter(last)
if (this.isOpenParen(prev) && this.isCloseParen(next)) {
first = prev
last = next
} else {
return { first, last }
}
}
}
},
utils
)
+21
View File
@@ -0,0 +1,21 @@
module.exports = {
__version: undefined,
get version () {
if (this.__version === undefined) {
return this.loadNuxtPkg()
}
return this.__version
},
loadPkg (pkgName) {
try {
return require(`${pkgName}/package.json`)
} catch (e) {
return {}
}
},
loadNuxtPkg () {
const { version } = this.loadPkg('nuxt') || this.loadPkg('nuxt-edge')
this.__version = version || false
return this.__version
}
}
+89
View File
@@ -0,0 +1,89 @@
{
"_args": [
[
"eslint-plugin-nuxt@1.0.0",
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
]
],
"_development": true,
"_from": "eslint-plugin-nuxt@1.0.0",
"_id": "eslint-plugin-nuxt@1.0.0",
"_inBundle": false,
"_integrity": "sha512-/wStWT367UXimakvNkYmG66dlP+O4CIEDS7Kg8BrwSlLX/ubQRZowVT3oJqspJJvR6jqJPMdGym5PBYd5iE+xg==",
"_location": "/eslint-plugin-nuxt",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "eslint-plugin-nuxt@1.0.0",
"name": "eslint-plugin-nuxt",
"escapedName": "eslint-plugin-nuxt",
"rawSpec": "1.0.0",
"saveSpec": null,
"fetchSpec": "1.0.0"
},
"_requiredBy": [
"#DEV:/"
],
"_resolved": "https://registry.npmjs.org/eslint-plugin-nuxt/-/eslint-plugin-nuxt-1.0.0.tgz",
"_spec": "1.0.0",
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
"author": {
"name": "Clark Du",
"email": "clarkdo@gmail.com"
},
"bugs": {
"url": "https://github.com/nuxt/eslint-plugin-nuxt/issues"
},
"dependencies": {
"eslint-plugin-vue": "^6.2.2",
"semver": "^7.3.2",
"vue-eslint-parser": "^7.0.0"
},
"description": "ESLint plugin for Nuxt.js",
"devDependencies": {
"eslint": "^7.0.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"husky": "^4.2.5",
"jest": "^26.0.1",
"lint-staged": "^10.2.2",
"standard-version": "^8.0.0"
},
"files": [
"lib",
"!__tests__"
],
"homepage": "https://github.com/nuxt/eslint-plugin-nuxt#readme",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"keywords": [
"nuxt",
"eslint",
"eslintplugin"
],
"license": "MIT",
"lint-staged": {
"*.js": [
"eslint"
]
},
"main": "lib/index.js",
"name": "eslint-plugin-nuxt",
"repository": {
"type": "git",
"url": "git+https://github.com/nuxt/eslint-plugin-nuxt.git"
},
"scripts": {
"lint": "eslint ./",
"release": "standard-version",
"test": "jest --silent"
},
"version": "1.0.0"
}