Commit ec4f219e authored by Trey Hunner's avatar Trey Hunner Committed by Tim Graham
Browse files

Fixed #22463 -- Added code style guide and JavaScript linting (EditorConfig and ESLint)

parent 1e63652e
Loading
Loading
Loading
Loading

.editorconfig

0 → 100644
+37 −0
Original line number Diff line number Diff line
# http://editorconfig.org

root = true

[*]
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
end_of_line = lf
charset = utf-8

# Use 2 spaces for the HTML files
[*.html]
indent_size = 2

# The JSON files contain newlines inconsistently
[*.json]
indent_size = 2
insert_final_newline = ignore

[**/admin/js/vendor/**]
indent_style = ignore
indent_size = ignore

# Minified JavaScript files shouldn't be changed
[**.min.js]
indent_style = ignore
insert_final_newline = ignore

# Makefiles always use tabs for indentation
[Makefile]
indent_style = tab

# Batch files use tabs for indentation
[*.bat]
indent_style = tab

.eslintignore

0 → 100644
+3 −0
Original line number Diff line number Diff line
**/{*.min,jquery}.js
django/contrib/gis/templates/**/*.js
node_modules/**.js

.eslintrc

0 → 100644
+51 −0
Original line number Diff line number Diff line
{
    "rules": {
        "camelcase": [1, {"properties": "always"}],
        "comma-spacing": [1, {"before": false, "after": true}],
        "dot-notation": [1, {"allowKeywords": true}],
        "curly": [1, "all"],
        "indent": [
            2,
            4
        ],
        "key-spacing": [1, {
            "beforeColon": false,
            "afterColon": true
        }],
        "new-cap": [1, {"newIsCap": true, "capIsNew": true}],
        "no-alert": [0],
        "no-eval": [1],
        "no-extend-native": [2, {"exceptions": ["Date", "String"]}],
        "no-multi-spaces": [1],
        "no-octal-escape": [1],
        "no-underscore-dangle": [1],
        "no-unused-vars": [2, {"vars": "local", "args": "none"}],
        "no-script-url": [1],
        "no-shadow": [1, {"hoist": "functions"}],
        "quotes": [
            1,
            "single"
        ],
        "linebreak-style": [
            2,
            "unix"
        ],
        "semi": [
            2,
            "always"
        ],
        "space-before-blocks": [2, "always"],
        "space-before-function-paren": [1, {"anonymous": "always", "named": "never"}],
        "space-infix-ops": [
            1,
            {"int32Hint": false}
        ],
        "strict": [1, "function"]
    },
    "env": {
        "browser": true
    },
    "globals": {
        "django": false
    }
}
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ MANIFEST
dist/
docs/_build/
docs/locale/
node_modules/
tests/coverage_html/
tests/.coverage
build/
+8 −9
Original line number Diff line number Diff line
/*eslint no-cond-assign:1*/
var SelectBox = {
    cache: new Object(),
    cache: {},
    init: function(id) {
        var box = document.getElementById(id);
        var node;
        SelectBox.cache[id] = new Array();
        SelectBox.cache[id] = [];
        var cache = SelectBox.cache[id];
        for (var i = 0; (node = box.options[i]); i++) {
            cache.push({value: node.value, text: node.text, displayed: 1});
@@ -31,7 +32,7 @@ var SelectBox = {
        for (var i = 0; (node = SelectBox.cache[id][i]); i++) {
            node.displayed = 1;
            for (var j = 0; (token = tokens[j]); j++) {
                if (node.text.toLowerCase().indexOf(token) == -1) {
                if (node.text.toLowerCase().indexOf(token) === -1) {
                    node.displayed = 0;
                }
            }
@@ -41,13 +42,13 @@ var SelectBox = {
    delete_from_cache: function(id, value) {
        var node, delete_index = null;
        for (var i = 0; (node = SelectBox.cache[id][i]); i++) {
            if (node.value == value) {
            if (node.value === value) {
                delete_index = i;
                break;
            }
        }
        var j = SelectBox.cache[id].length - 1;
        for (var i = delete_index; i < j; i++) {
        for (i = delete_index; i < j; i++) {
            SelectBox.cache[id][i] = SelectBox.cache[id][i+1];
        }
        SelectBox.cache[id].length--;
@@ -59,7 +60,7 @@ var SelectBox = {
        // Check if an item is contained in the cache
        var node;
        for (var i = 0; (node = SelectBox.cache[id][i]); i++) {
            if (node.value == value) {
            if (node.value === value) {
                return true;
            }
        }
@@ -67,7 +68,6 @@ var SelectBox = {
    },
    move: function(from, to) {
        var from_box = document.getElementById(from);
        var to_box = document.getElementById(to);
        var option;
        for (var i = 0; (option = from_box.options[i]); i++) {
            if (option.selected && SelectBox.cache_contains(from, option.value)) {
@@ -80,7 +80,6 @@ var SelectBox = {
    },
    move_all: function(from, to) {
        var from_box = document.getElementById(from);
        var to_box = document.getElementById(to);
        var option;
        for (var i = 0; (option = from_box.options[i]); i++) {
            if (SelectBox.cache_contains(from, option.value)) {
@@ -111,4 +110,4 @@ var SelectBox = {
            box.options[i].selected = 'selected';
        }
    }
}
};
Loading