// Finish an AST node, adding `type` and `end` properties. function finishNodeAt(node, type, pos, loc) { node.type = type node.end = pos if (this.options.locations) node.loc.end = loc if (this.options.ranges) node.range[1] = pos return node }
getAstString(source, ast) { const lines = Array.isArray(source) ? source : source.split(/\r?\n/g); const start = ast.loc.start; const end = ast.loc.end; const result = []; if (start.line === end.line) { result.push(lines[start.line - 1].substring(start.column, end.column)); } else { result.push(lines[start.line - 1].slice(start.column)); for (let i = start.line; i < end.line; i++) { result.push(lines[i]); } result.push(lines[end.line - 1].slice(0, end.column)); } return result.join('\n'); }
const create = context => ({ Program: node => { for (const comment of node.comments) { const value = comment.value.trim(); const result = disableRegex.exec(value); if ( result && // It's a eslint-disable comment !result.groups.ruleId // But it did not specify any rules ) { context.report({ loc: { start: { ...comment.loc.start, column: -1 }, end: comment.loc.end }, message: 'Specify the rules you want to disable.' }); } } } })
transpileFile(file, errorsReport) { try { const ast = parse( file.content, { sourceFilename: file.fileName, sourceType: 'module', plugins: ['objectRestSpread'] }, ); this.transpilers.forEach((t) => babelTraverse(ast, t.traverseObject())); const content = babelGenerator(ast, {}, file.content).code; return Object.assign({}, file, { content }); } catch (e) { if (e.toString().indexOf('SyntaxError') !== -1) { const line = file.content.split('\n')[e.loc.line - 1]; const spaces = Array(e.loc.column).fill(' ').join(''); errorsReport.error(`Syntax error during '${file.fileName}' parsing: ${e.message}:\n${line}\n${spaces}^`); } else { errorsReport.error(e); } } return undefined; }
this.nodes[nodeId].type = nodeInfo.type; this.nodes[nodeId].name = nodeInfo.name; this.nodes[nodeId].loc = nodeInfo.loc; this.nodes[nodeId].ready = true;
node.loc.start.line }` );
const { line, column } = getLocation(src, variableDef.loc.start) deprecate(`The $${name} variable should be of type ${newType} instead of ${oldType}.`, { customCaller: [resourcePath, line, column]
name = callee.property.loc ? callee.property.loc.identifierName : callee.property.name; } else { name = callee.loc ? callee.loc.identifierName : callee.name; const base = state.opts.base || '.'; const pathname = relative( base, filename ).split( sep ).join( '/' ); translation.comments.reference = pathname + ':' + path.node.loc.start.line;
_originalNodeLine = node.loc.start.line; if ( ! commentNode.loc ) { return; const { line } = commentNode.loc.end; if ( line < _originalNodeLine - 1 || line > _originalNodeLine ) { return; if ( ! parent || ! parent.loc || ! parentPath ) { return; const { line } = parent.loc.start; if ( line >= _originalNodeLine - 1 && line <= _originalNodeLine ) { return getExtractedComment( parentPath, _originalNodeLine );
this.nodes[nodeId].type = nodeInfo.type; this.nodes[nodeId].name = nodeInfo.name; this.nodes[nodeId].loc = nodeInfo.loc; this.nodes[nodeId].ready = true;
this.nodes[nodeId].type = nodeInfo.type; this.nodes[nodeId].name = nodeInfo.name; this.nodes[nodeId].loc = nodeInfo.loc; this.nodes[nodeId].ready = true;
const { line, column } = getLocation(src, variableDef.loc.start) deprecate(`The $${name} variable should be of type ${newType} instead of ${oldType}.`, { customCaller: [resourcePath, line, column]