拿掉 build files

This commit is contained in:
2022-07-18 16:33:23 +08:00
parent 41e2287bcb
commit 3707f158a3
31953 changed files with 0 additions and 4411796 deletions
-104
View File
@@ -1,104 +0,0 @@
'use strict';
const reservedWords = require('reserved-words');
const resolveVariableName = require('./resolve-variable-name');
const indexifyName = (name, index) => name + '_'.repeat(index);
const scopeHasArgumentsSpecial = scope => {
while (scope) {
if (scope.taints.get('arguments')) {
return true;
}
scope = scope.upper;
}
return false;
};
const someScopeHasVariableName = (name, scopes) => scopes.some(scope => resolveVariableName(name, scope));
const someScopeIsStrict = scopes => scopes.some(scope => scope.isStrict);
const nameCollidesWithArgumentsSpecial = (name, scopes, isStrict) => {
if (name !== 'arguments') {
return false;
}
return isStrict || scopes.some(scope => scopeHasArgumentsSpecial(scope));
};
/*
Unresolved reference is probably from the global scope. We should avoid using that name.
For example, like `foo` and `bar` below.
```
function unicorn() {
return foo;
}
function unicorn() {
return function() {
return bar;
};
}
```
*/
const isUnresolvedName = (name, scopes) => scopes.some(scope =>
scope.references.some(reference => reference.identifier && reference.identifier.name === name && !reference.resolved) ||
isUnresolvedName(name, scope.childScopes)
);
const isSafeName = (name, scopes, ecmaVersion, isStrict) => {
ecmaVersion = Math.min(6, ecmaVersion); // 6 is the latest version understood by `reservedWords`
return (
!someScopeHasVariableName(name, scopes) &&
!reservedWords.check(name, ecmaVersion, isStrict) &&
!nameCollidesWithArgumentsSpecial(name, scopes, isStrict) &&
!isUnresolvedName(name, scopes)
);
};
const alwaysTrue = () => true;
/**
Rule-specific name check function.
@callback isSafe
@param {string} indexifiedName - The generated candidate name.
@param {Scope[]} scopes - The same list of scopes you pass to `avoidCapture`.
@returns {boolean} - `true` if the `indexifiedName` is ok.
*/
/**
Generates a unique name prefixed with `name` such that:
- it is not defined in any of the `scopes`,
- it is not a reserved word,
- it is not `arguments` in strict scopes (where `arguments` is not allowed),
- it does not collide with the actual `arguments` (which is always defined in function scopes).
Useful when you want to rename a variable (or create a new variable) while being sure not to shadow any other variables in the code.
@param {string} name - The desired name for a new variable.
@param {Scope[]} scopes - The list of scopes the new variable will be referenced in.
@param {number} ecmaVersion - The language version, get it from `context.parserOptions.ecmaVersion`.
@param {isSafe} [isSafe] - Rule-specific name check function.
@returns {string} - Either `name` as is, or a string like `${name}_` suffixed with underscores to make the name unique.
*/
module.exports = (name, scopes, ecmaVersion, isSafe = alwaysTrue) => {
const isStrict = someScopeIsStrict(scopes);
let index = 0;
let indexifiedName = indexifyName(name, index);
while (
!isSafeName(indexifiedName, scopes, ecmaVersion, isStrict) ||
!isSafe(indexifiedName, scopes)
) {
index++;
indexifiedName = indexifyName(name, index);
}
return indexifiedName;
};
-41
View File
@@ -1,41 +0,0 @@
'use strict';
const enforceNew = [
'Object',
'Array',
'ArrayBuffer',
'BigInt64Array',
'BigUint64Array',
'DataView',
'Date',
'Error',
'Float32Array',
'Float64Array',
'Function',
'Int8Array',
'Int16Array',
'Int32Array',
'Map',
'WeakMap',
'Set',
'WeakSet',
'Promise',
'RegExp',
'Uint8Array',
'Uint16Array',
'Uint32Array',
'Uint8ClampedArray'
];
const disallowNew = [
'BigInt',
'Boolean',
'Number',
'String',
'Symbol'
];
module.exports = {
enforceNew,
disallowNew
};
@@ -1,20 +0,0 @@
'use strict';
module.exports = (combinations, length = Infinity) => {
const total = combinations.reduce((total, {length}) => total * length, 1);
const samples = Array.from({length: Math.min(total, length)}, (_, sampleIndex) => {
let indexRemaining = sampleIndex;
return combinations.reduceRight((combination, items) => {
const {length} = items;
const index = indexRemaining % length;
indexRemaining = (indexRemaining - index) / length;
return [items[index], ...combination];
}, []);
});
return {
total,
samples
};
};
-98
View File
@@ -1,98 +0,0 @@
{
"mouse": [
"click",
"contextmenu",
"dblclick",
"mousedown",
"mouseenter",
"mouseleave",
"mousemove",
"mouseover",
"mouseout",
"mouseup"
],
"keyboard": [
"keydown",
"keypress",
"keyup"
],
"frame": [
"abort",
"beforeunload",
"error",
"hashchange",
"load",
"pageshow",
"pagehide",
"resize",
"scroll",
"unload"
],
"form": [
"blur",
"change",
"focus",
"focusin",
"focusout",
"input",
"invalid",
"reset",
"search",
"select",
"submit"
],
"drag": [
"drag",
"dragend",
"dragenter",
"dragleave",
"dragover",
"dragstart",
"drop"
],
"clipboard": [
"copy",
"cut",
"paste"
],
"print": [
"afterprint",
"beforeprint"
],
"media": [
"abort",
"canplay",
"canplaythrough",
"durationchange",
"ended",
"error",
"loadeddata",
"loadedmetadata",
"loadstart",
"pause",
"play",
"playing",
"progress",
"ratechange",
"seeked",
"seeking",
"stalled",
"suspend",
"timeupdate",
"volumechange",
"waiting"
],
"server-sent": [
"error",
"message",
"open"
],
"misc": [
"wheel",
"online",
"offline",
"show",
"toggle",
"wheel"
]
}
@@ -1,6 +0,0 @@
'use strict';
module.exports = string => string.replace(
/(?<=(?:^|[^\\])(?:\\\\)*)(?<symbol>(?:`|\$(?={)))/g,
'\\$<symbol>'
);
@@ -1,10 +0,0 @@
'use strict';
const path = require('path');
const packageJson = require('../../package');
const repoUrl = 'https://github.com/sindresorhus/eslint-plugin-unicorn';
module.exports = filename => {
const ruleName = path.basename(filename, '.js');
return `${repoUrl}/blob/v${packageJson.version}/docs/rules/${ruleName}.md`;
};
-10
View File
@@ -1,10 +0,0 @@
'use strict';
const {uniq} = require('lodash');
const getReferences = scope => uniq(
scope.references.concat(
...scope.childScopes.map(scope => getReferences(scope))
)
);
module.exports = getReferences;
@@ -1,8 +0,0 @@
'use strict';
const {uniq} = require('lodash');
// Get identifiers of given variable
module.exports = ({identifiers, references}) => uniq([
...identifiers,
...references.map(({identifier}) => identifier)
]);
@@ -1,11 +0,0 @@
'use strict';
const isSameNode = require('./is-same-node');
module.exports = identifier =>
identifier.parent.type === 'AssignmentPattern' &&
identifier.parent.left === identifier &&
identifier.parent.parent.type === 'Property' &&
isSameNode(identifier, identifier.parent.parent.key) &&
identifier.parent.parent.value === identifier.parent &&
identifier.parent.parent.shorthand;
-2
View File
@@ -1,2 +0,0 @@
'use strict';
module.exports = (node, value) => node && node.type === 'Literal' && node.value === value;
-12
View File
@@ -1,12 +0,0 @@
'use strict';
const isMethodNamed = (node, name) => {
return (
node.type === 'CallExpression' &&
node.callee.type === 'MemberExpression' &&
node.callee.property.type === 'Identifier' &&
node.callee.property.name === name
);
};
module.exports = isMethodNamed;
-11
View File
@@ -1,11 +0,0 @@
'use strict';
module.exports = (node, object, method) => {
const {callee} = node;
return (
callee.type === 'MemberExpression' &&
callee.object.type === 'Identifier' &&
callee.object.name === object &&
callee.property.type === 'Identifier' &&
callee.property.name === method
);
};
-11
View File
@@ -1,11 +0,0 @@
'use strict';
module.exports = (node1, node2) =>
node1 &&
node2 &&
(
node1 === node2 ||
// In `babel-eslint` parent.key is not reference of identifier, #444
// issue https://github.com/babel/babel-eslint/issues/809
(node1.range[0] === node2.range[0] && node1.range[1] === node2.range[1])
);
-36
View File
@@ -1,36 +0,0 @@
'use strict';
const isSameNode = require('./is-same-node');
/**
* Finds the eslint-scope reference in the given scope.
* @param {Object} scope The scope to search.
* @param {ASTNode} node The identifier node.
* @returns {Reference|undefined} Returns the found reference or null if none were found.
*/
function findReference(scope, node) {
const references = scope.references
.filter(reference => isSameNode(reference.identifier, node));
if (references.length === 1) {
return references[0];
}
}
/**
* Checks if the given identifier node is shadowed in the given scope.
* @param {Object} scope The current scope.
* @param {string} node The identifier node to check
* @returns {boolean} Whether or not the name is shadowed.
*/
function isShadowed(scope, node) {
const reference = findReference(scope, node);
return (
reference &&
reference.resolved &&
reference.resolved.defs.length > 0
);
}
module.exports = isShadowed;
@@ -1,6 +0,0 @@
'use strict';
module.exports = identifier =>
identifier.parent.type === 'ExportSpecifier' &&
identifier.parent.exported.name === identifier.name &&
identifier.parent.local.name === identifier.name;
@@ -1,6 +0,0 @@
'use strict';
module.exports = identifier =>
identifier.parent.type === 'ImportSpecifier' &&
identifier.parent.imported.name === identifier.name &&
identifier.parent.local.name === identifier.name;
@@ -1,8 +0,0 @@
'use strict';
const isSameNode = require('./is-same-node');
module.exports = identifier =>
identifier.parent.type === 'Property' &&
identifier.parent.shorthand &&
isSameNode(identifier, identifier.parent.key);
@@ -1,3 +0,0 @@
'use strict';
module.exports = name => /^[$_a-z][\w$]*$/i.test(name);
@@ -1,3 +0,0 @@
'use strict';
module.exports = ({parent}) => !parent || parent.type === 'ExpressionStatement';
-65
View File
@@ -1,65 +0,0 @@
'use strict';
module.exports = options => {
const {
name,
names,
length,
object,
min,
max,
property = ''
} = {
min: 0,
max: Infinity,
...options
};
const prefix = property ? `${property}.` : '';
const selector = [
`[${prefix}type="CallExpression"]`,
`[${prefix}callee.type="MemberExpression"]`,
`[${prefix}callee.computed=false]`,
`[${prefix}callee.property.type="Identifier"]`
];
if (name) {
selector.push(`[callee.property.name="${name}"]`);
}
if (Array.isArray(names) && names.length !== 0) {
selector.push(
':matches(' +
names.map(name => `[${prefix}callee.property.name="${name}"]`).join(', ') +
')'
);
}
if (object) {
selector.push(`[${prefix}callee.object.type="Identifier"]`);
selector.push(`[${prefix}callee.object.name="${object}"]`);
}
if (typeof length === 'number') {
selector.push(`[${prefix}arguments.length=${length}]`);
}
if (min !== 0) {
selector.push(`[${prefix}arguments.length>=${min}]`);
}
if (Number.isFinite(max)) {
selector.push(`[${prefix}arguments.length<=${max}]`);
}
const maxArguments = Number.isFinite(max) ? max : length;
if (typeof maxArguments === 'number') {
// Exclude arguments with `SpreadElement` type
for (let index = 0; index < maxArguments; index += 1) {
selector.push(`[${prefix}arguments.${index}.type!="SpreadElement"]`);
}
}
return selector.join('');
};
-86
View File
@@ -1,86 +0,0 @@
'use strict';
// https://github.com/eslint/espree/blob/6b7d0b8100537dcd5c84a7fb17bbe28edcabe05d/lib/token-translator.js#L20
const tokenTypesNeedsSemicolon = new Set([
'String',
'Null',
'Boolean',
'Numeric',
'RegularExpression'
]);
const charactersMightNeedsSemicolon = new Set([
'[',
'(',
'/',
'`',
'+',
'-',
'*',
',',
'.'
]);
/**
Determines if a semicolon needs to be inserted before `code`, in order to avoid a SyntaxError.
@param {Token} tokenBefore Token before `code`.
@param {SourceCode} sourceCode
@param {String} [code] Code text to determine.
@returns {boolean} `true` if a semicolon needs to be inserted before `code`.
*/
function needsSemicolon(tokenBefore, sourceCode, code) {
if (
code === '' ||
(code && !charactersMightNeedsSemicolon.has(code.charAt(0)))
) {
return false;
}
if (!tokenBefore) {
return false;
}
const {type, value} = tokenBefore;
if (type === 'Punctuator') {
if (value === ';') {
return false;
}
if (value === ']' || value === ')') {
return true;
}
}
if (tokenTypesNeedsSemicolon.has(type)) {
return true;
}
if (type === 'Template') {
return value.endsWith('`');
}
const lastBlockNode = sourceCode.getNodeByRangeIndex(tokenBefore.range[0]);
if (lastBlockNode && lastBlockNode.type === 'ObjectExpression') {
return true;
}
if (type === 'Identifier') {
// `for...of`
if (value === 'of' && lastBlockNode && lastBlockNode.type === 'ForOfStatement') {
return false;
}
// `await`
if (value === 'await' && lastBlockNode && lastBlockNode.type === 'AwaitExpression') {
return false;
}
return true;
}
return false;
}
module.exports = needsSemicolon;
-30
View File
@@ -1,30 +0,0 @@
'use strict';
// AST Types:
// https://github.com/eslint/espree/blob/master/lib/ast-node-types.js#L18
// Only types possible to be `callee` or `argument` are listed
const impossibleNodeTypes = [
'ArrayExpression',
'ArrowFunctionExpression',
'ClassExpression',
'FunctionExpression',
'Literal',
'ObjectExpression',
'TemplateLiteral'
];
// We might need this later
/* istanbul ignore next */
const isNotDomNode = node =>
impossibleNodeTypes.includes(node.type) ||
(node.type === 'Identifier' && node.name === 'undefined');
const notDomNodeSelector = node => [
...impossibleNodeTypes.map(type => `[${node}.type!="${type}"]`),
`:not([${node}.type="Identifier"][${node}.name="undefined"])`
].join('');
module.exports = {
isNotDomNode,
notDomNodeSelector
};
-17
View File
@@ -1,17 +0,0 @@
'use strict';
/**
Escape string and wrap the result in quotes.
@param {string} string - The string to be quoted.
@param {string} quote - The quote character.
@returns {string} - The quoted and escaped string.
*/
module.exports = (string, quote = '\'') => {
const escaped = string
.replace(/\\/g, '\\\\')
.replace(/\r/g, '\\r')
.replace(/\n/g, '\\n')
.replace(new RegExp(quote, 'g'), `\\${quote}`);
return quote + escaped + quote;
};
-37
View File
@@ -1,37 +0,0 @@
'use strict';
const isShorthandPropertyIdentifier = require('./is-shorthand-property-identifier');
const isAssignmentPatternShorthandPropertyIdentifier = require('./is-assignment-pattern-shorthand-property-identifier');
const isShorthandImportIdentifier = require('./is-shorthand-import-identifier');
const isShorthandExportIdentifier = require('./is-shorthand-export-identifier');
function renameIdentifier(identifier, name, fixer, sourceCode) {
if (
isShorthandPropertyIdentifier(identifier) ||
isAssignmentPatternShorthandPropertyIdentifier(identifier)
) {
return fixer.replaceText(identifier, `${identifier.name}: ${name}`);
}
if (isShorthandImportIdentifier(identifier)) {
return fixer.replaceText(identifier, `${identifier.name} as ${name}`);
}
if (isShorthandExportIdentifier(identifier)) {
return fixer.replaceText(identifier, `${name} as ${identifier.name}`);
}
// `TypeParameter` default value
if (identifier.default) {
return fixer.replaceText(identifier, `${name} = ${sourceCode.getText(identifier.default)}`);
}
// `typeAnnotation`
if (identifier.typeAnnotation) {
return fixer.replaceText(identifier, `${name}${sourceCode.getText(identifier.typeAnnotation)}`);
}
return fixer.replaceText(identifier, name);
}
module.exports = renameIdentifier;
-7
View File
@@ -1,7 +0,0 @@
'use strict';
const getVariableIdentifiers = require('./get-variable-identifiers');
const renameIdentifier = require('./rename-identifier');
module.exports = (variable, name, fixer, sourceCode) =>
getVariableIdentifiers(variable)
.map(identifier => renameIdentifier(identifier, name, fixer, sourceCode));
-12
View File
@@ -1,12 +0,0 @@
'use strict';
// Replace `StringLiteral` or `TemplateLiteral` node with raw text
module.exports = (fixer, node, raw) =>
fixer.replaceTextRange(
// Ignore quotes and backticks
[
node.range[0] + 1,
node.range[1] - 1
],
raw
);
@@ -1,9 +0,0 @@
'use strict';
module.exports = (fixer, node, replacement) => {
const {range: [start, end], tail} = node;
return fixer.replaceTextRange(
[start + 1, end - (tail ? 1 : 2)],
replacement
);
};
@@ -1,20 +0,0 @@
'use strict';
/**
Finds a variable named `name` in the scope `scope` (or it's parents).
@param {string} name - The variable name to be resolve.
@param {Scope} scope - The scope to look for the variable in.
@returns {Variable?} - The found variable, if any.
*/
module.exports = (name, scope) => {
while (scope) {
const variable = scope.set.get(name);
if (variable) {
return variable;
}
scope = scope.upper;
}
};