Skip to content

Commit

Permalink
Make sure the passed lint conf is not null
Browse files Browse the repository at this point in the history
  • Loading branch information
sbaudoin committed Nov 3, 2020
1 parent 958975d commit 7444f8f
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/main/java/com/github/sbaudoin/yamllint/Linter.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ private Linter() {
* Lints a YAML source represented as a string
*
* @param buffer a YAML configuration
* @param conf yamllint configuration
* @param conf yamllint configuration. Cannot be <code>null</code>.
* @return the list of problems found for the passed file, possibly empty (never <code>null</code>)
* @throws IllegalArgumentException if <var>conf</var> is {@code null}
*/
public static List<LintProblem> run(String buffer, YamlLintConfig conf) {
return run(buffer, conf, null);
Expand All @@ -106,9 +107,10 @@ public static List<LintProblem> run(String buffer, YamlLintConfig conf) {
* Lints a YAML source represented as a string
*
* @param buffer a YAML configuration
* @param conf yamllint configuration
* @param conf yamllint configuration. Cannot be <code>null</code>.
* @return the list of problems found for the passed file, possibly empty (never <code>null</code>)
* @throws IOException if there is a problem reading the file
* @throws IllegalArgumentException if <var>conf</var> is {@code null}
*/
public static List<LintProblem> run(InputStream buffer, YamlLintConfig conf) throws IOException {
return run(buffer, conf, null);
Expand All @@ -117,12 +119,15 @@ public static List<LintProblem> run(InputStream buffer, YamlLintConfig conf) thr
/**
* Lints a YAML source represented as a file
*
* @param conf yamllint configuration
* @param conf yamllint configuration. Cannot be <code>null</code>.
* @param file the (YAML) file to lint
* @return the list of problems found for the passed file, possibly empty (never <code>null</code>)
* @throws IOException if there is a problem reading the file
* @throws NullPointerException if <var>conf</var> is {@code null}
*/
public static List<LintProblem> run(YamlLintConfig conf, File file) throws IOException {
Objects.requireNonNull(conf);

if (conf.isFileIgnored(file.getPath())) {
return new ArrayList<>();
}
Expand All @@ -141,8 +146,11 @@ public static List<LintProblem> run(YamlLintConfig conf, File file) throws IOExc
* @param file the file whose content has been passed as the <var>buffer</var>. May be <code>null</code>.
* @return the list of problems found on the passed YAML string
* @throws IOException if an error occurred while reading the input stream
* @throws NullPointerException if <var>conf</var> is {@code null}
*/
public static List<LintProblem> run(InputStream in, YamlLintConfig conf, File file) throws IOException {
Objects.requireNonNull(conf);

// Properly read buffer, taking the BOM into account
Reader reader = new UnicodeReader(in);

Expand All @@ -163,8 +171,11 @@ public static List<LintProblem> run(InputStream in, YamlLintConfig conf, File fi
* @param conf yamllint configuration. Cannot be <code>null</code>.
* @param file the file whose content has been passed as the <var>buffer</var>. May be <code>null</code>.
* @return the list of problems found on the passed YAML string
* @throws NullPointerException if <var>conf</var> is {@code null}
*/
public static List<LintProblem> run(String buffer, YamlLintConfig conf, File file) {
Objects.requireNonNull(conf);

// Use a set to avoid duplicated problems
TreeSet<LintProblem> problems = new TreeSet<>((p1, p2) -> {
if (p1.getLine() < p2.getLine()) {
Expand Down Expand Up @@ -242,12 +253,15 @@ public static LintProblem getSyntaxError(String buffer) {
* for filtering the rules to be applied.
*
* @param buffer the YAML string to be checked
* @param conf the YAML lint configuration
* @param conf the YAML lint configuration. Cannot be {@code null}.
* @param file file supposed to be the passed YAML string. Used to determined the rules to be applied. May be {@code null}.
* @return a list of problems found on the passed string
* @throws NullPointerException if <var>conf</var> is {@code null}
*/
@SuppressWarnings("unchecked")
public static List<LintProblem> getCosmeticProblems(String buffer, YamlLintConfig conf, @Nullable File file) {
Objects.requireNonNull(conf);

List<Rule> rules = conf.getEnabledRules(file);

// Split token rules from line rules
Expand Down

0 comments on commit 7444f8f

Please sign in to comment.