All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.vandmo.textchecker.maven.rules.ConsistentLineSeparator Maven / Gradle / Ivy

There is a newer version: 0.22.1
Show newest version
package se.vandmo.textchecker.maven.rules;

import se.vandmo.textchecker.maven.annotations.FixWith;

import static com.google.common.collect.Lists.newArrayList;
import static java.util.Collections.emptyList;

import java.util.Collection;
import java.util.regex.Pattern;

import se.vandmo.textchecker.maven.Complaint;
import se.vandmo.textchecker.maven.Content;
import se.vandmo.textchecker.maven.Rule;
import se.vandmo.textchecker.maven.fixers.MakeLineSeparatorsConsistent;

@FixWith(MakeLineSeparatorsConsistent.class)
public final class ConsistentLineSeparator implements Rule {

  private static final Pattern N_WITHOUT_PRECEEDING_R = Pattern.compile("[^\r]\n");

  @Override
  public Collection check(Content content) {
    if (!isOk(content.data())) {
      return newArrayList(new Complaint("File has inconsistent line endings"));
    }
    return emptyList();
  }

  public static boolean isOk(String data) {
    if (!data.contains("\r")) {
      return true;
    }
    return !N_WITHOUT_PRECEEDING_R.matcher(data).matches();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy