_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q17900 | createIndexMap | train | function createIndexMap(tokens, comments) {
const map = Object.create(null);
let tokenIndex = 0;
let commentIndex = 0;
let nextStart = 0;
let range = null;
while (tokenIndex < tokens.length || commentIndex < comments.length) {
nextStart = (commentIndex < comments.length) ? comments[comm... | javascript | {
"resource": ""
} |
q17901 | createCursorWithPadding | train | function createCursorWithPadding(tokens, comments, indexMap, startLoc, endLoc, beforeCount, afterCount) {
if (typeof beforeCount === "undefined" && typeof afterCount === "undefined") {
return new ForwardTokenCursor(tokens, comments, indexMap, startLoc, endLoc);
}
if (typeof beforeCount === "number" ... | javascript | {
"resource": ""
} |
q17902 | getAdjacentCommentTokensFromCursor | train | function getAdjacentCommentTokensFromCursor(cursor) {
const tokens = [];
let currentToken = cursor.getOneToken();
while (currentToken && astUtils.isCommentToken(currentToken)) {
tokens.push(currentToken);
currentToken = cursor.getOneToken();
}
return tokens;
} | javascript | {
"resource": ""
} |
q17903 | hasLeadingSpace | train | function hasLeadingSpace(token) {
const tokenBefore = sourceCode.getTokenBefore(token);
return tokenBefore && astUtils.isTokenOnSameLine(tokenBefore, token) && sourceCode.isSpaceBetweenTokens(tokenBefore, token);
} | javascript | {
"resource": ""
} |
q17904 | hasTrailingSpace | train | function hasTrailingSpace(token) {
const tokenAfter = sourceCode.getTokenAfter(token);
return tokenAfter && astUtils.isTokenOnSameLine(token, tokenAfter) && sourceCode.isSpaceBetweenTokens(token, tokenAfter);
} | javascript | {
"resource": ""
} |
q17905 | isLastTokenInCurrentLine | train | function isLastTokenInCurrentLine(token) {
const tokenAfter = sourceCode.getTokenAfter(token);
return !(tokenAfter && astUtils.isTokenOnSameLine(token, tokenAfter));
} | javascript | {
"resource": ""
} |
q17906 | isFirstTokenInCurrentLine | train | function isFirstTokenInCurrentLine(token) {
const tokenBefore = sourceCode.getTokenBefore(token);
return !(tokenBefore && astUtils.isTokenOnSameLine(token, tokenBefore));
} | javascript | {
"resource": ""
} |
q17907 | isBeforeClosingParen | train | function isBeforeClosingParen(token) {
const nextToken = sourceCode.getTokenAfter(token);
return (nextToken && astUtils.isClosingBraceToken(nextToken) || astUtils.isClosingParenToken(nextToken));
} | javascript | {
"resource": ""
} |
q17908 | checkSemicolonSpacing | train | function checkSemicolonSpacing(token, node) {
if (astUtils.isSemicolonToken(token)) {
const location = token.loc.start;
if (hasLeadingSpace(token)) {
if (!requireSpaceBefore) {
context.report({
node,
... | javascript | {
"resource": ""
} |
q17909 | checkForBreakAfter | train | function checkForBreakAfter(node, messageId) {
const openParen = sourceCode.getTokenAfter(node, astUtils.isNotClosingParenToken);
const nodeExpressionEnd = sourceCode.getTokenBefore(openParen);
if (openParen.loc.start.line !== nodeExpressionEnd.loc.end.line) {
contex... | javascript | {
"resource": ""
} |
q17910 | getTopLoopNode | train | function getTopLoopNode(node, excludedNode) {
const border = excludedNode ? excludedNode.range[1] : 0;
let retv = node;
let containingLoopNode = node;
while (containingLoopNode && containingLoopNode.range[0] >= border) {
retv = containingLoopNode;
containingLoopNode = getContainingLoopN... | javascript | {
"resource": ""
} |
q17911 | isSafe | train | function isSafe(loopNode, reference) {
const variable = reference.resolved;
const definition = variable && variable.defs[0];
const declaration = definition && definition.parent;
const kind = (declaration && declaration.type === "VariableDeclaration")
? declaration.kind
: "";
// Vari... | javascript | {
"resource": ""
} |
q17912 | isSafeReference | train | function isSafeReference(upperRef) {
const id = upperRef.identifier;
return (
!upperRef.isWrite() ||
variable.scope.variableScope === upperRef.from.variableScope &&
id.range[0] < border
);
} | javascript | {
"resource": ""
} |
q17913 | getUpperFunction | train | function getUpperFunction(node) {
for (let currentNode = node; currentNode; currentNode = currentNode.parent) {
if (anyFunctionPattern.test(currentNode.type)) {
return currentNode;
}
}
return null;
} | javascript | {
"resource": ""
} |
q17914 | isInLoop | train | function isInLoop(node) {
for (let currentNode = node; currentNode && !isFunction(currentNode); currentNode = currentNode.parent) {
if (isLoop(currentNode)) {
return true;
}
}
return false;
} | javascript | {
"resource": ""
} |
q17915 | isMethodWhichHasThisArg | train | function isMethodWhichHasThisArg(node) {
for (
let currentNode = node;
currentNode.type === "MemberExpression" && !currentNode.computed;
currentNode = currentNode.property
) {
if (currentNode.property.type === "Identifier") {
return arrayMethodPattern.test(currentNode... | javascript | {
"resource": ""
} |
q17916 | getOpeningParenOfParams | train | function getOpeningParenOfParams(node, sourceCode) {
return node.id
? sourceCode.getTokenAfter(node.id, isOpeningParenToken)
: sourceCode.getFirstToken(node, isOpeningParenToken);
} | javascript | {
"resource": ""
} |
q17917 | equalTokens | train | function equalTokens(left, right, sourceCode) {
const tokensL = sourceCode.getTokens(left);
const tokensR = sourceCode.getTokens(right);
if (tokensL.length !== tokensR.length) {
return false;
}
for (let i = 0; i < tokensL.length; ++i) {
if (tokensL[i].type !== tokensR[i].type ||
... | javascript | {
"resource": ""
} |
q17918 | combineArrays | train | function combineArrays(arr1, arr2) {
const res = [];
if (arr1.length === 0) {
return explodeArray(arr2);
}
if (arr2.length === 0) {
return explodeArray(arr1);
}
arr1.forEach(x1 => {
arr2.forEach(x2 => {
res.push([].concat(x1, x2));
});
});
ret... | javascript | {
"resource": ""
} |
q17919 | groupByProperty | train | function groupByProperty(objects) {
const groupedObj = objects.reduce((accumulator, obj) => {
const prop = Object.keys(obj)[0];
accumulator[prop] = accumulator[prop] ? accumulator[prop].concat(obj) : [obj];
return accumulator;
}, {});
return Object.keys(groupedObj).map(prop => grou... | javascript | {
"resource": ""
} |
q17920 | generateConfigsFromSchema | train | function generateConfigsFromSchema(schema) {
const configSet = new RuleConfigSet();
if (Array.isArray(schema)) {
for (const opt of schema) {
if (opt.enum) {
configSet.addEnums(opt.enum);
} else if (opt.type && opt.type === "object") {
if (!configS... | javascript | {
"resource": ""
} |
q17921 | createCoreRuleConfigs | train | function createCoreRuleConfigs() {
return Object.keys(builtInRules).reduce((accumulator, id) => {
const rule = rules.get(id);
const schema = (typeof rule === "function") ? rule.schema : rule.meta.schema;
accumulator[id] = generateConfigsFromSchema(schema);
return accumulator;
},... | javascript | {
"resource": ""
} |
q17922 | nearestBody | train | function nearestBody() {
const ancestors = context.getAncestors();
let ancestor = ancestors.pop(),
generation = 1;
while (ancestor && ["Program", "FunctionDeclaration",
"FunctionExpression", "ArrowFunctionExpression"
].indexOf(ancestor.typ... | javascript | {
"resource": ""
} |
q17923 | check | train | function check(node) {
const body = nearestBody(),
valid = ((body.type === "Program" && body.distance === 1) ||
body.distance === 2);
if (!valid) {
context.report({
node,
message: "Move {{type}} declarat... | javascript | {
"resource": ""
} |
q17924 | reportIfTooManyStatements | train | function reportIfTooManyStatements(node, count, max) {
if (count > max) {
const name = lodash.upperFirst(astUtils.getFunctionNameWithKind(node));
context.report({
node,
messageId: "exceed",
data: { name, count, max ... | javascript | {
"resource": ""
} |
q17925 | endFunction | train | function endFunction(node) {
const count = functionStack.pop();
if (ignoreTopLevelFunctions && functionStack.length === 0) {
topLevelFunctions.push({ node, count });
} else {
reportIfTooManyStatements(node, count, maxStatements);
}
... | javascript | {
"resource": ""
} |
q17926 | reportNoLineBreak | train | function reportNoLineBreak(token) {
const tokenBefore = sourceCode.getTokenBefore(token, { includeComments: true });
context.report({
loc: {
start: tokenBefore.loc.end,
end: token.loc.start
},
messageId: "un... | javascript | {
"resource": ""
} |
q17927 | reportRequiredLineBreak | train | function reportRequiredLineBreak(token) {
const tokenBefore = sourceCode.getTokenBefore(token, { includeComments: true });
context.report({
loc: {
start: tokenBefore.loc.end,
end: token.loc.start
},
messageI... | javascript | {
"resource": ""
} |
q17928 | checkAndReport | train | function checkAndReport(context, node, value, array, messageId) {
if (array.indexOf(value) !== -1) {
context.report({
node,
messageId,
data: {
module: value
}
});
}
} | javascript | {
"resource": ""
} |
q17929 | getLastTokenOnLine | train | function getLastTokenOnLine(node) {
const lastToken = sourceCode.getLastToken(node);
const secondToLastToken = sourceCode.getTokenBefore(lastToken);
return astUtils.isSemicolonToken(lastToken) && lastToken.loc.start.line > secondToLastToken.loc.end.line
? secondToLas... | javascript | {
"resource": ""
} |
q17930 | hasNewlineAfter | train | function hasNewlineAfter(node) {
const lastToken = getLastTokenOnLine(node);
const tokenAfter = sourceCode.getTokenAfter(lastToken, { includeComments: true });
return tokenAfter.loc.start.line - lastToken.loc.end.line >= 2;
} | javascript | {
"resource": ""
} |
q17931 | reportError | train | function reportError(node, location, expected) {
context.report({
node,
messageId: expected ? "expected" : "unexpected",
data: {
value: node.expression.value,
location
},
fix(fixer) {
... | javascript | {
"resource": ""
} |
q17932 | checkDirectives | train | function checkDirectives(node) {
const directives = astUtils.getDirectivePrologue(node);
if (!directives.length) {
return;
}
const firstDirective = directives[0];
const leadingComments = sourceCode.getCommentsBefore(firstDirective);
... | javascript | {
"resource": ""
} |
q17933 | isBoundary | train | function isBoundary(node) {
const t = node.type;
return (
t === "FunctionDeclaration" ||
t === "FunctionExpression" ||
t === "ArrowFunctionExpression" ||
/*
* Don't report the await expressions on for-await-of loop since it's
* asynchronous iteration intention... | javascript | {
"resource": ""
} |
q17934 | isLooped | train | function isLooped(node, parent) {
switch (parent.type) {
case "ForStatement":
return (
node === parent.test ||
node === parent.update ||
node === parent.body
);
case "ForOfStatement":
case "ForInStatement":
... | javascript | {
"resource": ""
} |
q17935 | validate | train | function validate(awaitNode) {
if (awaitNode.type === "ForOfStatement" && !awaitNode.await) {
return;
}
let node = awaitNode;
let parent = node.parent;
while (parent && !isBoundary(parent)) {
if (isLooped(node, parent)) {
... | javascript | {
"resource": ""
} |
q17936 | compareLocations | train | function compareLocations(itemA, itemB) {
return itemA.line - itemB.line || itemA.column - itemB.column;
} | javascript | {
"resource": ""
} |
q17937 | applyDirectives | train | function applyDirectives(options) {
const problems = [];
let nextDirectiveIndex = 0;
let currentGlobalDisableDirective = null;
const disabledRuleMap = new Map();
// enabledRules is only used when there is a current global disable directive.
const enabledRules = new Set();
const usedDisableD... | javascript | {
"resource": ""
} |
q17938 | validateExpression | train | function validateExpression(node) {
if (node.body.type === "BlockStatement") {
return;
}
const arrowToken = sourceCode.getTokenBefore(node.body, isNotOpeningParenToken);
const firstTokenOfBody = sourceCode.getTokenAfter(arrowToken);
if (arrow... | javascript | {
"resource": ""
} |
q17939 | isInBooleanContext | train | function isInBooleanContext(node, parent) {
return (
(BOOLEAN_NODE_TYPES.indexOf(parent.type) !== -1 &&
node === parent.test) ||
// !<bool>
(parent.type === "UnaryExpression" &&
parent.operator === "!")
);
... | javascript | {
"resource": ""
} |
q17940 | findReference | train | function findReference(scope, node) {
const references = scope.references.filter(reference => reference.identifier.range[0] === node.range[0] &&
reference.identifier.range[1] === node.range[1]);
if (references.length === 1) {
return references[0];
}
return null;
} | javascript | {
"resource": ""
} |
q17941 | isShadowed | train | function isShadowed(scope, node) {
const reference = findReference(scope, node);
return reference && reference.resolved && reference.resolved.defs.length > 0;
} | javascript | {
"resource": ""
} |
q17942 | isGlobalThisReferenceOrGlobalWindow | train | function isGlobalThisReferenceOrGlobalWindow(scope, node) {
if (scope.type === "global" && node.type === "ThisExpression") {
return true;
}
if (node.name === "window") {
return !isShadowed(scope, node);
}
return false;
} | javascript | {
"resource": ""
} |
q17943 | checkRegex | train | function checkRegex(node, value, valueStart) {
const multipleSpacesRegex = /( {2,})( [+*{?]|[^+*{?]|$)/u,
regexResults = multipleSpacesRegex.exec(value);
if (regexResults !== null) {
const count = regexResults[1].length;
context.report({
... | javascript | {
"resource": ""
} |
q17944 | checkLiteral | train | function checkLiteral(node) {
const token = sourceCode.getFirstToken(node),
nodeType = token.type,
nodeValue = token.value;
if (nodeType === "RegularExpression") {
checkRegex(node, nodeValue, token.range[0]);
}
} | javascript | {
"resource": ""
} |
q17945 | isNotNormalMemberAccess | train | function isNotNormalMemberAccess(reference) {
const id = reference.identifier;
const parent = id.parent;
return !(
parent.type === "MemberExpression" &&
parent.object === id &&
!parent.computed
);
} | javascript | {
"resource": ""
} |
q17946 | report | train | function report(reference) {
context.report({
node: reference.identifier,
loc: reference.identifier.loc,
message: "Use the rest parameters instead of 'arguments'."
});
} | javascript | {
"resource": ""
} |
q17947 | checkForArguments | train | function checkForArguments() {
const argumentsVar = getVariableOfArguments(context.getScope());
if (argumentsVar) {
argumentsVar
.references
.filter(isNotNormalMemberAccess)
.forEach(report);
}
} | javascript | {
"resource": ""
} |
q17948 | checkSpacingBefore | train | function checkSpacingBefore(token) {
const prevToken = sourceCode.getTokenBefore(token);
if (prevToken &&
CLOSE_PAREN.test(token.value) &&
astUtils.isTokenOnSameLine(prevToken, token) &&
sourceCode.isSpaceBetweenTokens(prevToken, token) !== always... | javascript | {
"resource": ""
} |
q17949 | findConditionalAncestor | train | function findConditionalAncestor(node) {
let currentAncestor = node;
do {
if (isConditionalTestExpression(currentAncestor)) {
return currentAncestor.parent;
}
} while ((currentAncestor = currentAncestor.parent) && !astUtils.isFunct... | javascript | {
"resource": ""
} |
q17950 | isIdentifier | train | function isIdentifier(name, ecmaVersion) {
if (ecmaVersion >= 6) {
return esutils.keyword.isIdentifierES6(name);
}
return esutils.keyword.isIdentifierES5(name);
} | javascript | {
"resource": ""
} |
q17951 | isPropertyCall | train | function isPropertyCall(objName, funcName, node) {
if (!node) {
return false;
}
return node.type === "CallExpression" &&
node.callee.object.name === objName &&
node.callee.property.name === funcName;
} | javascript | {
"resource": ""
} |
q17952 | normalizeOptions | train | function normalizeOptions(optionValue) {
if (typeof optionValue === "string") {
return {
arrays: optionValue,
objects: optionValue,
imports: optionValue,
exports: optionValue,
// For backward compatibility, always ignore functions.
fun... | javascript | {
"resource": ""
} |
q17953 | getLastItem | train | function getLastItem(node) {
switch (node.type) {
case "ObjectExpression":
case "ObjectPattern":
return lodash.last(node.properties);
case "ArrayExpression":
case "ArrayPattern":
return lodash.last(node.e... | javascript | {
"resource": ""
} |
q17954 | getTrailingToken | train | function getTrailingToken(node, lastItem) {
switch (node.type) {
case "ObjectExpression":
case "ArrayExpression":
case "CallExpression":
case "NewExpression":
return sourceCode.getLastToken(node, 1);
default:... | javascript | {
"resource": ""
} |
q17955 | isMultiline | train | function isMultiline(node) {
const lastItem = getLastItem(node);
if (!lastItem) {
return false;
}
const penultimateToken = getTrailingToken(node, lastItem);
const lastToken = sourceCode.getTokenAfter(penultimateToken);
return las... | javascript | {
"resource": ""
} |
q17956 | forbidTrailingComma | train | function forbidTrailingComma(node) {
const lastItem = getLastItem(node);
if (!lastItem || (node.type === "ImportDeclaration" && lastItem.type !== "ImportSpecifier")) {
return;
}
const trailingToken = getTrailingToken(node, lastItem);
if (ast... | javascript | {
"resource": ""
} |
q17957 | forceTrailingComma | train | function forceTrailingComma(node) {
const lastItem = getLastItem(node);
if (!lastItem || (node.type === "ImportDeclaration" && lastItem.type !== "ImportSpecifier")) {
return;
}
if (!isTrailingCommaAllowed(lastItem)) {
forbidTrailingComma(n... | javascript | {
"resource": ""
} |
q17958 | report | train | function report(node) {
context.report({ node, messageId: "unexpected", data: { operator: node.operator } });
} | javascript | {
"resource": ""
} |
q17959 | isInt32Hint | train | function isInt32Hint(node) {
return int32Hint && node.operator === "|" && node.right &&
node.right.type === "Literal" && node.right.value === 0;
} | javascript | {
"resource": ""
} |
q17960 | checkNodeForBitwiseOperator | train | function checkNodeForBitwiseOperator(node) {
if (hasBitwiseOperator(node) && !allowedOperator(node) && !isInt32Hint(node)) {
report(node);
}
} | javascript | {
"resource": ""
} |
q17961 | translateOptions | train | function translateOptions(cliOptions) {
return {
envs: cliOptions.env,
extensions: cliOptions.ext,
rules: cliOptions.rule,
plugins: cliOptions.plugin,
globals: cliOptions.global,
ignore: cliOptions.ignore,
ignorePath: cliOptions.ignorePath,
ignorePatte... | javascript | {
"resource": ""
} |
q17962 | checkForIf | train | function checkForIf(node) {
return node.type === "IfStatement" && hasElse(node) &&
naiveHasReturn(node.alternate) && naiveHasReturn(node.consequent);
} | javascript | {
"resource": ""
} |
q17963 | alwaysReturns | train | function alwaysReturns(node) {
if (node.type === "BlockStatement") {
// If we have a BlockStatement, check each consequent body node.
return node.body.some(checkForReturnOrIf);
}
/*
* If not a block statement, make sure the consequent is... | javascript | {
"resource": ""
} |
q17964 | checkIfWithoutElse | train | function checkIfWithoutElse(node) {
const parent = node.parent;
/*
* Fixing this would require splitting one statement into two, so no error should
* be reported if this node is in a position where only one statement is allowed.
*/
if (!astUtil... | javascript | {
"resource": ""
} |
q17965 | checkIfWithElse | train | function checkIfWithElse(node) {
const parent = node.parent;
/*
* Fixing this would require splitting one statement into two, so no error should
* be reported if this node is in a position where only one statement is allowed.
*/
if (!astUtils.... | javascript | {
"resource": ""
} |
q17966 | initOptionProperty | train | function initOptionProperty(toOptions, fromOptions) {
toOptions.mode = fromOptions.mode || "strict";
// Set value of beforeColon
if (typeof fromOptions.beforeColon !== "undefined") {
toOptions.beforeColon = +fromOptions.beforeColon;
} else {
toOptions.beforeColon = 0;
}
// Set ... | javascript | {
"resource": ""
} |
q17967 | continuesPropertyGroup | train | function continuesPropertyGroup(lastMember, candidate) {
const groupEndLine = lastMember.loc.start.line,
candidateStartLine = candidate.loc.start.line;
if (candidateStartLine - groupEndLine <= 1) {
return true;
}
/*
* Check t... | javascript | {
"resource": ""
} |
q17968 | isKeyValueProperty | train | function isKeyValueProperty(property) {
return !(
(property.method ||
property.shorthand ||
property.kind !== "init" || property.type !== "Property") // Could be "ExperimentalSpreadProperty" or "SpreadElement"
);
} | javascript | {
"resource": ""
} |
q17969 | getKey | train | function getKey(property) {
const key = property.key;
if (property.computed) {
return sourceCode.getText().slice(key.range[0], key.range[1]);
}
return property.key.name || property.key.value;
} | javascript | {
"resource": ""
} |
q17970 | report | train | function report(property, side, whitespace, expected, mode) {
const diff = whitespace.length - expected,
nextColon = getNextColon(property.key),
tokenBeforeColon = sourceCode.getTokenBefore(nextColon, { includeComments: true }),
tokenAfterColon = sourceCode.ge... | javascript | {
"resource": ""
} |
q17971 | getKeyWidth | train | function getKeyWidth(property) {
const startToken = sourceCode.getFirstToken(property);
const endToken = getLastTokenBeforeColon(property.key);
return endToken.range[1] - startToken.range[0];
} | javascript | {
"resource": ""
} |
q17972 | getPropertyWhitespace | train | function getPropertyWhitespace(property) {
const whitespace = /(\s*):(\s*)/u.exec(sourceCode.getText().slice(
property.key.range[1], property.value.range[0]
));
if (whitespace) {
return {
beforeColon: whitespace[1],
... | javascript | {
"resource": ""
} |
q17973 | createGroups | train | function createGroups(node) {
if (node.properties.length === 1) {
return [node.properties];
}
return node.properties.reduce((groups, property) => {
const currentGroup = last(groups),
prev = last(currentGroup);
if (... | javascript | {
"resource": ""
} |
q17974 | verifyGroupAlignment | train | function verifyGroupAlignment(properties) {
const length = properties.length,
widths = properties.map(getKeyWidth), // Width of keys, including quotes
align = alignmentOptions.on; // "value" or "colon"
let targetWidth = Math.max(...widths),
beforeC... | javascript | {
"resource": ""
} |
q17975 | verifyAlignment | train | function verifyAlignment(node) {
createGroups(node).forEach(group => {
verifyGroupAlignment(group.filter(isKeyValueProperty));
});
} | javascript | {
"resource": ""
} |
q17976 | verifySpacing | train | function verifySpacing(node, lineOptions) {
const actual = getPropertyWhitespace(node);
if (actual) { // Object literal getters/setters lack colons
report(node, "key", actual.beforeColon, lineOptions.beforeColon, lineOptions.mode);
report(node, "value", actual.af... | javascript | {
"resource": ""
} |
q17977 | verifyListSpacing | train | function verifyListSpacing(properties) {
const length = properties.length;
for (let i = 0; i < length; i++) {
verifySpacing(properties[i], singleLineOptions);
}
} | javascript | {
"resource": ""
} |
q17978 | isMultiplyByOne | train | function isMultiplyByOne(node) {
return node.operator === "*" && (
node.left.type === "Literal" && node.left.value === 1 ||
node.right.type === "Literal" && node.right.value === 1
);
} | javascript | {
"resource": ""
} |
q17979 | isNumeric | train | function isNumeric(node) {
return (
node.type === "Literal" && typeof node.value === "number" ||
node.type === "CallExpression" && (
node.callee.name === "Number" ||
node.callee.name === "parseInt" ||
node.callee.name === "parseFloat"
)
);
} | javascript | {
"resource": ""
} |
q17980 | getNonNumericOperand | train | function getNonNumericOperand(node) {
const left = node.left,
right = node.right;
if (right.type !== "BinaryExpression" && !isNumeric(right)) {
return right;
}
if (left.type !== "BinaryExpression" && !isNumeric(left)) {
return left;
}
return null;
} | javascript | {
"resource": ""
} |
q17981 | isEmptyString | train | function isEmptyString(node) {
return astUtils.isStringLiteral(node) && (node.value === "" || (node.type === "TemplateLiteral" && node.quasis.length === 1 && node.quasis[0].value.cooked === ""));
} | javascript | {
"resource": ""
} |
q17982 | report | train | function report(node, recommendation, shouldFix) {
context.report({
node,
message: "use `{{recommendation}}` instead.",
data: {
recommendation
},
fix(fixer) {
if (!shouldFix) {
... | javascript | {
"resource": ""
} |
q17983 | startBlock | train | function startBlock() {
blockStack.push({
let: { initialized: false, uninitialized: false },
const: { initialized: false, uninitialized: false }
});
} | javascript | {
"resource": ""
} |
q17984 | isRequire | train | function isRequire(decl) {
return decl.init && decl.init.type === "CallExpression" && decl.init.callee.name === "require";
} | javascript | {
"resource": ""
} |
q17985 | countDeclarations | train | function countDeclarations(declarations) {
const counts = { uninitialized: 0, initialized: 0 };
for (let i = 0; i < declarations.length; i++) {
if (declarations[i].init === null) {
counts.uninitialized++;
} else {
counts.in... | javascript | {
"resource": ""
} |
q17986 | hasOnlyOneStatement | train | function hasOnlyOneStatement(statementType, declarations) {
const declarationCounts = countDeclarations(declarations);
const currentOptions = options[statementType] || {};
const currentScope = getCurrentScope(statementType);
const hasRequires = declarations.some(isRequir... | javascript | {
"resource": ""
} |
q17987 | joinDeclarations | train | function joinDeclarations(declarations) {
const declaration = declarations[0];
const body = Array.isArray(declaration.parent.parent.body) ? declaration.parent.parent.body : [];
const currentIndex = body.findIndex(node => node.range[0] === declaration.parent.range[0]);
con... | javascript | {
"resource": ""
} |
q17988 | splitDeclarations | train | function splitDeclarations(declaration) {
return fixer => declaration.declarations.map(declarator => {
const tokenAfterDeclarator = sourceCode.getTokenAfter(declarator);
if (tokenAfterDeclarator === null) {
return null;
}
... | javascript | {
"resource": ""
} |
q17989 | getScope | train | function getScope(identifier) {
for (let currentNode = identifier; currentNode; currentNode = currentNode.parent) {
const scope = sourceCode.scopeManager.acquire(currentNode, true);
if (scope) {
return scope;
}
}
re... | javascript | {
"resource": ""
} |
q17990 | resolveVariableInScope | train | function resolveVariableInScope(identifier, scope) {
return scope.variables.find(variable => variable.name === identifier.name) ||
(scope.upper ? resolveVariableInScope(identifier, scope.upper) : null);
} | javascript | {
"resource": ""
} |
q17991 | resolveVariable | train | function resolveVariable(identifier) {
if (!resolvedVariableCache.has(identifier)) {
const surroundingScope = getScope(identifier);
if (surroundingScope) {
resolvedVariableCache.set(identifier, resolveVariableInScope(identifier, surroundingScope));
... | javascript | {
"resource": ""
} |
q17992 | isLocalVariableWithoutEscape | train | function isLocalVariableWithoutEscape(expression, surroundingFunction) {
if (expression.type !== "Identifier") {
return false;
}
const variable = resolveVariable(expression);
if (!variable) {
return false;
}
retur... | javascript | {
"resource": ""
} |
q17993 | reportAssignment | train | function reportAssignment(assignmentExpression) {
context.report({
node: assignmentExpression,
messageId: "nonAtomicUpdate",
data: {
value: sourceCode.getText(assignmentExpression.left)
}
});
} | javascript | {
"resource": ""
} |
q17994 | validateRuleSeverity | train | function validateRuleSeverity(options) {
const severity = Array.isArray(options) ? options[0] : options;
const normSeverity = typeof severity === "string" ? severityMap[severity.toLowerCase()] : severity;
if (normSeverity === 0 || normSeverity === 1 || normSeverity === 2) {
return normSeverity;
... | javascript | {
"resource": ""
} |
q17995 | validateRuleSchema | train | function validateRuleSchema(rule, localOptions) {
if (!ruleValidators.has(rule)) {
const schema = getRuleOptionsSchema(rule);
if (schema) {
ruleValidators.set(rule, ajv.compile(schema));
}
}
const validateRule = ruleValidators.get(rule);
if (validateRule) {
... | javascript | {
"resource": ""
} |
q17996 | validateRules | train | function validateRules(rulesConfig, ruleMapper, source = null) {
if (!rulesConfig) {
return;
}
Object.keys(rulesConfig).forEach(id => {
validateRuleOptions(ruleMapper(id), id, rulesConfig[id], source);
});
} | javascript | {
"resource": ""
} |
q17997 | validateGlobals | train | function validateGlobals(globalsConfig, source = null) {
if (!globalsConfig) {
return;
}
Object.entries(globalsConfig)
.forEach(([configuredGlobal, configuredValue]) => {
try {
ConfigOps.normalizeConfigGlobal(configuredValue);
} catch (err) {
... | javascript | {
"resource": ""
} |
q17998 | formatErrors | train | function formatErrors(errors) {
return errors.map(error => {
if (error.keyword === "additionalProperties") {
const formattedPropertyPath = error.dataPath.length ? `${error.dataPath.slice(1)}.${error.params.additionalProperty}` : error.params.additionalProperty;
return `Unexpected to... | javascript | {
"resource": ""
} |
q17999 | validateConfigSchema | train | function validateConfigSchema(config, source = null) {
validateSchema = validateSchema || ajv.compile(configSchema);
if (!validateSchema(config)) {
throw new Error(`ESLint configuration in ${source} is invalid:\n${formatErrors(validateSchema.errors)}`);
}
if (Object.hasOwnProperty.call(config,... | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.