<commit_before>import React, { Component } from "react";
import Editor from "./Editor";
import Messages from "./Messages";
import FixedCode from "./FixedCode";
import BugReport from "./BugReport";
import Crash from "./Crash";
import Configuration from "./Configuration";
import Unicode from "../utils/unicode";
import linterModule from "../../eslint";

function getUrlState() {
    try {
        return JSON.parse(Unicode.decodeFromBase64(window.location.hash.replace(/^#/, "")));
    } catch (err) {
        return null;
    }
}

const hasLocalStorage = (function() {
    try {
        window.localStorage.setItem("localStorageTest", "foo");
        window.localStorage.removeItem("localStorageTest");
        return true;
    } catch (e) {
        return false;
    }
}());

const linter = new linterModule.Linter();
const rules = linter.getRules();
const ruleNames = Array.from(rules.keys());
const docs = Array.from(rules.entries()).reduce((result, [key, value]) => {
    result[key] = value.meta;
    return result;
}, {});

const ENV_NAMES = [
    "browser",
    "node",
    "commonjs",
    "shared-node-browser",
    "worker",
    "amd",
    "mocha",
    "jasmine",
    "jest",
    "phantomjs",
    "jquery",
    "qunit",
    "prototypejs",
    "shelljs",
    "meteor",
    "mongo",
    "protractor",
    "applescript",
    "nashorn",
    "serviceworker",
    "atomtest",
    "embertest",
    "webextensions",
    "es6",
    "greasemonkey"
];

export default class App extends Component {
    constructor(props) {
        super(props);

        const storedState = JSON.parse(window.localStorage.getItem("linterDemoState") || null);
        const urlState = getUrlState();
        const initialState = Object.assign(
            { fix: false },
            urlState || storedState || {
                options: {
                    parserOptions: {
                        ecmaVersion: 5,
                        sourceType: "script",
                        ecmaFeatures: {}
                    },
                    rules: rules.reduce((result, rule, ruleId) => {
                        if (rule.meta.docs.recommended) {
                            result[ruleId] = 2;
                        }
                        return result;
                    }, {}),
                    env: {}
                },
                text: "var foo = bar;"
            }
        );

        if (
            initialState &&<commit_msg>Fix: recommended rules crash (#640)<commit_after>import React, { Component } from "react";
import Editor from "./Editor";
import Messages from "./Messages";
import FixedCode from "./FixedCode";
import BugReport from "./BugReport";
import Crash from "./Crash";
import Configuration from "./Configuration";
import Unicode from "../utils/unicode";
import linterModule from "../../eslint";

function getUrlState() {
    try {
        return JSON.parse(Unicode.decodeFromBase64(window.location.hash.replace(/^#/, "")));
    } catch (err) {
        return null;
    }
}

const hasLocalStorage = (function() {
    try {
        window.localStorage.setItem("localStorageTest", "foo");
        window.localStorage.removeItem("localStorageTest");
        return true;
    } catch (e) {
        return false;
    }
}());

const linter = new linterModule.Linter();
const rules = linter.getRules();
const ruleNames = Array.from(rules.keys());
const docs = Array.from(rules.entries()).reduce((result, [key, value]) => {
    result[key] = value.meta;
    return result;
}, {});

const ENV_NAMES = [
    "browser",
    "node",
    "commonjs",
    "shared-node-browser",
    "worker",
    "amd",
    "mocha",
    "jasmine",
    "jest",
    "phantomjs",
    "jquery",
    "qunit",
    "prototypejs",
    "shelljs",
    "meteor",
    "mongo",
    "protractor",
    "applescript",
    "nashorn",
    "serviceworker",
    "atomtest",
    "embertest",
    "webextensions",
    "es6",
    "greasemonkey"
];

export default class App extends Component {
    constructor(props) {
        super(props);

        const storedState = JSON.parse(window.localStorage.getItem("linterDemoState") || null);
        const urlState = getUrlState();
        const initialState = Object.assign(
            { fix: false },
            urlState || storedState || {
                options: {
                    parserOptions: {
                        ecmaVersion: 5,
                        sourceType: "script",
                        ecmaFeatures: {}
                    },
                    rules: [...rules.entries()].reduce((result, [ruleId, rule]) => {
                        if (rule.meta.docs.recommended) {
                            result[ruleId] = 2;
                        }
                        return result;
                    }, {}),
                    env: {}
                },
                text: "var foo = bar;"
            }
        );

        if (
            initialState &&
{'fraction_non_alphanumeric': 0.14242115971515767, 'fraction_numerical': 0.002644964394710071, 'mean_word_length': 1.82691201840138, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4714924', 'n_tokens_mistral': 1412, 'n_tokens_neox': 1350, 'n_words': 306}