<commit_before>package com.googlecode.jslint4java;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;

/**
 * A command line interface to {@link JSLint}.
 *
 * @author dom
 * @version $Id$
 */
public class Main {

    /** Just a useful utility class. Should probably be top-level. */
    private static class Pair<A, B> {
        public final A a;
        public final B b;

        public Pair(A a, B b) {
            this.a = a;
            this.b = b;
        }

        public static <A, B> Pair<A, B> of(A a, B b) {
            return new Pair<A, B>(a, b);
        }
    }

    private static final String PROGNAME = "jslint";

    /**
     * The main entry point. Try passing in "--help" for more details.
     *
     * @param args
     *            One or more JavaScript files.
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        Main main = new Main();
        List<String> files = main.processOptions(args);
        if (files.size() == 0) {
            main.help();
        }
        for (String file : files) {
            main.lintFile(file);
        }
        System.exit(main.isErrored() ? 1 : 0);
    }

    private boolean errored = false;

    private JSLint lint;

    private Main() throws IOException {
        lint = new JSLintBuilder().fromDefault();
    }

    /**
     * Apply a set of options to the current JSLint.
     */
    private void applyOptions(Map<Option, String> options) {
        for (Entry<Option, String> entry : options.entrySet()) {
            String value = entry.getValue();
            if (value == null) {
                lint.addOption(entry.getKey());
            } else {
                lint.addOption(entry.getKey(), value);
            }
        }
    }

    private void die(String message) {
        System.err.println(PROGNAME + ": " + message);
        System.exit(1);
    }

    private void err(String message) {
        System.out.println(PROGNAME + ":" + message);
        setErrored(true);
    }

    /**
     * Fetch the named {@link Option}, or null if there is no matching one.
     */
    private Option getOption(String optName) {
        try {
            return Option.valueOf(optName.toUpperCase(Locale.getDefault()));
        } catch (IllegalArgumentException e) {
            return null;
        }
    }

    private void help() {
        info("usage: jslint [options] file.js ...");
        String fmt = "  --%-" + Option.maximumNameLength() + "s %s";
        for (Option o : Option.values()) {
            info(String.format(fmt, o.getLowerName(), o.getDescription()));
        }
        info("");
        info(String.format(fmt, "help", "Show this help"));
        info("");
        info("using jslint version " + lint.getEdition());
        System.exit(0);
    }

    private void info(String message) {
        System.out.println(message);
    }

    private boolean isErrored() {
        return errored;<commit_msg>Add DieException instead of calling System.exit().<commit_after>package com.googlecode.jslint4java;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;

/**
 * A command line interface to {@link JSLint}.
 *
 * @author dom
 * @version $Id$
 */
public class Main {

    /** Just a useful utility class. Should probably be top-level. */
    private static class Pair<A, B> {
        public final A a;
        public final B b;

        public Pair(A a, B b) {
            this.a = a;
            this.b = b;
        }

        public static <A, B> Pair<A, B> of(A a, B b) {
            return new Pair<A, B>(a, b);
        }
    }

    /**
     * This is just to avoid calling {@link System#exit(int)} outside of main()…
     */
    @SuppressWarnings("serial")
    private static class DieException extends RuntimeException {
        private final int code;

        public DieException(String message, int code) {
            super(message);
            this.code = code;
        }

        public int getCode() {
            return code;
        }
    }

    private static final String PROGNAME = "jslint";

    /**
     * The main entry point. Try passing in "--help" for more details.
     *
     * @param args
     *            One or more JavaScript files.
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        try {
            Main main = new Main();
            List<String> files = main.processOptions(args);
            if (files.size() == 0) {
                main.help();
            }
            for (String file : files) {
                main.lintFile(file);
            }
            System.exit(main.isErrored() ? 1 : 0);
        } catch (DieException e) {
            if (e.getMessage() != null) {
                System.err.println(PROGNAME + ": " + e.getMessage());
            }
            System.exit(e.getCode());
        }
    }

    private boolean errored = false;

    private JSLint lint;

    private Main() throws IOException {
        lint = new JSLintBuilder().fromDefault();
    }

    /**
     * Apply a set of options to the current JSLint.
     */
    private void applyOptions(Map<Option, String> options) {
        for (Entry<Option, String> entry : options.entrySet()) {
            String value = entry.getValue();
            if (value == null) {
                lint.addOption(entry.getKey());
            } else {
                lint.addOption(entry.getKey(), value);
            }
        }
    }

    private void die(String message) {
        throw new DieException(message, 1);
    }

    private void err(String message) {
        System.out.println(PROGNAME + ":" + message);
        setErrored(true);
    }

    /**
     * Fetch the named {@link Option}, or null if there is no matching one.
     */
    private Option getOption(String optName) {
        try {
            return Option.valueOf(optName.toUpperCase(Locale.getDefault()));
        } catch (IllegalArgumentException e) {
            return null;
        }
    }

    private void help() {
        info("usage: jslint [options] file.js ...");
        String fmt = "  --%-" + Option.maximumNameLength() + "s %s";
        for (Option o : Option.values()) {
            info(String.format(fmt, o.getLowerName(), o.getDescription()));
        }
        info("");
        info(String.format(fmt, "help", "Show this help"));
        info("");
        info("using jslint version " + lint.getEdition());
        throw new DieException(null, 0);
    }

    private void info(String message) {
        System.out.println(message);
    }

    private boolean isErrored() {
        return errored;
{'fraction_non_alphanumeric': 0.12435522096751708, 'fraction_numerical': 0.001672940192388122, 'mean_word_length': 1.9425758818703855, 'pattern_counts': {'":': 4, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5281533', 'n_tokens_mistral': 2106, 'n_tokens_neox': 2040, 'n_words': 575}