Skip to content

Commit 34ded55

Browse files
author
Dmitriy Kubyshkin
committed
Cleaned up leaked global vars and added .jshintrc
1 parent a2ebcb2 commit 34ded55

File tree

5 files changed

+47
-33
lines changed

5 files changed

+47
-33
lines changed

.jshintrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"curly": true,
3+
"eqeqeq": true,
4+
"immed": true,
5+
"latedef": true,
6+
"newcap": true,
7+
"noarg": true,
8+
"sub": true,
9+
"expr": true,
10+
"undef": true,
11+
"unused": true,
12+
"boss": true,
13+
"eqnull": true,
14+
"devel": true,
15+
"node": true,
16+
"browser": true
17+
}

lib/CanvasTextEditor.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var FontMetrics = require('FontMetrics'),
99
* @constructor
1010
*/
1111
var CanvasTextEditor = function(doc, options) {
12-
this._document = doc || (new Document);
12+
this._document = doc || (new Document());
1313

1414
this.options = {
1515
textColor: 'WindowText',
@@ -24,7 +24,7 @@ var CanvasTextEditor = function(doc, options) {
2424
};
2525

2626
if (typeof options === 'object') {
27-
for(key in options) {
27+
for(var key in options) {
2828
this.options[key] = options[key];
2929
}
3030
}
@@ -133,8 +133,7 @@ CanvasTextEditor.prototype.selectionChange = function() {
133133

134134
// if it's not we put together selected text from document
135135
if (!this._selection.isEmpty()) {
136-
var ranges = this._selection.lineRanges(),
137-
line = '';
136+
var ranges = this._selection.lineRanges();
138137
for(var key in ranges) {
139138
selectedText += this._document.getLine(parseInt(key)).slice(
140139
ranges[key][0], ranges[key][1] === true ? undefined : ranges[key][1]
@@ -213,7 +212,9 @@ CanvasTextEditor.prototype.render = function() {
213212
selectionWidth = 0;
214213

215214
// Making sure we don't render something that we won't see
216-
if (lineCount < maxHeight) maxHeight = lineCount;
215+
if (lineCount < maxHeight) {
216+
maxHeight = lineCount;
217+
}
217218

218219
// Clearing previous iteration
219220
this.context.fillStyle = this.options.backgroundColor;
@@ -241,7 +242,7 @@ CanvasTextEditor.prototype.render = function() {
241242
topOffset,
242243
selectionWidth,
243244
lineHeight
244-
)
245+
);
245246

246247
// Restoring fill color for the text
247248
this.context.fillStyle = this.options.textColor;

lib/Document.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* @param {string} text Full document text.
55
* @constructor
66
*/
7-
Document = function(text) {
8-
text || (text = '');
7+
var Document = function(text) {
8+
text = text || '';
99
this.storage = Document.prepareText(text);
1010
};
1111

@@ -55,9 +55,9 @@ Document.prototype.getLine = function(index) {
5555
*/
5656
Document.prototype.getLength = function() {
5757
var sum = 0;
58-
for (var i = this.storage.length - 1; i >= 0; --i) {
59-
sum += this.storage[i].length
60-
};
58+
for(var i = this.storage.length - 1; i >= 0; --i) {
59+
sum += this.storage[i].length;
60+
}
6161
return sum;
6262
};
6363

@@ -67,8 +67,10 @@ Document.prototype.getLength = function() {
6767
* @return {string|undefined}
6868
*/
6969
Document.prototype.charAt = function(column, row) {
70-
var row = this.storage[row];
71-
if (row) return row.charAt(column);
70+
row = this.storage[row];
71+
if (row){
72+
return row.charAt(column);
73+
}
7274
};
7375

7476
/**
@@ -85,7 +87,9 @@ Document.prototype.insertText = function(text, column, row) {
8587
// First we calculate new column position because
8688
// text array will be changed in the process
8789
var newColumn = text[text.length - 1].length;
88-
if (text.length === 1) newColumn += column;
90+
if (text.length === 1) {
91+
newColumn += column;
92+
}
8993

9094
// append remainder of the current line to last line in new text
9195
text[text.length - 1] += this.storage[row].substr(column);
@@ -176,4 +180,4 @@ Document.prototype.deleteChar = function(forward, startColumn, startRow) {
176180
}
177181

178182
return this.deleteRange(startColumn, startRow, endColumn, endRow);
179-
};
183+
};

lib/Selection.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @param {Editor} editor.
44
* @constructor
55
*/
6-
Selection = function(editor, color) {
6+
var Selection = function(editor, color) {
77
this.editor = editor;
88
color || (color = '#000');
99

@@ -62,14 +62,16 @@ Selection.prototype.blink = function() {
6262
* @return {Array}
6363
*/
6464
Selection.prototype.lineRanges = function() {
65-
if (this.isEmpty()) return {};
65+
if (this.isEmpty()) {
66+
return {};
67+
}
6668
var ranges = {},
6769
character = this.start.character,
6870
line = this.start.line;
69-
for (; line <= this.end.line ; line++) {
71+
for(; line <= this.end.line ; line++) {
7072
ranges[line] = ([character, line !== this.end.line || this.end.character]);
7173
character = 0;
72-
};
74+
}
7375
return ranges;
7476
};
7577

@@ -186,7 +188,7 @@ Selection.prototype._doSetPosition = function(character, line, keepSelection) {
186188
// If this is a selection range
187189
if (keepSelection) {
188190

189-
compare = this.comparePosition({
191+
var compare = this.comparePosition({
190192
line: line,
191193
character: character
192194
}, this.start);
@@ -213,7 +215,7 @@ Selection.prototype._doSetPosition = function(character, line, keepSelection) {
213215
var temp = {
214216
line: this.start.line,
215217
character: this.start.character
216-
}
218+
};
217219
this.start.line = this.end.line;
218220
this.start.character = this.end.character;
219221
this.end.line = temp.line;
@@ -236,7 +238,7 @@ Selection.prototype.getPosition = function() {
236238
} else {
237239
return [this.start.character, this.start.line];
238240
}
239-
}
241+
};
240242

241243
/**
242244
* Moves up specified amount of lines.

scripts/build.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
var common = require('./common');
22
var fs = require('fs');
3-
var jsp = require("uglify-js").parser;
4-
var pro = require("uglify-js").uglify;
53

64
common.package.compile(function (err, source){
75
var dir = __dirname + '/../build';
@@ -14,12 +12,4 @@ common.package.compile(function (err, source){
1412
var path = dir + '/' + common.name + '.js';
1513
fs.writeFileSync(path, source);
1614
console.log('Developer version: ' + path.replace(__dirname + '/../', ''));
17-
18-
// And production one
19-
var minPath = dir + '/' + common.name + '.min.js';
20-
var ast = jsp.parse(source); // parse code and get the initial AST
21-
ast = pro.ast_mangle(ast); // get a new AST with mangled names
22-
ast = pro.ast_squeeze(ast); // get an AST with compression optimizations
23-
fs.writeFile(minPath, pro.gen_code(ast));
24-
console.log('Minified version: ' + minPath.replace(__dirname + '/../', ''));
25-
})
15+
});

0 commit comments

Comments
 (0)