<commit_before>package com.googlecode.jslint4java.cli;

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.lang.reflect.Field;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Locale;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterDescription;
import com.googlecode.jslint4java.Issue;
import com.googlecode.jslint4java.JSLint;
import com.googlecode.jslint4java.JSLintBuilder;
import com.googlecode.jslint4java.JSLintResult;
import com.googlecode.jslint4java.Option;
import com.googlecode.jslint4java.formatter.JSLintResultFormatter;
import com.googlecode.jslint4java.formatter.JSLintXmlFormatter;
import com.googlecode.jslint4java.formatter.JUnitXmlFormatter;
import com.googlecode.jslint4java.formatter.PlainFormatter;
import com.googlecode.jslint4java.formatter.ReportFormatter;

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

    /**
     * The default command line output.
     */
    private static final class DefaultFormatter implements JSLintResultFormatter {
        public String format(JSLintResult result) {
            StringBuilder sb = new StringBuilder();
            for (Issue issue : result.getIssues()) {
                sb.append(PROGNAME);
                sb.append(':');
                sb.append(issue.toString());
                sb.append('\n');
            }
            return sb.toString();
        }

        public String footer() {
            return null;
        }

        public String header() {
            return null;
        }
    }

    /**
     * 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();
            for (String file : main.processOptions(args)) {
                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 Charset encoding = Charset.defaultCharset();

    private boolean errored = false;

    private final Flags flags = new Flags();

    private JSLintResultFormatter formatter;

    private JSLint lint;

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

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

    /**
     * Fetch the named {@link Option}, or null if there is no matching one.
     */<commit_msg>issue 43: Use headers and footers on the command line.<commit_after>package com.googlecode.jslint4java.cli;

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.lang.reflect.Field;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Locale;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterDescription;
import com.googlecode.jslint4java.Issue;
import com.googlecode.jslint4java.JSLint;
import com.googlecode.jslint4java.JSLintBuilder;
import com.googlecode.jslint4java.JSLintResult;
import com.googlecode.jslint4java.Option;
import com.googlecode.jslint4java.formatter.JSLintResultFormatter;
import com.googlecode.jslint4java.formatter.JSLintXmlFormatter;
import com.googlecode.jslint4java.formatter.JUnitXmlFormatter;
import com.googlecode.jslint4java.formatter.PlainFormatter;
import com.googlecode.jslint4java.formatter.ReportFormatter;

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

    /**
     * The default command line output.
     */
    private static final class DefaultFormatter implements JSLintResultFormatter {
        public String format(JSLintResult result) {
            StringBuilder sb = new StringBuilder();
            for (Issue issue : result.getIssues()) {
                sb.append(PROGNAME);
                sb.append(':');
                sb.append(issue.toString());
                sb.append('\n');
            }
            return sb.toString();
        }

        public String footer() {
            return null;
        }

        public String header() {
            return null;
        }
    }

    /**
     * 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 {
            System.exit(new Main().run(args));
        } catch (DieException e) {
            if (e.getMessage() != null) {
                System.err.println(PROGNAME + ": " + e.getMessage());
            }
            System.exit(e.getCode());
        }
    }

    private int run(String[] args) throws IOException {
        List<String> files = processOptions(args);
        if (formatter.header() != null) {
            info(formatter.header());
        }
        for (String file : files) {
            lintFile(file);
        }
        if (formatter.footer() != null) {
            info(formatter.footer());
        }
        return isErrored() ? 1 : 0;
    }

    private Charset encoding = Charset.defaultCharset();

    private boolean errored = false;

    private final Flags flags = new Flags();

    private JSLintResultFormatter formatter;

    private JSLint lint;

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

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

    /**
     * Fetch the named {@link Option}, or null if there is no matching one.
     */
{'fraction_non_alphanumeric': 0.1025531914893617, 'fraction_numerical': 0.00425531914893617, 'mean_word_length': 2.3608198284080077, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, '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': '3835087', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1953, 'n_words': 495}