Find the deepest child that has a line number to which a lint might
 apply (if it is a control comment enable node, it will be the line of
 the comment itself).
320608
def end_line(node)
      child = node
      prev_child = node
      until [nil, prev_child].include?(child = last_child(child))
        prev_child = child
      end

      # Fall back to prev_child if last_child() returned nil (i.e. node had no
      # children with line numbers)
      (child || prev_child).line
    end
1027974
def check_children_order(sorted_children, children)
      sorted_children.each_with_index do |sorted_item, index|
        next if sorted_item == children[index]

        add_lint(sorted_item.first.line,
                 "Expected item on line #{sorted_item.first.line} to appear " \
                 "before line #{children[index].first.line}. #{MESSAGE}")
        break
      end
    end
125324
function (source) {
        var tocStartIndex = source.indexOf(TOC_COMMENT),
            tocEndIndex = source.indexOf(TOC_END_COMMENT, tocStartIndex);

        if (tocStartIndex === -1 || tocEndIndex === -1) return source;

        return source.substring(0, tocStartIndex + TOC_COMMENT.length) +
                source.substring(tocEndIndex + TOC_END_COMMENT.length);
    }
1369907
function(ln, line_number) {

  var all_matched = true;
  var last_child;
  var first_nonspace;
  var offset = 0;
  var match;
  var data;
  var blank;
  var indent;
  var last_matched_container;
  var i;
  var CODE_INDENT = 4;

  var container = this.doc;
  var oldtip = this.tip;

  // Convert tabs to spaces:
  ln = detabLine(ln);

  // For each containing block, try to parse the associated line start.
  // Bail out on failure: container will point to the last matching block.
  // Set all_matched to false if not all containers match.
  while (container.children.length > 0) {
    last_child = container.children[container.children.length - 1];
    if (!last_child.open) {
      break;
    }
    container = last_child;

    match = matchAt(/[^ ]/, ln, offset);
    if (match === null) {
      first_nonspace = ln.length;
      blank = true;
    } else {
      first_nonspace = match;
      blank = false;
    }
    indent = first_nonspace - offset;

    switch (container.t) {
      case 'BlockQuote':
        var matched = indent <= 3 && ln.charAt(first_nonspace) === '>';
        if (matched) {
          offset = first_nonspace + 1;
          if (ln.charAt(offset) === ' ') {
            offset++;
          }
        } else {
          all_matched = false;
        }
        break;

      case 'ListItem':
        if (indent >= container.list_data.marker_offset +
                      container.list_data.padding) {
          offset += container.list_data.marker_offset +
                    container.list_data.padding;
        } else if (blank) {
          offset = first_nonspace;
        } else {
          all_matched = false;
        }
        break;

      case 'IndentedCode':
        if (indent >= CODE_INDENT) {
          offset += CODE_INDENT;
        } else if (blank) {
          offset = first_nonspace;
        } else {
          all_matched = false;
        }
        break;

      case 'ATXHeader':
      case 'SetextHeader':
      case 'HorizontalRule':
        // a header can never container > 1 line, so fail to match:
        all_matched = false;
        break;

      case 'FencedCode':
        // skip optional spaces of fence offset
        i = container.fence_offset;
        while (i > 0 && ln.charAt(offset) === ' ') {
          offset++;
          i--;
        }
        break;

      case 'HtmlBlock':
        if (blank) {
          all_matched = false;
        }
        break;

      case 'Paragraph':
        if (blank) {
          container.last_line_blank = true;
          all_matched = false;
        }
        break;

      default:
    }

    if (!all_matched) {
      container = container.parent; // back up to last matching block
      break;
    }
  }

  last_matched_container = container;

  // This function is used to finalize and close any unmatched
  // blocks.  We aren't ready to do this now, because we might
  // have a lazy paragraph continuation, in which case we don't
  // want to close unmatched blocks.  So we store this closure for
  // use later, when we have more information.
  var closeUnmatchedBlocks = function(mythis) {
    // finalize any blocks not matched
    while (!already_done && oldtip != last_matched_container) {
      mythis.finalize(oldtip, line_number);
      oldtip = oldtip.parent;
    }
    var already_done = true;
  };

  // Check to see if we've hit 2nd blank line; if so break out of list:
  if (blank && container.last_line_blank) {
    this.breakOutOfLists(container, line_number);
  }

  // Unless last matched container is a code block, try new container starts,
  // adding children to the last matched container:
  while (container.t != 'FencedCode' &&
         container.t != 'IndentedCode' &&
         container.t != 'HtmlBlock' &&
         // this is a little performance optimization:
         matchAt(/^[ #`~*+_=<>0-9-]/,ln,offset) !== null) {

    match = matchAt(/[^ ]/, ln, offset);
    if (match === null) {
      first_nonspace = ln.length;
      blank = true;
    } else {
      first_nonspace = match;
      blank = false;
    }
    indent = first_nonspace - offset;

    if (indent >= CODE_INDENT) {
      // indented code
      if (this.tip.t != 'Paragraph' && !blank) {
        offset += CODE_INDENT;
        closeUnmatchedBlocks(this);
        container = this.addChild('IndentedCode', line_number, offset);
      } else { // indent > 4 in a lazy paragraph continuation
        break;
      }

    } else if (ln.charAt(first_nonspace) === '>') {
      // blockquote
      offset = first_nonspace + 1;
      // optional following space
      if (ln.charAt(offset) === ' ') {
        offset++;
      }
      closeUnmatchedBlocks(this);
      container = this.addChild('BlockQuote', line_number, offset);

    } else if ((match = ln.slice(first_nonspace).match(/^#{1,6}(?: +|$)/))) {
      // ATX header
      offset = first_nonspace + match[0].length;
      closeUnmatchedBlocks(this);
      container = this.addChild('ATXHeader', line_number, first_nonspace);
      container.level = match[0].trim().length; // number of #s
      // remove trailing ###s:
      container.strings =
            [ln.slice(offset).replace(/(?:(\\#) *#*| *#+) *$/,'$1')];
      break;

    } else if ((match = ln.slice(first_nonspace).match(/^`{3,}(?!.*`)|^~{3,}(?!.*~)/))) {
      // fenced code block
      var fence_length = match[0].length;
      closeUnmatchedBlocks(this);
      container = this.addChild('FencedCode', line_number, first_nonspace);
      container.fence_length = fence_length;
      container.fence_char = match[0].charAt(0);
      container.fence_offset = first_nonspace - offset;
      offset = first_nonspace + fence_length;
      break;

    } else if (matchAt(reHtmlBlockOpen, ln, first_nonspace) !== null) {
      // html block
      closeUnmatchedBlocks(this);
      container = this.addChild('HtmlBlock', line_number, first_nonspace);
      // note, we don't adjust offset because the tag is part of the text
      break;

    } else if (container.t == 'Paragraph' &&
               container.strings.length === 1 &&
               ((match = ln.slice(first_nonspace).match(/^(?:=+|-+) *$/)))) {
      // setext header line
      closeUnmatchedBlocks(this);
      container.t = 'SetextHeader'; // convert Paragraph to SetextHeader
      container.level = match[0].charAt(0) === '=' ? 1 : 2;
      offset = ln.length;

    } else if (matchAt(reHrule, ln, first_nonspace) !== null) {
      // hrule
      closeUnmatchedBlocks(this);
      container = this.addChild('HorizontalRule', line_number, first_nonspace);
      offset = ln.length - 1;
      break;

    } else if ((data = parseListMarker(ln, first_nonspace))) {
      // list item
      closeUnmatchedBlocks(this);
      data.marker_offset = indent;
      offset = first_nonspace + data.padding;

      // add the list if needed
      if (container.t !== 'List' ||
          !(listsMatch(container.list_data, data))) {
           container = this.addChild('List', line_number, first_nonspace);
           container.list_data = data;
      }

      // add the list item
      container = this.addChild('ListItem', line_number, first_nonspace);
      container.list_data = data;

    } else {
      break;

    }

    if (acceptsLines(container.t)) {
      // if it's a line container, it can't contain other containers
      break;
    }
  }

  // What remains at the offset is a text line.  Add the text to the
  // appropriate container.

  match = matchAt(/[^ ]/, ln, offset);
  if (match === null) {
    first_nonspace = ln.length;
    blank = true;
  } else {
    first_nonspace = match;
    blank = false;
  }
  indent = first_nonspace - offset;

  // First check for a lazy paragraph continuation:
  if (this.tip !== last_matched_container &&
      !blank &&
      this.tip.t == 'Paragraph' &&
      this.tip.strings.length > 0) {
     // lazy paragraph continuation

    this.last_line_blank = false;
    this.addLine(ln, offset);

  } else { // not a lazy continuation

    // finalize any blocks not matched
    closeUnmatchedBlocks(this);

    // Block quote lines are never blank as they start with >
    // and we don't count blanks in fenced code for purposes of tight/loose
    // lists or breaking out of lists.  We also don't set last_line_blank
    // on an empty list item.
    container.last_line_blank = blank &&
      !(container.t == 'BlockQuote' ||
        container.t == 'FencedCode' ||
        (container.t == 'ListItem' &&
         container.children.length === 0 &&
         container.start_line == line_number));

    var cont = container;
    while (cont.parent) {
      cont.parent.last_line_blank = false;
      cont = cont.parent;
    }

    switch (container.t) {
    case 'IndentedCode':
    case 'HtmlBlock':
      this.addLine(ln, offset);
      break;

    case 'FencedCode':
      // check for closing code fence:
      match = (indent <= 3 &&
               ln.charAt(first_nonspace) == container.fence_char &&
               ln.slice(first_nonspace).match(/^(?:`{3,}|~{3,})(?= *$)/));
      if (match && match[0].length >= container.fence_length) {
        // don't add closing fence to container; instead, close it:
        this.finalize(container, line_number);
      } else {
        this.addLine(ln, offset);
      }
      break;

    case 'ATXHeader':
    case 'SetextHeader':
    case 'HorizontalRule':
      // nothing to do; we already added the contents.
      break;

    default:
      if (acceptsLines(container.t)) {
        this.addLine(ln, first_nonspace);
      } else if (blank) {
        // do nothing
      } else if (container.t != 'HorizontalRule' &&
                 container.t != 'SetextHeader') {
        // create paragraph container for line
        container = this.addChild('Paragraph', line_number, first_nonspace);
        this.addLine(ln, first_nonspace);
      } else {
        console.log("Line " + line_number.toString() +
                     " with container type " + container.t +
                     " did not match any condition.");

      }
    }
  }
}
334914
def nontrivial_end_line
      if (last_child = children.last)
        last_child.line_numbers.end - 1
      elsif successor
        successor.line_numbers.begin - 1
      else
        @document.source_lines.count
      end
    end
1142539
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;
        }
1026125
public int getLine()
  {
    if (_line >= 0)
      return _line;

    Attribute attr = getAttribute("LineNumberTable");

    if (attr == null) {
      _line = 0;
      return _line;
    }

    _line = 0;
    return _line;
  }
618665
function checkSC(i) {
  if (i >= tokensLength) return 0;

  let l;
  let lsc = 0;
  const ln = tokens[i].ln;

  while (i < tokensLength) {
    if (tokens[i].ln !== ln) break;

    if (l = checkS(i)) tokens[i].sc_child = 1;
    else if (l = checkCommentML(i)) tokens[i].sc_child = 2;
    else if (l = checkCommentSL(i)) tokens[i].sc_child = 3;
    else break;

    i += l;
    lsc += l;

    if (tokens[i] && tokens[i].type === TokenType.Newline) break;
  }

  return lsc || 0;
}
356439
def find_objects(self, linespec):
        
        # Note(asr1kteam): In this code we are only adding children one-level
        # deep to a given parent (linespec), as that satisfies the IOS conf
        # parsing.
        # Note(asr1kteam): Not tested with tabs in the config. Currently used
        # with IOS config where we haven't seen tabs, but may be needed for a
        # more general case.
        res = []
        self._build_indent_based_list()
        for item, index in self._find_starts(linespec):
            parent = LineItem(item[1])
            next_ident_level = self._find_next_indent_level(index)
            if next_ident_level:
                # We start iterating from the next element
                for item in self._indent_list[(index + 1):]:
                    if item[0] == next_ident_level:
                        parent.add_children(LineItem(item[1]))
                    elif item[0] > next_ident_level:  # We skip higher indent
                        continue
                    else:  # Indent level is same or lesser than item
                        break
            res.append(parent)
        return res
1319172
function hasBlankLinesBetween(node, token) {
    return token.loc.start.line > node.loc.end.line + 1;
}
969314
function hasCommentBefore(node, sourceCode) {
  return sourceCode.getCommentsBefore(node)
    .some(comment => comment.loc.end.line >= node.loc.start.line - 1)
}
806865
function isPreviousLineEmpty(text, node, locStart) {
  let idx = locStart(node) - 1;
  idx = skipSpaces(text, idx, { backwards: true });
  idx = skipNewline(text, idx, { backwards: true });
  idx = skipSpaces(text, idx, { backwards: true });
  const idx2 = skipNewline(text, idx, { backwards: true });
  return idx !== idx2;
}
1083092
private void commentLinesAfter( String content, int line ) {
        int offset = rootElement.getElement(line).getEndOffset();
        // End of comment not found, nothing to do
        int endDelimiter = indexOf(content, getEndDelimiter(), offset);
        if (endDelimiter < 0)
            return;
        // Matching start/end of comment found, comment the lines
        int startDelimiter = lastIndexOf(content, getStartDelimiter(), endDelimiter);
        if (startDelimiter < 0 || startDelimiter <= offset) {
            doc.setCharacterAttributes(offset, endDelimiter - offset + 1, comment, false);
        }
    }
220931
def _number_slash_end_handler(c, ctx, event):
    
    assert c == _SLASH
    c, self = yield
    next_ctx = ctx.derive_child_context(ctx.whence)
    comment = _comment_handler(_SLASH, next_ctx, next_ctx.whence)
    comment.send((c, comment))
    # If the previous line returns without error, it's a valid comment and the number may be emitted.
    yield _CompositeTransition(event, ctx, comment, next_ctx, initialize_handler=False)
1288223
def node_for_line(line)
      find(-> { HamlLint::Tree::NullNode.new }) { |node| node.line_numbers.cover?(line) }
    end
1302209
public ParseTree getStatementAtLine( int iLineNum, Class clsSkip )
  {
    if( _pe instanceof NewExpression )
    {
      NewExpression newExpression = (NewExpression)_pe;
      IType type = newExpression.getType();
      if( type instanceof IGosuClassInternal && newExpression.isAnonymousClass() )
      {
        return (ParseTree)((IGosuClassInternal)type).getClassStatement().getLocation().getStatementAtLine( iLineNum, clsSkip );
      }
    }

    if( (_pe instanceof Statement) && // Note we must analyze expressions e.g., block expressions can have statements
        !(_pe instanceof FunctionStatement && ((FunctionStatement)_pe).getDynamicFunctionSymbol() instanceof ProgramClassFunctionSymbol) &&
        (getLineNum() == iLineNum) &&
        (clsSkip == null || !clsSkip.isAssignableFrom( _pe.getClass() )) )
    {
      return this;
    }

    ParseTree deepest = null;
    for(int i = 0; i < _children.size; i++)
    {
      ParseTree child = (ParseTree) _children.data[i];
      ParseTree l = child.getStatementAtLine( iLineNum, clsSkip );
      if( Search.isDeeper( deepest, l ) )
      {
        deepest = l;
      }
    }

    return deepest;
  }
774041
function getLastCommentLineOfBlock(commentStartLine) {
            const currentCommentEnd = commentEndLine[commentStartLine];

            return commentEndLine[currentCommentEnd + 1] ? getLastCommentLineOfBlock(currentCommentEnd + 1) : currentCommentEnd;
        }