_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q18100 | convertToStarredBlock | train | function convertToStarredBlock(firstComment, commentLinesList) {
const initialOffset = sourceCode.text.slice(firstComment.range[0] - firstComment.loc.start.column, firstComment.range[0]);
const starredLines = commentLinesList.map(line => `${initialOffset} *${line}`);
return `\n${sta... | javascript | {
"resource": ""
} |
q18101 | convertToSeparateLines | train | function convertToSeparateLines(firstComment, commentLinesList) {
const initialOffset = sourceCode.text.slice(firstComment.range[0] - firstComment.loc.start.column, firstComment.range[0]);
const separateLines = commentLinesList.map(line => `// ${line.trim()}`);
return separateLines.... | javascript | {
"resource": ""
} |
q18102 | convertToBlock | train | function convertToBlock(firstComment, commentLinesList) {
const initialOffset = sourceCode.text.slice(firstComment.range[0] - firstComment.loc.start.column, firstComment.range[0]);
const blockLines = commentLinesList.map(line => line.trim());
return `/* ${blockLines.join(`\n${initia... | javascript | {
"resource": ""
} |
q18103 | isJSDoc | train | function isJSDoc(commentGroup) {
const lines = commentGroup[0].value.split(astUtils.LINEBREAK_MATCHER);
return commentGroup[0].type === "Block" &&
/^\*\s*$/u.test(lines[0]) &&
lines.slice(1, -1).every(line => /^\s* /u.test(line)) &&
/^\s*$/u.test(... | javascript | {
"resource": ""
} |
q18104 | isIdentifierReference | train | function isIdentifierReference(node) {
const parent = node.parent;
switch (parent.type) {
case "LabeledStatement":
case "BreakStatement":
case "ContinueStatement":
case "ArrayPattern":
case "RestElement":
case "ImportSpecifier":
case "ImportDefaultSpecifi... | javascript | {
"resource": ""
} |
q18105 | leaveFromCurrentSegment | train | function leaveFromCurrentSegment(analyzer, node) {
const state = CodePath.getState(analyzer.codePath);
const currentSegments = state.currentSegments;
for (let i = 0; i < currentSegments.length; ++i) {
const currentSegment = currentSegments[i];
debug.dump(`onCodePathSegmentEnd ${currentSegm... | javascript | {
"resource": ""
} |
q18106 | preprocess | train | function preprocess(analyzer, node) {
const codePath = analyzer.codePath;
const state = CodePath.getState(codePath);
const parent = node.parent;
switch (parent.type) {
case "LogicalExpression":
if (
parent.right === node &&
isHandledLogicalOperator(pa... | javascript | {
"resource": ""
} |
q18107 | processCodePathToEnter | train | function processCodePathToEnter(analyzer, node) {
let codePath = analyzer.codePath;
let state = codePath && CodePath.getState(codePath);
const parent = node.parent;
switch (node.type) {
case "Program":
case "FunctionDeclaration":
case "FunctionExpression":
case "ArrowFun... | javascript | {
"resource": ""
} |
q18108 | processCodePathToExit | train | function processCodePathToExit(analyzer, node) {
const codePath = analyzer.codePath;
const state = CodePath.getState(codePath);
let dontForward = false;
switch (node.type) {
case "IfStatement":
case "ConditionalExpression":
state.popChoiceContext();
break;
... | javascript | {
"resource": ""
} |
q18109 | getOperatorToken | train | function getOperatorToken(node) {
return sourceCode.getFirstTokenBetween(node.left, node.right, token => token.value === node.operator);
} | javascript | {
"resource": ""
} |
q18110 | verify | train | function verify(node) {
if (node.operator !== "=" || node.right.type !== "BinaryExpression") {
return;
}
const left = node.left;
const expr = node.right;
const operator = expr.operator;
if (isCommutativeOperatorWithShorthand(opera... | javascript | {
"resource": ""
} |
q18111 | prohibit | train | function prohibit(node) {
if (node.operator !== "=") {
context.report({
node,
messageId: "unexpected",
fix(fixer) {
if (canBeFixed(node.left)) {
const operatorToken = getOperatorTo... | javascript | {
"resource": ""
} |
q18112 | validateArguments | train | function validateArguments(parens, elements) {
const leftParen = parens.leftParen;
const tokenAfterLeftParen = sourceCode.getTokenAfter(leftParen);
const hasLeftNewline = !astUtils.isTokenOnSameLine(leftParen, tokenAfterLeftParen);
const needsNewlines = shouldHaveNewlines... | javascript | {
"resource": ""
} |
q18113 | getParenTokens | train | function getParenTokens(node) {
switch (node.type) {
case "NewExpression":
if (!node.arguments.length && !(
astUtils.isOpeningParenToken(sourceCode.getLastToken(node, { skip: 1 })) &&
astUtils.isClosingParenToken(sourceCode.... | javascript | {
"resource": ""
} |
q18114 | validateNode | train | function validateNode(node) {
const parens = getParenTokens(node);
if (parens) {
validateParens(parens, astUtils.isFunction(node) ? node.params : node.arguments);
if (multilineArgumentsOption) {
validateArguments(parens, astUtils.isFunction(n... | javascript | {
"resource": ""
} |
q18115 | getDefinedMessage | train | function getDefinedMessage(unusedVar) {
const defType = unusedVar.defs && unusedVar.defs[0] && unusedVar.defs[0].type;
let type;
let pattern;
if (defType === "CatchClause" && config.caughtErrorsIgnorePattern) {
type = "args";
pattern = con... | javascript | {
"resource": ""
} |
q18116 | hasRestSpreadSibling | train | function hasRestSpreadSibling(variable) {
if (config.ignoreRestSiblings) {
return variable.defs.some(def => {
const propertyNode = def.name.parent;
const patternNode = propertyNode.parent;
return (
propertyN... | javascript | {
"resource": ""
} |
q18117 | isSelfReference | train | function isSelfReference(ref, nodes) {
let scope = ref.from;
while (scope) {
if (nodes.indexOf(scope.block) >= 0) {
return true;
}
scope = scope.upper;
}
return false;
} | javascript | {
"resource": ""
} |
q18118 | getFunctionDefinitions | train | function getFunctionDefinitions(variable) {
const functionDefinitions = [];
variable.defs.forEach(def => {
const { type, node } = def;
// FunctionDeclarations
if (type === "FunctionName") {
functionDefinitions.push(node);
... | javascript | {
"resource": ""
} |
q18119 | isInside | train | function isInside(inner, outer) {
return (
inner.range[0] >= outer.range[0] &&
inner.range[1] <= outer.range[1]
);
} | javascript | {
"resource": ""
} |
q18120 | getRhsNode | train | function getRhsNode(ref, prevRhsNode) {
const id = ref.identifier;
const parent = id.parent;
const granpa = parent.parent;
const refScope = ref.from.variableScope;
const varScope = ref.resolved.scope.variableScope;
const canBeUsedLater = refScope !... | javascript | {
"resource": ""
} |
q18121 | isReadForItself | train | function isReadForItself(ref, rhsNode) {
const id = ref.identifier;
const parent = id.parent;
const granpa = parent.parent;
return ref.isRead() && (
// self update. e.g. `a += 1`, `a++`
(// in RHS of an assignment for itself. e.g. `a = a ... | javascript | {
"resource": ""
} |
q18122 | isForInRef | train | function isForInRef(ref) {
let target = ref.identifier.parent;
// "for (var ...) { return; }"
if (target.type === "VariableDeclarator") {
target = target.parent.parent;
}
if (target.type !== "ForInStatement") {
return false;
... | javascript | {
"resource": ""
} |
q18123 | isAfterLastUsedArg | train | function isAfterLastUsedArg(variable) {
const def = variable.defs[0];
const params = context.getDeclaredVariables(def.node);
const posteriorParams = params.slice(params.indexOf(variable) + 1);
// If any used parameters occur after this parameter, do not report.
... | javascript | {
"resource": ""
} |
q18124 | report | train | function report(node, loc, otherNode) {
context.report({
node,
fix(fixer) {
if (options[loc]) {
if (loc === "before") {
return fixer.insertTextBefore(node, " ");
}
... | javascript | {
"resource": ""
} |
q18125 | validateCommaItemSpacing | train | function validateCommaItemSpacing(tokens, reportItem) {
if (tokens.left && astUtils.isTokenOnSameLine(tokens.left, tokens.comma) &&
(options.before !== sourceCode.isSpaceBetweenTokens(tokens.left, tokens.comma))
) {
report(reportItem, "before", tokens.left);
... | javascript | {
"resource": ""
} |
q18126 | addNullElementsToIgnoreList | train | function addNullElementsToIgnoreList(node) {
let previousToken = sourceCode.getFirstToken(node);
node.elements.forEach(element => {
let token;
if (element === null) {
token = sourceCode.getTokenAfter(previousToken);
if (a... | javascript | {
"resource": ""
} |
q18127 | getEnclosingFunctionScope | train | function getEnclosingFunctionScope(scope) {
let currentScope = scope;
while (currentScope.type !== "function" && currentScope.type !== "global") {
currentScope = currentScope.upper;
}
return currentScope;
} | javascript | {
"resource": ""
} |
q18128 | isLoopAssignee | train | function isLoopAssignee(node) {
return (node.parent.type === "ForOfStatement" || node.parent.type === "ForInStatement") &&
node === node.parent.left;
} | javascript | {
"resource": ""
} |
q18129 | getScopeNode | train | function getScopeNode(node) {
for (let currentNode = node; currentNode; currentNode = currentNode.parent) {
if (SCOPE_NODE_TYPE.test(currentNode.type)) {
return currentNode;
}
}
/* istanbul ignore next : unreachable */
return null;
} | javascript | {
"resource": ""
} |
q18130 | isUsedFromOutsideOf | train | function isUsedFromOutsideOf(scopeNode) {
/**
* Checks whether a given reference is inside of the specified scope or not.
*
* @param {eslint-scope.Reference} reference - A reference to check.
* @returns {boolean} `true` if the reference is inside of the specified
* scope.
*/
... | javascript | {
"resource": ""
} |
q18131 | isOutsideOfScope | train | function isOutsideOfScope(reference) {
const scope = scopeNode.range;
const id = reference.identifier.range;
return id[0] < scope[0] || id[1] > scope[1];
} | javascript | {
"resource": ""
} |
q18132 | hasReferenceInTDZ | train | function hasReferenceInTDZ(node) {
const initStart = node.range[0];
const initEnd = node.range[1];
return variable => {
const id = variable.defs[0].name;
const idStart = id.range[0];
const defaultValue = (id.parent.type === "AssignmentPattern" ? id.parent.right : null);
cons... | javascript | {
"resource": ""
} |
q18133 | hasSelfReferenceInTDZ | train | function hasSelfReferenceInTDZ(declarator) {
if (!declarator.init) {
return false;
}
const variables = context.getDeclaredVariables(declarator);
return variables.some(hasReferenceInTDZ(declarator.init));
} | javascript | {
"resource": ""
} |
q18134 | report | train | function report(node) {
context.report({
node,
message: "Unexpected var, use let or const instead.",
fix(fixer) {
const varToken = sourceCode.getFirstToken(node, { filter: t => t.value === "var" });
return canFix(node)... | javascript | {
"resource": ""
} |
q18135 | checkArrowFunc | train | function checkArrowFunc(node) {
const body = node.body;
if (isConditional(body) && !(allowParens && astUtils.isParenthesised(sourceCode, body))) {
context.report({
node,
messageId: "confusing",
fix(fixer) {
... | javascript | {
"resource": ""
} |
q18136 | checkFunction | train | function checkFunction(node) {
const parent = node.parent;
if (parent.type === "CallExpression") {
callbackStack.push(node);
}
if (callbackStack.length > THRESHOLD) {
const opts = { num: callbackStack.length, max: THRESHOLD };
... | javascript | {
"resource": ""
} |
q18137 | isInitialized | train | function isInitialized(node) {
const declaration = node.parent;
const block = declaration.parent;
if (isForLoop(block)) {
if (block.type === "ForStatement") {
return block.init === declaration;
}
return block.left === declaration;
}
return Boolean(node.init);
} | javascript | {
"resource": ""
} |
q18138 | checkArray | train | function checkArray(obj, key, fallback) {
/* istanbul ignore if */
if (Object.prototype.hasOwnProperty.call(obj, key) && !Array.isArray(obj[key])) {
throw new TypeError(`${key}, if provided, must be an Array`);
}
return obj[key] || fallback;
} | javascript | {
"resource": ""
} |
q18139 | calculateCapIsNewExceptions | train | function calculateCapIsNewExceptions(config) {
let capIsNewExceptions = checkArray(config, "capIsNewExceptions", CAPS_ALLOWED);
if (capIsNewExceptions !== CAPS_ALLOWED) {
capIsNewExceptions = capIsNewExceptions.concat(CAPS_ALLOWED);
}
return capIsNewExceptions.reduce(invert, {});
} | javascript | {
"resource": ""
} |
q18140 | getCap | train | function getCap(str) {
const firstChar = str.charAt(0);
const firstCharLower = firstChar.toLowerCase();
const firstCharUpper = firstChar.toUpperCase();
if (firstCharLower === firstCharUpper) {
// char has no uppercase variant, so it's non-alphabetic
... | javascript | {
"resource": ""
} |
q18141 | isCapAllowed | train | function isCapAllowed(allowedMap, node, calleeName, pattern) {
const sourceText = sourceCode.getText(node.callee);
if (allowedMap[calleeName] || allowedMap[sourceText]) {
return true;
}
if (pattern && pattern.test(sourceText)) {
return tr... | javascript | {
"resource": ""
} |
q18142 | report | train | function report(node, messageId) {
let callee = node.callee;
if (callee.type === "MemberExpression") {
callee = callee.property;
}
context.report({ node, loc: callee.loc.start, messageId });
} | javascript | {
"resource": ""
} |
q18143 | getVisitorKeys | train | function getVisitorKeys(visitorKeys, node) {
let keys = visitorKeys[node.type];
if (!keys) {
keys = vk.getKeys(node);
debug("Unknown node type \"%s\": Estimated visitor keys %j", node.type, keys);
}
return keys;
} | javascript | {
"resource": ""
} |
q18144 | looksLikeLiteral | train | function looksLikeLiteral(node) {
return (node.type === "UnaryExpression" &&
node.operator === "-" &&
node.prefix &&
node.argument.type === "Literal" &&
typeof node.argument.value === "number");
} | javascript | {
"resource": ""
} |
q18145 | report | train | function report(node, existing, substitute) {
context.report({
node,
message: "Avoid using {{existing}}, instead use {{substitute}}.",
data: {
existing,
substitute
}
});
} | javascript | {
"resource": ""
} |
q18146 | checkRegex | train | function checkRegex(regex, node, uFlag) {
let ast;
try {
ast = parser.parsePattern(regex, 0, regex.length, uFlag);
} catch (_) {
// ignore regex syntax errors
return;
}
regexpp.visitRegExpAST(ast, {
... | javascript | {
"resource": ""
} |
q18147 | normalizeDirectoryEntries | train | function normalizeDirectoryEntries(entries, directory, supportedConfigs) {
const fileHash = {};
entries.forEach(entry => {
if (supportedConfigs.indexOf(entry) >= 0) {
const resolvedEntry = path.resolve(directory, entry);
if (fs.statSync(resolvedEntry).isFile()) {
... | javascript | {
"resource": ""
} |
q18148 | getKind | train | function getKind(node) {
const parent = node.parent;
let kind = "";
if (node.type === "ArrowFunctionExpression") {
return "arrowFunctions";
}
// Detects main kind.
if (parent.type === "Property") {
if (parent.kind === "get") {
return "getters";
}
if ... | javascript | {
"resource": ""
} |
q18149 | reportIfEmpty | train | function reportIfEmpty(node) {
const kind = getKind(node);
const name = astUtils.getFunctionNameWithKind(node);
const innerComments = sourceCode.getTokens(node.body, {
includeComments: true,
filter: astUtils.isCommentToken
});
... | javascript | {
"resource": ""
} |
q18150 | enterLabeledScope | train | function enterLabeledScope(node) {
scopeInfo = {
label: node.label.name,
used: false,
upper: scopeInfo
};
} | javascript | {
"resource": ""
} |
q18151 | exitLabeledScope | train | function exitLabeledScope(node) {
if (!scopeInfo.used) {
context.report({
node: node.label,
messageId: "unused",
data: node.label,
fix(fixer) {
/*
* Only perform ... | javascript | {
"resource": ""
} |
q18152 | markAsUsed | train | function markAsUsed(node) {
if (!node.label) {
return;
}
const label = node.label.name;
let info = scopeInfo;
while (info) {
if (info.label === label) {
info.used = true;
break;
... | javascript | {
"resource": ""
} |
q18153 | isIIFEStatement | train | function isIIFEStatement(node) {
if (node.type === "ExpressionStatement") {
let call = node.expression;
if (call.type === "UnaryExpression") {
call = call.argument;
}
return call.type === "CallExpression" && astUtils.isFunction(call.callee);
}
return false;
} | javascript | {
"resource": ""
} |
q18154 | isBlockLikeStatement | train | function isBlockLikeStatement(sourceCode, node) {
// do-while with a block is a block-like statement.
if (node.type === "DoWhileStatement" && node.body.type === "BlockStatement") {
return true;
}
/*
* IIFE is a block-like statement specially from
* JSCS#disallowPaddingNewLinesAfterBl... | javascript | {
"resource": ""
} |
q18155 | isDirective | train | function isDirective(node, sourceCode) {
return (
node.type === "ExpressionStatement" &&
(
node.parent.type === "Program" ||
(
node.parent.type === "BlockStatement" &&
astUtils.isFunction(node.parent.parent)
)
) &&
n... | javascript | {
"resource": ""
} |
q18156 | isDirectivePrologue | train | function isDirectivePrologue(node, sourceCode) {
if (isDirective(node, sourceCode)) {
for (const sibling of node.parent.body) {
if (sibling === node) {
break;
}
if (!isDirective(sibling, sourceCode)) {
return false;
}
}
... | javascript | {
"resource": ""
} |
q18157 | getActualLastToken | train | function getActualLastToken(sourceCode, node) {
const semiToken = sourceCode.getLastToken(node);
const prevToken = sourceCode.getTokenBefore(semiToken);
const nextToken = sourceCode.getTokenAfter(semiToken);
const isSemicolonLessStyle = Boolean(
prevToken &&
nextToken &&
prevToke... | javascript | {
"resource": ""
} |
q18158 | verifyForNever | train | function verifyForNever(context, _, nextNode, paddingLines) {
if (paddingLines.length === 0) {
return;
}
context.report({
node: nextNode,
message: "Unexpected blank line before this statement.",
fix(fixer) {
if (paddingLines.length >= 2) {
return ... | javascript | {
"resource": ""
} |
q18159 | verifyForAlways | train | function verifyForAlways(context, prevNode, nextNode, paddingLines) {
if (paddingLines.length > 0) {
return;
}
context.report({
node: nextNode,
message: "Expected blank line before this statement.",
fix(fixer) {
const sourceCode = context.getSourceCode();
... | javascript | {
"resource": ""
} |
q18160 | match | train | function match(node, type) {
let innerStatementNode = node;
while (innerStatementNode.type === "LabeledStatement") {
innerStatementNode = innerStatementNode.body;
}
if (Array.isArray(type)) {
return type.some(match.bind(null, innerStatemen... | javascript | {
"resource": ""
} |
q18161 | getPaddingType | train | function getPaddingType(prevNode, nextNode) {
for (let i = configureList.length - 1; i >= 0; --i) {
const configure = configureList[i];
const matched =
match(prevNode, configure.prev) &&
match(nextNode, configure.next);
... | javascript | {
"resource": ""
} |
q18162 | getPaddingLineSequences | train | function getPaddingLineSequences(prevNode, nextNode) {
const pairs = [];
let prevToken = getActualLastToken(sourceCode, prevNode);
if (nextNode.loc.start.line - prevToken.loc.end.line >= 2) {
do {
const token = sourceCode.getTokenAfter(
... | javascript | {
"resource": ""
} |
q18163 | verify | train | function verify(node) {
const parentType = node.parent.type;
const validParent =
astUtils.STATEMENT_LIST_PARENTS.has(parentType) ||
parentType === "SwitchStatement";
if (!validParent) {
return;
}
// Save this n... | javascript | {
"resource": ""
} |
q18164 | checkDotLocation | train | function checkDotLocation(obj, prop, node) {
const dot = sourceCode.getTokenBefore(prop);
const textBeforeDot = sourceCode.getText().slice(obj.range[1], dot.range[0]);
const textAfterDot = sourceCode.getText().slice(dot.range[1], prop.range[0]);
if (dot.type === "Punctua... | javascript | {
"resource": ""
} |
q18165 | validateStatement | train | function validateStatement(node, keywordName) {
const option = getOption(keywordName);
if (node.type === "BlockStatement" || option === "any") {
return;
}
const tokenBefore = sourceCode.getTokenBefore(node);
if (tokenBefore.loc.end.line === ... | javascript | {
"resource": ""
} |
q18166 | compareMessagesByFixRange | train | function compareMessagesByFixRange(a, b) {
return a.fix.range[0] - b.fix.range[0] || a.fix.range[1] - b.fix.range[1];
} | javascript | {
"resource": ""
} |
q18167 | attemptFix | train | function attemptFix(problem) {
const fix = problem.fix;
const start = fix.range[0];
const end = fix.range[1];
// Remain it as a problem if it's overlapped or it's a negative range
if (lastPos >= start || start > end) {
remainingMessages.push(problem);
ret... | javascript | {
"resource": ""
} |
q18168 | looksLikeExport | train | function looksLikeExport(astNode) {
return astNode.type === "ExportDefaultDeclaration" || astNode.type === "ExportNamedDeclaration" ||
astNode.type === "ExportAllDeclaration" || astNode.type === "ExportSpecifier";
} | javascript | {
"resource": ""
} |
q18169 | getCommentLineNumbers | train | function getCommentLineNumbers(comments) {
const lines = new Set();
comments.forEach(comment => {
for (let i = comment.loc.start.line; i <= comment.loc.end.line; i++) {
lines.add(i);
}
});
return lines;
} | javascript | {
"resource": ""
} |
q18170 | isOuterVariable | train | function isOuterVariable(variable, reference) {
return (
variable.defs[0].type === "Variable" &&
variable.scope.variableScope !== reference.from.variableScope
);
} | javascript | {
"resource": ""
} |
q18171 | isInRange | train | function isInRange(node, location) {
return node && node.range[0] <= location && location <= node.range[1];
} | javascript | {
"resource": ""
} |
q18172 | isInInitializer | train | function isInInitializer(variable, reference) {
if (variable.scope !== reference.from) {
return false;
}
let node = variable.identifiers[0].parent;
const location = reference.identifier.range[1];
while (node) {
if (node.type === "VariableDeclarator") {
if (isInRange(nod... | javascript | {
"resource": ""
} |
q18173 | findVariablesInScope | train | function findVariablesInScope(scope) {
scope.references.forEach(reference => {
const variable = reference.resolved;
/*
* Skips when the reference is:
* - initialization's.
* - referring to an undefined variable.
... | javascript | {
"resource": ""
} |
q18174 | isLastChild | train | function isLastChild(node) {
const t = node.parent.type;
if (t === "IfStatement" && node.parent.consequent === node && node.parent.alternate) { // before `else` keyword.
return true;
}
if (t === "DoWhileStatement") { // before `while` keyword.
return true;
}
const nodeList = get... | javascript | {
"resource": ""
} |
q18175 | check | train | function check(semiToken, expected) {
const prevToken = sourceCode.getTokenBefore(semiToken);
const nextToken = sourceCode.getTokenAfter(semiToken);
const prevIsSameLine = !prevToken || astUtils.isTokenOnSameLine(prevToken, semiToken);
const nextIsSameLine = !nextToken ||... | javascript | {
"resource": ""
} |
q18176 | ruleApplies | train | function ruleApplies(node) {
if (node.type === "JSXElement" || node.type === "JSXFragment") {
const isSingleLine = node.loc.start.line === node.loc.end.line;
switch (IGNORE_JSX) {
// Exclude this JSX element from linting
case "all":
... | javascript | {
"resource": ""
} |
q18177 | isNewExpressionWithParens | train | function isNewExpressionWithParens(newExpression) {
const lastToken = sourceCode.getLastToken(newExpression);
const penultimateToken = sourceCode.getTokenBefore(lastToken);
return newExpression.arguments.length > 0 || astUtils.isOpeningParenToken(penultimateToken) && astUtils.isClos... | javascript | {
"resource": ""
} |
q18178 | requiresLeadingSpace | train | function requiresLeadingSpace(node) {
const leftParenToken = sourceCode.getTokenBefore(node);
const tokenBeforeLeftParen = sourceCode.getTokenBefore(node, 1);
const firstToken = sourceCode.getFirstToken(node);
return tokenBeforeLeftParen &&
tokenBeforeLef... | javascript | {
"resource": ""
} |
q18179 | requiresTrailingSpace | train | function requiresTrailingSpace(node) {
const nextTwoTokens = sourceCode.getTokensAfter(node, { count: 2 });
const rightParenToken = nextTwoTokens[0];
const tokenAfterRightParen = nextTwoTokens[1];
const tokenBeforeRightParen = sourceCode.getLastToken(node);
r... | javascript | {
"resource": ""
} |
q18180 | doesMemberExpressionContainCallExpression | train | function doesMemberExpressionContainCallExpression(node) {
let currentNode = node.object;
let currentNodeType = node.object.type;
while (currentNodeType === "MemberExpression") {
currentNode = currentNode.object;
currentNodeType = currentNode.type;
... | javascript | {
"resource": ""
} |
q18181 | checkClass | train | function checkClass(node) {
if (!node.superClass) {
return;
}
/*
* If `node.superClass` is a LeftHandSideExpression, parentheses are extra.
* Otherwise, parentheses are needed.
*/
const hasExtraParens = precedence(no... | javascript | {
"resource": ""
} |
q18182 | checkSpreadOperator | train | function checkSpreadOperator(node) {
const hasExtraParens = precedence(node.argument) >= PRECEDENCE_OF_ASSIGNMENT_EXPR
? hasExcessParens(node.argument)
: hasDoubleExcessParens(node.argument);
if (hasExtraParens) {
report(node.argument);
... | javascript | {
"resource": ""
} |
q18183 | checkExpressionOrExportStatement | train | function checkExpressionOrExportStatement(node) {
const firstToken = isParenthesised(node) ? sourceCode.getTokenBefore(node) : sourceCode.getFirstToken(node);
const secondToken = sourceCode.getTokenAfter(firstToken, astUtils.isNotOpeningParenToken);
const thirdToken = secondToken ? s... | javascript | {
"resource": ""
} |
q18184 | checkDestructured | train | function checkDestructured(node) {
if (ignoreDestructuring) {
return;
}
const properties = node.properties;
for (let i = 0; i < properties.length; i++) {
if (properties[i].shorthand) {
continue;
}
... | javascript | {
"resource": ""
} |
q18185 | checkImport | train | function checkImport(node) {
if (ignoreImport) {
return;
}
if (node.imported.name === node.local.name &&
node.imported.range[0] !== node.local.range[0]) {
reportError(node, node.imported, node.local, "Import");
}
... | javascript | {
"resource": ""
} |
q18186 | checkExport | train | function checkExport(node) {
if (ignoreExport) {
return;
}
if (node.local.name === node.exported.name &&
node.local.range[0] !== node.exported.range[0]) {
reportError(node, node.local, node.exported, "Export");
}
... | javascript | {
"resource": ""
} |
q18187 | checkFunction | train | function checkFunction(node) {
if (node.params.length > numParams) {
context.report({
loc: astUtils.getFunctionHeadLoc(node, sourceCode),
node,
messageId: "exceed",
data: {
name: lodash.up... | javascript | {
"resource": ""
} |
q18188 | reportBegin | train | function reportBegin(node, message, match, refChar) {
const type = node.type.toLowerCase(),
commentIdentifier = type === "block" ? "/*" : "//";
context.report({
node,
fix(fixer) {
const start = node.range[0];
... | javascript | {
"resource": ""
} |
q18189 | reportEnd | train | function reportEnd(node, message, match) {
context.report({
node,
fix(fixer) {
if (requireSpace) {
return fixer.insertTextAfterRange([node.range[0], node.range[1] - 2], " ");
}
const end = nod... | javascript | {
"resource": ""
} |
q18190 | checkCommentForSpace | train | function checkCommentForSpace(node) {
const type = node.type.toLowerCase(),
rule = styleRules[type],
commentIdentifier = type === "block" ? "/*" : "//";
// Ignores empty comments.
if (node.value.length === 0) {
return;
}
... | javascript | {
"resource": ""
} |
q18191 | isolateBadConfig | train | function isolateBadConfig(text, config, problemType) {
for (const ruleId of Object.keys(config.rules)) {
const reducedConfig = Object.assign({}, config, { rules: { [ruleId]: config.rules[ruleId] } });
let fixResult;
try {
fixResult = linter.verifyAndFix(text,... | javascript | {
"resource": ""
} |
q18192 | isolateBadAutofixPass | train | function isolateBadAutofixPass(originalText, config) {
let lastGoodText = originalText;
let currentText = originalText;
do {
let messages;
try {
messages = linter.verify(currentText, config);
} catch (err) {
return lastGoodTex... | javascript | {
"resource": ""
} |
q18193 | getRelativePath | train | function getRelativePath(filepath, baseDir) {
const absolutePath = path.isAbsolute(filepath)
? filepath
: path.resolve(filepath);
if (baseDir) {
if (!path.isAbsolute(baseDir)) {
throw new Error(`baseDir should be an absolute path: ${baseDir}`);
}
return path.... | javascript | {
"resource": ""
} |
q18194 | formatSponsors | train | function formatSponsors(sponsors) {
const nonEmptySponsors = Object.keys(sponsors).filter(tier => sponsors[tier].length > 0);
/* eslint-disable indent*/
return stripIndents`<!--sponsorsstart-->
${
nonEmptySponsors.map(tier => `<h3>${tier[0].toUpperCase()}${tier.slice(1)} Sponsors</h3>
... | javascript | {
"resource": ""
} |
q18195 | computeLineLength | train | function computeLineLength(line, tabWidth) {
let extraCharacterCount = 0;
line.replace(/\t/gu, (match, offset) => {
const totalOffset = offset + extraCharacterCount,
previousTabStopOffset = tabWidth ? totalOffset % tabWidth : 0,
spaceCount... | javascript | {
"resource": ""
} |
q18196 | stripTrailingComment | train | function stripTrailingComment(line, comment) {
// loc.column is zero-indexed
return line.slice(0, comment.loc.start.column).replace(/\s+$/u, "");
} | javascript | {
"resource": ""
} |
q18197 | groupByLineNumber | train | function groupByLineNumber(acc, node) {
for (let i = node.loc.start.line; i <= node.loc.end.line; ++i) {
ensureArrayAndPush(acc, i, node);
}
return acc;
} | javascript | {
"resource": ""
} |
q18198 | checkProgramForMaxLength | train | function checkProgramForMaxLength(node) {
// split (honors line-ending)
const lines = sourceCode.lines,
// list of comments to ignore
comments = ignoreComments || maxCommentLength || ignoreTrailingComments ? sourceCode.getAllComments() : [];
// we i... | javascript | {
"resource": ""
} |
q18199 | isConstant | train | function isConstant(node, name) {
switch (node.type) {
case "Literal":
return node.value === name;
case "TemplateLiteral":
return (
node.expressions.length === 0 &&
node.quasis[0].value.cooked === name
);
default:
... | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.