Skip to content

Commit

Permalink
Fixed #22463 -- Added code style guide and JavaScript linting (Editor…
Browse files Browse the repository at this point in the history
…Config and ESLint)
  • Loading branch information
treyhunner authored and timgraham committed Jun 27, 2015
1 parent 1e63652 commit ec4f219
Show file tree
Hide file tree
Showing 26 changed files with 1,007 additions and 842 deletions.
37 changes: 37 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/{*.min,jquery}.js
django/contrib/gis/templates/**/*.js
node_modules/**.js
51 changes: 51 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"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
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ MANIFEST
dist/
docs/_build/
docs/locale/
node_modules/
tests/coverage_html/
tests/.coverage
build/
17 changes: 8 additions & 9 deletions django/contrib/admin/static/admin/js/SelectBox.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/*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});
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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--;
Expand All @@ -59,15 +60,14 @@ 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;
}
}
return false;
},
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)) {
Expand All @@ -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)) {
Expand Down Expand Up @@ -111,4 +110,4 @@ var SelectBox = {
box.options[i].selected = 'selected';
}
}
}
};
Loading

0 comments on commit ec4f219

Please sign in to comment.