_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
27
233k
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,
javascript
{ "resource": "" }
q17902
getAdjacentCommentTokensFromCursor
train
function getAdjacentCommentTokensFromCursor(cursor) { const tokens = []; let currentToken = cursor.getOneToken(); while (currentToken && astUtils.isCommentToken(currentToken)) {
javascript
{ "resource": "" }
q17903
hasLeadingSpace
train
function hasLeadingSpace(token) { const tokenBefore = sourceCode.getTokenBefore(token);
javascript
{ "resource": "" }
q17904
hasTrailingSpace
train
function hasTrailingSpace(token) { const tokenAfter = sourceCode.getTokenAfter(token);
javascript
{ "resource": "" }
q17905
isLastTokenInCurrentLine
train
function isLastTokenInCurrentLine(token) { const tokenAfter = sourceCode.getTokenAfter(token);
javascript
{ "resource": "" }
q17906
isFirstTokenInCurrentLine
train
function isFirstTokenInCurrentLine(token) { const tokenBefore = sourceCode.getTokenBefore(token);
javascript
{ "resource": "" }
q17907
isBeforeClosingParen
train
function isBeforeClosingParen(token) { const nextToken = sourceCode.getTokenAfter(token);
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 !==
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) {
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() ||
javascript
{ "resource": "" }
q17913
getUpperFunction
train
function getUpperFunction(node) { for (let currentNode = node; currentNode; currentNode = currentNode.parent) {
javascript
{ "resource": "" }
q17914
isInLoop
train
function isInLoop(node) { for (let currentNode = node; currentNode && !isFunction(currentNode); currentNode = currentNode.parent) {
javascript
{ "resource": "" }
q17915
isMethodWhichHasThisArg
train
function isMethodWhichHasThisArg(node) { for ( let currentNode = node; currentNode.type === "MemberExpression" && !currentNode.computed; currentNode = currentNode.property ) {
javascript
{ "resource": "" }
q17916
getOpeningParenOfParams
train
function getOpeningParenOfParams(node, sourceCode) { return node.id ? sourceCode.getTokenAfter(node.id, 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) {
javascript
{ "resource": "" }
q17918
combineArrays
train
function combineArrays(arr1, arr2) { const res = []; if (arr1.length === 0) { return explodeArray(arr2); } if (arr2.length ===
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];
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 :
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({
javascript
{ "resource": "" }
q17925
endFunction
train
function endFunction(node) { const count = functionStack.pop(); if (ignoreTopLevelFunctions && functionStack.length === 0) { topLevelFunctions.push({ node, count }); }
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,
javascript
{ "resource": "" }
q17929
getLastTokenOnLine
train
function getLastTokenOnLine(node) { const lastToken = sourceCode.getLastToken(node); const secondToLastToken = sourceCode.getTokenBefore(lastToken);
javascript
{ "resource": "" }
q17930
hasNewlineAfter
train
function hasNewlineAfter(node) { const lastToken = getLastTokenOnLine(node); const tokenAfter = sourceCode.getTokenAfter(lastToken, { includeComments: true });
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
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 -
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) ||
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]);
javascript
{ "resource": "" }
q17941
isShadowed
train
function isShadowed(scope, node) { const reference = findReference(scope, node); return reference &&
javascript
{ "resource": "" }
q17942
isGlobalThisReferenceOrGlobalWindow
train
function isGlobalThisReferenceOrGlobalWindow(scope, node) { if (scope.type === "global" && node.type === "ThisExpression") { return true; }
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,
javascript
{ "resource": "" }
q17945
isNotNormalMemberAccess
train
function isNotNormalMemberAccess(reference) { const id = reference.identifier; const parent = id.parent; return !( parent.type
javascript
{ "resource": "" }
q17946
report
train
function report(reference) { context.report({ node: reference.identifier,
javascript
{ "resource": "" }
q17947
checkForArguments
train
function checkForArguments() { const argumentsVar = getVariableOfArguments(context.getScope()); if (argumentsVar) { argumentsVar
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;
javascript
{ "resource": "" }
q17950
isIdentifier
train
function isIdentifier(name, ecmaVersion) { if (ecmaVersion >= 6) { return esutils.keyword.isIdentifierES6(name);
javascript
{ "resource": "" }
q17951
isPropertyCall
train
function isPropertyCall(objName, funcName, node) { if (!node) { return false; }
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":
javascript
{ "resource": "" }
q17955
isMultiline
train
function isMultiline(node) { const lastItem = getLastItem(node); if (!lastItem) { return false; } const penultimateToken = getTrailingToken(node, lastItem);
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:
javascript
{ "resource": "" }
q17959
isInt32Hint
train
function isInt32Hint(node) { return int32Hint && node.operator === "|" && node.right &&
javascript
{ "resource": "" }
q17960
checkNodeForBitwiseOperator
train
function checkNodeForBitwiseOperator(node) { if (hasBitwiseOperator(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) &&
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); } /*
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
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
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]);
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);
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]
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),
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 => {
javascript
{ "resource": "" }
q17976
verifySpacing
train
function verifySpacing(node, lineOptions) { const actual = getPropertyWhitespace(node); if (actual) { // Object literal getters/setters lack colons
javascript
{ "resource": "" }
q17977
verifyListSpacing
train
function verifyListSpacing(properties) { const length = properties.length; for (let i = 0; i < length; i++) {
javascript
{ "resource": "" }
q17978
isMultiplyByOne
train
function isMultiplyByOne(node) { return node.operator === "*" && ( node.left.type ===
javascript
{ "resource": "" }
q17979
isNumeric
train
function isNumeric(node) { return ( node.type === "Literal" && typeof node.value === "number" || node.type === "CallExpression"
javascript
{ "resource": "" }
q17980
getNonNumericOperand
train
function getNonNumericOperand(node) { const left = node.left, right = node.right; if (right.type !== "BinaryExpression" && !isNumeric(right)) { return right; }
javascript
{ "resource": "" }
q17981
isEmptyString
train
function isEmptyString(node) { return astUtils.isStringLiteral(node) && (node.value
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 },
javascript
{ "resource": "" }
q17984
isRequire
train
function isRequire(decl) { return decl.init && decl.init.type === "CallExpression" &&
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) {
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) {
javascript
{ "resource": "" }
q17990
resolveVariableInScope
train
function resolveVariableInScope(identifier, scope) { return scope.variables.find(variable => variable.name === identifier.name) ||
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;
javascript
{ "resource": "" }
q17993
reportAssignment
train
function reportAssignment(assignmentExpression) { context.report({ node: assignmentExpression, messageId: "nonAtomicUpdate", data: {
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 => {
javascript
{ "resource": "" }
q17997
validateGlobals
train
function validateGlobals(globalsConfig, source = null) { if (!globalsConfig) { return; } Object.entries(globalsConfig) .forEach(([configuredGlobal, configuredValue]) => {
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
javascript
{ "resource": "" }