Skip to content

Commit

Permalink
Add one-variable-per-declaration tslint rule
Browse files Browse the repository at this point in the history
Multiple declarations per line makes it more difficult to read what
exactly is declared and generally makes code more verbose and less
likely to fill in types
  • Loading branch information
Tyriar committed Aug 5, 2017
1 parent 7d1c5d1 commit e6b431d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 58 deletions.
66 changes: 28 additions & 38 deletions src/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,12 @@ export class InputHandler implements IInputHandler {
* Insert Ps (Blank) Character(s) (default = 1) (ICH).
*/
public insertChars(params: number[]): void {
let param, row, j, ch;

param = params[0];
let param = params[0];
if (param < 1) param = 1;

row = this._terminal.buffer.y + this._terminal.buffer.ybase;
j = this._terminal.buffer.x;
ch = [this._terminal.eraseAttr(), ' ', 1]; // xterm
const row = this._terminal.buffer.y + this._terminal.buffer.ybase;
let j = this._terminal.buffer.x;
const ch = [this._terminal.eraseAttr(), ' ', 1]; // xterm

while (param-- && j < this._terminal.cols) {
this._terminal.buffer.lines.get(row).splice(j++, 0, ch);
Expand Down Expand Up @@ -325,9 +323,8 @@ export class InputHandler implements IInputHandler {
* Cursor Position [row;column] (default = [1,1]) (CUP).
*/
public cursorPosition(params: number[]): void {
let row, col;

row = params[0] - 1;
let col: number;
let row: number = params[0] - 1;

if (params.length >= 2) {
col = params[1] - 1;
Expand Down Expand Up @@ -439,14 +436,13 @@ export class InputHandler implements IInputHandler {
* Insert Ps Line(s) (default = 1) (IL).
*/
public insertLines(params: number[]): void {
let param, row, j;

param = params[0];
let param: number = params[0];
if (param < 1) {
param = 1;
}
row = this._terminal.buffer.y + this._terminal.buffer.ybase;
let row: number = this._terminal.buffer.y + this._terminal.buffer.ybase;

let j: number;
j = this._terminal.rows - 1 - this._terminal.buffer.scrollBottom;
j = this._terminal.rows - 1 + this._terminal.buffer.ybase - j + 1;

Expand Down Expand Up @@ -475,14 +471,13 @@ export class InputHandler implements IInputHandler {
* Delete Ps Line(s) (default = 1) (DL).
*/
public deleteLines(params: number[]): void {
let param, row, j;

param = params[0];
let param = params[0];
if (param < 1) {
param = 1;
}
row = this._terminal.buffer.y + this._terminal.buffer.ybase;
const row: number = this._terminal.buffer.y + this._terminal.buffer.ybase;

let j: number;
j = this._terminal.rows - 1 - this._terminal.buffer.scrollBottom;
j = this._terminal.rows - 1 + this._terminal.buffer.ybase - j;

Expand All @@ -509,15 +504,13 @@ export class InputHandler implements IInputHandler {
* Delete Ps Character(s) (default = 1) (DCH).
*/
public deleteChars(params: number[]): void {
let param, row, ch;

param = params[0];
let param: number = params[0];
if (param < 1) {
param = 1;
}

row = this._terminal.buffer.y + this._terminal.buffer.ybase;
ch = [this._terminal.eraseAttr(), ' ', 1]; // xterm
const row = this._terminal.buffer.y + this._terminal.buffer.ybase;
const ch = [this._terminal.eraseAttr(), ' ', 1]; // xterm

while (param--) {
this._terminal.buffer.lines.get(row).splice(this._terminal.buffer.x, 1);
Expand Down Expand Up @@ -558,16 +551,14 @@ export class InputHandler implements IInputHandler {
* Erase Ps Character(s) (default = 1) (ECH).
*/
public eraseChars(params: number[]): void {
let param, row, j, ch;

param = params[0];
let param = params[0];
if (param < 1) {
param = 1;
}

row = this._terminal.buffer.y + this._terminal.buffer.ybase;
j = this._terminal.buffer.x;
ch = [this._terminal.eraseAttr(), ' ', 1]; // xterm
const row = this._terminal.buffer.y + this._terminal.buffer.ybase;
let j = this._terminal.buffer.x;
const ch = [this._terminal.eraseAttr(), ' ', 1]; // xterm

while (param-- && j < this._terminal.cols) {
this._terminal.buffer.lines.get(row)[j++] = ch;
Expand Down Expand Up @@ -619,9 +610,9 @@ export class InputHandler implements IInputHandler {
* CSI Ps b Repeat the preceding graphic character Ps times (REP).
*/
public repeatPrecedingCharacter(params: number[]): void {
let param = params[0] || 1
, line = this._terminal.buffer.lines.get(this._terminal.buffer.ybase + this._terminal.buffer.y)
, ch = line[this._terminal.buffer.x - 1] || [this._terminal.defAttr, ' ', 1];
let param = params[0] || 1;
const line = this._terminal.buffer.lines.get(this._terminal.buffer.ybase + this._terminal.buffer.y);
const ch = line[this._terminal.buffer.x - 1] || [this._terminal.defAttr, ' ', 1];

while (param--) {
line[this._terminal.buffer.x++] = ch;
Expand Down Expand Up @@ -1203,14 +1194,13 @@ export class InputHandler implements IInputHandler {
return;
}

let l = params.length
, i = 0
, flags = this._terminal.curAttr >> 18
, fg = (this._terminal.curAttr >> 9) & 0x1ff
, bg = this._terminal.curAttr & 0x1ff
, p;
const l = params.length;
let flags = this._terminal.curAttr >> 18;
let fg = (this._terminal.curAttr >> 9) & 0x1ff;
let bg = this._terminal.curAttr & 0x1ff;
let p;

for (; i < l; i++) {
for (let i = 0; i < l; i++) {
p = params[i];
if (p >= 30 && p <= 37) {
// fg color 8
Expand Down
7 changes: 6 additions & 1 deletion src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ export class Parser {
* @param data The data to parse.
*/
public parse(data: string): ParserState {
let l = data.length, j, cs, ch, code, low;
const l = data.length;
let j;
let cs;
let ch;
let code;
let low;

if (this._terminal.debug) {
this._terminal.log('data: ' + data);
Expand Down
32 changes: 16 additions & 16 deletions src/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ const tangoColors = [
// Colors 0-15 + 16-255
// Much thanks to TooTallNate for writing this.
const defaultColors = (function() {
let colors = tangoColors.slice()
, r = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff]
, i;
let colors = tangoColors.slice();
let r = [0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff];
let i;

// 16-231
i = 0;
Expand Down Expand Up @@ -971,11 +971,11 @@ export class Terminal extends EventEmitter implements ITerminal {
}

function getButton(ev) {
let button
, shift
, meta
, ctrl
, mod;
let button;
let shift;
let meta;
let ctrl;
let mod;

// two low bits:
// 0 = left
Expand Down Expand Up @@ -1918,12 +1918,12 @@ export class Terminal extends EventEmitter implements ITerminal {
this.setOption('scrollback', y);
}

let line
, el
, i
, j
, ch
, addToY;
let line;
let el;
let i;
let j;
let ch;
let addToY;

if (x === this.cols && y === this.rows) {
// Check if we still need to measure the char size (fixes #785).
Expand Down Expand Up @@ -2426,8 +2426,8 @@ function wasMondifierKeyOnlyEvent(ev) {

function keys(obj) {
if (Object.keys) return Object.keys(obj);
let key, keys = [];
for (key in obj) {
const keys = [];
for (let key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
keys.push(key);
}
Expand Down
6 changes: 3 additions & 3 deletions src/handlers/Clipboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import * as Clipboard from './Clipboard';

describe('evaluatePastedTextProcessing', function () {
it('should replace carriage return + line feed with line feed on windows', function () {
const pastedText = 'foo\r\nbar\r\n',
processedText = Clipboard.prepareTextForTerminal(pastedText, false),
windowsProcessedText = Clipboard.prepareTextForTerminal(pastedText, true);
const pastedText = 'foo\r\nbar\r\n';
const processedText = Clipboard.prepareTextForTerminal(pastedText, false);
const windowsProcessedText = Clipboard.prepareTextForTerminal(pastedText, true);

assert.equal(processedText, 'foo\r\nbar\r\n');
assert.equal(windowsProcessedText, 'foo\rbar\r');
Expand Down
4 changes: 4 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
"no-eval": true,
"no-internal-module": true,
"no-trailing-whitespace": true,
"one-variable-per-declaration": [
true,
true
],
"no-unsafe-finally": true,
"no-var-keyword": true,
"quotemark": [
Expand Down

0 comments on commit e6b431d

Please sign in to comment.