ags
This commit is contained in:
parent
eddf7cecb8
commit
aea798d119
16631 changed files with 1480363 additions and 257 deletions
33
home/ags/node_modules/eslint-plugin-promise/rules/lib/eslint-compat.js
generated
vendored
Normal file
33
home/ags/node_modules/eslint-plugin-promise/rules/lib/eslint-compat.js
generated
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
'use strict'
|
||||
|
||||
function getSourceCode(context) {
|
||||
if (context.sourceCode != null) {
|
||||
return context.sourceCode
|
||||
}
|
||||
|
||||
return context.getSourceCode()
|
||||
}
|
||||
|
||||
function getAncestors(context, node) {
|
||||
const sourceCode = getSourceCode(context)
|
||||
if (typeof sourceCode.getAncestors === 'function') {
|
||||
return sourceCode.getAncestors(node)
|
||||
}
|
||||
|
||||
return context.getAncestors(node)
|
||||
}
|
||||
|
||||
function getScope(context, node) {
|
||||
const sourceCode = getSourceCode(context)
|
||||
if (typeof sourceCode.getScope === 'function') {
|
||||
return sourceCode.getScope(node)
|
||||
}
|
||||
|
||||
return context.getScope(node)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getSourceCode,
|
||||
getAncestors,
|
||||
getScope,
|
||||
}
|
||||
17
home/ags/node_modules/eslint-plugin-promise/rules/lib/get-docs-url.js
generated
vendored
Normal file
17
home/ags/node_modules/eslint-plugin-promise/rules/lib/get-docs-url.js
generated
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
'use strict'
|
||||
|
||||
const REPO_URL = 'https://github.com/eslint-community/eslint-plugin-promise'
|
||||
|
||||
/**
|
||||
* Generates the URL to documentation for the given rule name. It uses the
|
||||
* package version to build the link to a tagged version of the
|
||||
* documentation file.
|
||||
*
|
||||
* @param {string} ruleName - Name of the eslint rule
|
||||
* @returns {string} URL to the documentation for the given rule
|
||||
*/
|
||||
function getDocsUrl(ruleName) {
|
||||
return `${REPO_URL}/blob/main/docs/rules/${ruleName}.md`
|
||||
}
|
||||
|
||||
module.exports = getDocsUrl
|
||||
37
home/ags/node_modules/eslint-plugin-promise/rules/lib/has-promise-callback.js
generated
vendored
Normal file
37
home/ags/node_modules/eslint-plugin-promise/rules/lib/has-promise-callback.js
generated
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* Library: Has Promise Callback
|
||||
* Makes sure that an Expression node is part of a promise
|
||||
* with callback functions (like then() or catch())
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* @typedef {import('estree').SimpleCallExpression} CallExpression
|
||||
* @typedef {import('estree').MemberExpression} MemberExpression
|
||||
* @typedef {import('estree').Identifier} Identifier
|
||||
*
|
||||
* @typedef {object} NameIsThenOrCatch
|
||||
* @property {'then' | 'catch'} name
|
||||
*
|
||||
* @typedef {object} PropertyIsThenOrCatch
|
||||
* @property {Identifier & NameIsThenOrCatch} property
|
||||
*
|
||||
* @typedef {object} CalleeIsPromiseCallback
|
||||
* @property {MemberExpression & PropertyIsThenOrCatch} callee
|
||||
*
|
||||
* @typedef {CallExpression & CalleeIsPromiseCallback} HasPromiseCallback
|
||||
*/
|
||||
/**
|
||||
* @param {import('estree').Node} node
|
||||
* @returns {node is HasPromiseCallback}
|
||||
*/
|
||||
function hasPromiseCallback(node) {
|
||||
// istanbul ignore if -- only being called within `CallExpression`
|
||||
if (node.type !== 'CallExpression') return
|
||||
if (node.callee.type !== 'MemberExpression') return
|
||||
const propertyName = node.callee.property.name
|
||||
return propertyName === 'then' || propertyName === 'catch'
|
||||
}
|
||||
|
||||
module.exports = hasPromiseCallback
|
||||
14
home/ags/node_modules/eslint-plugin-promise/rules/lib/is-callback.js
generated
vendored
Normal file
14
home/ags/node_modules/eslint-plugin-promise/rules/lib/is-callback.js
generated
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
'use strict'
|
||||
|
||||
const isNamedCallback = require('./is-named-callback')
|
||||
|
||||
function isCallback(node, exceptions) {
|
||||
const isCallExpression = node.type === 'CallExpression'
|
||||
// istanbul ignore next -- always invoked on `CallExpression`
|
||||
const callee = node.callee || {}
|
||||
const nameIsCallback = isNamedCallback(callee.name, exceptions)
|
||||
const isCB = isCallExpression && nameIsCallback
|
||||
return isCB
|
||||
}
|
||||
|
||||
module.exports = isCallback
|
||||
20
home/ags/node_modules/eslint-plugin-promise/rules/lib/is-inside-callback.js
generated
vendored
Normal file
20
home/ags/node_modules/eslint-plugin-promise/rules/lib/is-inside-callback.js
generated
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
'use strict'
|
||||
|
||||
const isInsidePromise = require('./is-inside-promise')
|
||||
|
||||
function isInsideCallback(node) {
|
||||
const isCallExpression =
|
||||
node.type === 'FunctionExpression' ||
|
||||
node.type === 'ArrowFunctionExpression' ||
|
||||
node.type === 'FunctionDeclaration' // this may be controversial
|
||||
|
||||
// it's totally fine to use promises inside promises
|
||||
if (isInsidePromise(node)) return
|
||||
|
||||
const name = node.params && node.params[0] && node.params[0].name
|
||||
const firstArgIsError = name === 'err' || name === 'error'
|
||||
const isInACallback = isCallExpression && firstArgIsError
|
||||
return isInACallback
|
||||
}
|
||||
|
||||
module.exports = isInsideCallback
|
||||
15
home/ags/node_modules/eslint-plugin-promise/rules/lib/is-inside-promise.js
generated
vendored
Normal file
15
home/ags/node_modules/eslint-plugin-promise/rules/lib/is-inside-promise.js
generated
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
'use strict'
|
||||
|
||||
function isInsidePromise(node) {
|
||||
const isFunctionExpression =
|
||||
node.type === 'FunctionExpression' ||
|
||||
node.type === 'ArrowFunctionExpression'
|
||||
const parent = node.parent || {}
|
||||
const callee = parent.callee || {}
|
||||
const name = (callee.property && callee.property.name) || ''
|
||||
const parentIsPromise = name === 'then' || name === 'catch'
|
||||
const isInCB = isFunctionExpression && parentIsPromise
|
||||
return isInCB
|
||||
}
|
||||
|
||||
module.exports = isInsidePromise
|
||||
14
home/ags/node_modules/eslint-plugin-promise/rules/lib/is-named-callback.js
generated
vendored
Normal file
14
home/ags/node_modules/eslint-plugin-promise/rules/lib/is-named-callback.js
generated
vendored
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
'use strict'
|
||||
|
||||
let callbacks = ['done', 'cb', 'callback', 'next']
|
||||
|
||||
module.exports = function isNamedCallback(potentialCallbackName, exceptions) {
|
||||
for (let i = 0; i < exceptions.length; i++) {
|
||||
callbacks = callbacks.filter((item) => {
|
||||
return item !== exceptions[i]
|
||||
})
|
||||
}
|
||||
return callbacks.some((trueCallbackName) => {
|
||||
return potentialCallbackName === trueCallbackName
|
||||
})
|
||||
}
|
||||
48
home/ags/node_modules/eslint-plugin-promise/rules/lib/is-promise-constructor.js
generated
vendored
Normal file
48
home/ags/node_modules/eslint-plugin-promise/rules/lib/is-promise-constructor.js
generated
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/**
|
||||
* Library: isPromiseConstructor
|
||||
* Makes sure that an Expression node is new Promise().
|
||||
*/
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* @typedef {import('estree').Node} Node
|
||||
* @typedef {import('estree').Expression} Expression
|
||||
* @typedef {import('estree').NewExpression} NewExpression
|
||||
* @typedef {import('estree').FunctionExpression} FunctionExpression
|
||||
* @typedef {import('estree').ArrowFunctionExpression} ArrowFunctionExpression
|
||||
*
|
||||
* @typedef {NewExpression & { callee: { type: 'Identifier', name: 'Promise' } }} NewPromise
|
||||
* @typedef {NewPromise & { arguments: [FunctionExpression | ArrowFunctionExpression] }} NewPromiseWithInlineExecutor
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Checks whether the given node is new Promise().
|
||||
* @param {Node} node
|
||||
* @returns {node is NewPromise}
|
||||
*/
|
||||
function isPromiseConstructor(node) {
|
||||
return (
|
||||
node.type === 'NewExpression' &&
|
||||
node.callee.type === 'Identifier' &&
|
||||
node.callee.name === 'Promise'
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given node is new Promise(() => {}).
|
||||
* @param {Node} node
|
||||
* @returns {node is NewPromiseWithInlineExecutor}
|
||||
*/
|
||||
function isPromiseConstructorWithInlineExecutor(node) {
|
||||
return (
|
||||
isPromiseConstructor(node) &&
|
||||
node.arguments.length === 1 &&
|
||||
(node.arguments[0].type === 'FunctionExpression' ||
|
||||
node.arguments[0].type === 'ArrowFunctionExpression')
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isPromiseConstructor,
|
||||
isPromiseConstructorWithInlineExecutor,
|
||||
}
|
||||
36
home/ags/node_modules/eslint-plugin-promise/rules/lib/is-promise.js
generated
vendored
Normal file
36
home/ags/node_modules/eslint-plugin-promise/rules/lib/is-promise.js
generated
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* Library: isPromise
|
||||
* Makes sure that an Expression node is part of a promise.
|
||||
*/
|
||||
'use strict'
|
||||
|
||||
const PROMISE_STATICS = require('./promise-statics')
|
||||
|
||||
function isPromise(expression) {
|
||||
return (
|
||||
// hello.then()
|
||||
(expression.type === 'CallExpression' &&
|
||||
expression.callee.type === 'MemberExpression' &&
|
||||
expression.callee.property.name === 'then') ||
|
||||
// hello.catch()
|
||||
(expression.type === 'CallExpression' &&
|
||||
expression.callee.type === 'MemberExpression' &&
|
||||
expression.callee.property.name === 'catch') ||
|
||||
// hello.finally()
|
||||
(expression.type === 'CallExpression' &&
|
||||
expression.callee.type === 'MemberExpression' &&
|
||||
expression.callee.property.name === 'finally') ||
|
||||
// somePromise.ANYTHING()
|
||||
(expression.type === 'CallExpression' &&
|
||||
expression.callee.type === 'MemberExpression' &&
|
||||
isPromise(expression.callee.object)) ||
|
||||
// Promise.STATIC_METHOD()
|
||||
(expression.type === 'CallExpression' &&
|
||||
expression.callee.type === 'MemberExpression' &&
|
||||
expression.callee.object.type === 'Identifier' &&
|
||||
expression.callee.object.name === 'Promise' &&
|
||||
PROMISE_STATICS[expression.callee.property.name])
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = isPromise
|
||||
10
home/ags/node_modules/eslint-plugin-promise/rules/lib/promise-statics.js
generated
vendored
Normal file
10
home/ags/node_modules/eslint-plugin-promise/rules/lib/promise-statics.js
generated
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
'use strict'
|
||||
|
||||
module.exports = {
|
||||
all: true,
|
||||
allSettled: true,
|
||||
any: true,
|
||||
race: true,
|
||||
reject: true,
|
||||
resolve: true,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue