Skip to content

Commit

Permalink
Merge pull request #3133 from coderaiser/lint/putout
Browse files Browse the repository at this point in the history
Using putout linter on xterm codebase part 2
  • Loading branch information
Tyriar authored Nov 2, 2020
2 parents 02e4db4 + c6f1b45 commit 38e81f0
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 33 deletions.
4 changes: 2 additions & 2 deletions bin/extract_vtfeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ function empty(ar) {
}

function* parseMultiLineGen(filename, s) {
if (!~s.indexOf('@vt:')) {
if (!s.includes('@vt:')) {
return;
}
const lines = s.split('\n').map(el => el.trim().replace(/[*]/, '').replace(/\s/, ''));
Expand Down Expand Up @@ -413,7 +413,7 @@ function parseSingleLine(filename, s) {
const line = s.trim();
const match = line.match(REX_VT_LINE);
if (match !== null) {
if (!~TYPES.indexOf(match[2])) {
if (!TYPES.includes(match[2])) {
throw new Error(`unkown vt-command type "${match[2]}" specified in "${filename}"`);
}
return {
Expand Down
4 changes: 2 additions & 2 deletions bin/install-addons.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (fs.existsSync(addonsPath)) {

// walk all addon folders
fs.readdir(addonsPath, (err, files) => {
files.forEach(folder => {
for (const folder of files) {
const addonPath = path.join(addonsPath, folder);

// install only if there are dependencies listed
Expand All @@ -51,6 +51,6 @@ if (fs.existsSync(addonsPath)) {
} else {
console.log('Skipped', folder);
}
});
}
});
}
10 changes: 5 additions & 5 deletions bin/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const path = require('path');
// Setup auth
fs.writeFileSync(`${process.env['HOME']}/.npmrc`, `//registry.npmjs.org/:_authToken=${process.env['NPM_AUTH_TOKEN']}`);

const isDryRun = process.argv.indexOf('--dry') !== -1;
const isDryRun = process.argv.includes('--dry');
if (isDryRun) {
console.log('Publish dry run');
}
Expand All @@ -36,13 +36,13 @@ const addonPackageDirs = [
path.resolve(__dirname, '../addons/xterm-addon-webgl')
];
console.log(`Checking if addons need to be published`);
addonPackageDirs.forEach(p => {
for (const p of addonPackageDirs) {
const addon = path.basename(p);
if (changedFiles.some(e => e.indexOf(addon) !== -1)) {
if (changedFiles.some(e => e.includes(addon))) {
console.log(`Try publish ${addon}`);
checkAndPublishPackage(p);
}
});
}

// Publish website if it's a stable release
if (isStableRelease) {
Expand All @@ -54,7 +54,7 @@ function checkAndPublishPackage(packageDir) {

// Determine if this is a stable or beta release
const publishedVersions = getPublishedVersions(packageJson);
const isStableRelease = publishedVersions.indexOf(packageJson.version) === -1;
const isStableRelease = !publishedVersions.includes(packageJson.version);

// Get the next version
let nextVersion = isStableRelease ? packageJson.version : getNextBetaVersion(packageJson);
Expand Down
10 changes: 5 additions & 5 deletions bin/test_mousemodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ function evalButtonCode(code) {
if (code & 64) {
button |= 4
}
let actionS = 'press';
let action = 'press';
let buttonS = reverseButtons[button];
if (button === 3) {
buttonS = '<none>';
actionS = 'release';
action = 'release';
}
if (move) {
actionS = 'move';
action = 'move';
} else if (4 <= button && button <= 7) {
buttonS = 'wheel';
actionS = button === 4 ? 'up' : button === 5 ? 'down' : button === 6 ? 'left' : 'right';
action = button === 4 ? 'up' : button === 5 ? 'down' : button === 6 ? 'left' : 'right';
}
return {button: buttonS, action: actionS, modifier};
return {button: buttonS, action, modifier};
}

// protocols
Expand Down
4 changes: 2 additions & 2 deletions src/browser/Terminal2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (os.platform() === 'darwin') {
);
}
// filter skipFilenames
const FILES = TESTFILES.filter(value => SKIP_FILES.indexOf(value.split('/').slice(-1)[0]) === -1);
const FILES = TESTFILES.filter(value => !SKIP_FILES.includes(value.split('/').slice(-1)[0]));

describe('Escape Sequence Files', function(): void {
this.timeout(1000);
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('Escape Sequence Files', function(): void {
function formatError(input: string, output: string, expected: string): string {
function addLineNumber(start: number, color: string): (s: string) => string {
let counter = start || 0;
return function(s: string): string {
return (s: string): string => {
counter += 1;
return '\x1b[33m' + (' ' + counter).slice(-2) + color + s;
};
Expand Down
1 change: 1 addition & 0 deletions src/browser/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"lib": [
"dom",
"es2015",
"es2016.Array.Include"
],
"outDir": "../../out",
"types": [
Expand Down
2 changes: 1 addition & 1 deletion src/common/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const isNode = (typeof navigator === 'undefined') ? true : false;
const userAgent = (isNode) ? 'node' : navigator.userAgent;
const platform = (isNode) ? 'node' : navigator.platform;

export const isFirefox = !!~userAgent.indexOf('Firefox');
export const isFirefox = userAgent.includes('Firefox');
export const isSafari = /^((?!chrome|android).)*safari/i.test(userAgent);

// Find the users platform. We use this to interpret the meta key
Expand Down
24 changes: 12 additions & 12 deletions src/common/buffer/Buffer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ describe('Buffer', () => {
}
const wrappedLines: number[] = [];
for (let i = 0; i < buffer.lines.length; i++) {
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.indexOf(i) !== -1, `line ${i} isWrapped must equal ${wrappedLines.indexOf(i) !== -1}`);
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.includes(i), `line ${i} isWrapped must equal ${wrappedLines.includes(i)}`);
}
});
});
Expand All @@ -723,7 +723,7 @@ describe('Buffer', () => {
}
const wrappedLines: number[] = [];
for (let i = 0; i < buffer.lines.length; i++) {
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.indexOf(i) !== -1, `line ${i} isWrapped must equal ${wrappedLines.indexOf(i) !== -1}`);
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.includes(i), `line ${i} isWrapped must equal ${wrappedLines.includes(i)}`);
}
});
});
Expand Down Expand Up @@ -754,7 +754,7 @@ describe('Buffer', () => {
}
const wrappedLines: number[] = [];
for (let i = 0; i < buffer.lines.length; i++) {
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.indexOf(i) !== -1, `line ${i} isWrapped must equal ${wrappedLines.indexOf(i) !== -1}`);
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.includes(i), `line ${i} isWrapped must equal ${wrappedLines.includes(i)}`);
}
});
});
Expand All @@ -777,7 +777,7 @@ describe('Buffer', () => {
}
const wrappedLines: number[] = [];
for (let i = 0; i < buffer.lines.length; i++) {
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.indexOf(i) !== -1, `line ${i} isWrapped must equal ${wrappedLines.indexOf(i) !== -1}`);
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.includes(i), `line ${i} isWrapped must equal ${wrappedLines.includes(i)}`);
}
});
});
Expand Down Expand Up @@ -814,7 +814,7 @@ describe('Buffer', () => {
}
const wrappedLines: number[] = [];
for (let i = 0; i < buffer.lines.length; i++) {
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.indexOf(i) !== -1, `line ${i} isWrapped must equal ${wrappedLines.indexOf(i) !== -1}`);
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.includes(i), `line ${i} isWrapped must equal ${wrappedLines.includes(i)}`);
}
});
});
Expand All @@ -837,7 +837,7 @@ describe('Buffer', () => {
}
const wrappedLines: number[] = [];
for (let i = 0; i < buffer.lines.length; i++) {
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.indexOf(i) !== -1, `line ${i} isWrapped must equal ${wrappedLines.indexOf(i) !== -1}`);
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.includes(i), `line ${i} isWrapped must equal ${wrappedLines.includes(i)}`);
}
});
});
Expand Down Expand Up @@ -891,7 +891,7 @@ describe('Buffer', () => {
}
const wrappedLines = [1, 3, 5];
for (let i = 0; i < buffer.lines.length; i++) {
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.indexOf(i) !== -1, `line ${i} isWrapped must equal ${wrappedLines.indexOf(i) !== -1}`);
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.includes(i), `line ${i} isWrapped must equal ${wrappedLines.includes(i)}`);
}
});
});
Expand All @@ -917,7 +917,7 @@ describe('Buffer', () => {
}
const wrappedLines = [1, 3, 5];
for (let i = 0; i < buffer.lines.length; i++) {
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.indexOf(i) !== -1, `line ${i} isWrapped must equal ${wrappedLines.indexOf(i) !== -1}`);
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.includes(i), `line ${i} isWrapped must equal ${wrappedLines.includes(i)}`);
}
});
});
Expand Down Expand Up @@ -950,7 +950,7 @@ describe('Buffer', () => {
}
const wrappedLines = [11, 13, 15];
for (let i = 0; i < buffer.lines.length; i++) {
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.indexOf(i) !== -1, `line ${i} isWrapped must equal ${wrappedLines.indexOf(i) !== -1}`);
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.includes(i), `line ${i} isWrapped must equal ${wrappedLines.includes(i)}`);
}
});
});
Expand All @@ -975,7 +975,7 @@ describe('Buffer', () => {
}
const wrappedLines = [11, 13, 15];
for (let i = 0; i < buffer.lines.length; i++) {
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.indexOf(i) !== -1, `line ${i} isWrapped must equal ${wrappedLines.indexOf(i) !== -1}`);
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.includes(i), `line ${i} isWrapped must equal ${wrappedLines.includes(i)}`);
}
});
});
Expand Down Expand Up @@ -1014,7 +1014,7 @@ describe('Buffer', () => {
}
const wrappedLines = [8, 10, 12];
for (let i = 0; i < buffer.lines.length; i++) {
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.indexOf(i) !== -1, `line ${i} isWrapped must equal ${wrappedLines.indexOf(i) !== -1}`);
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.includes(i), `line ${i} isWrapped must equal ${wrappedLines.includes(i)}`);
}
});
});
Expand All @@ -1040,7 +1040,7 @@ describe('Buffer', () => {
}
const wrappedLines = [8, 10, 12];
for (let i = 0; i < buffer.lines.length; i++) {
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.indexOf(i) !== -1, `line ${i} isWrapped must equal ${wrappedLines.indexOf(i) !== -1}`);
assert.equal(buffer.lines.get(i)!.isWrapped, wrappedLines.includes(i), `line ${i} isWrapped must equal ${wrappedLines.includes(i)}`);
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/common/input/UnicodeV6.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ it('wcwidth should match all values from the old implementation', function(): vo
// ==> n = n >> m e.g. m=12 000000000000FFEEDDCCBBAA99887766
// we are only interested in 2 LSBs, cut off higher bits
// ==> n = n & 3 e.g. 000000000000000000000000000000XX
return function (num: number): number {
return (num: number): number => {
num = num | 0; // get asm.js like optimization under V8
if (num < 32) {
return control | 0;
Expand Down
4 changes: 2 additions & 2 deletions src/common/services/OptionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class OptionsService implements IOptionsService {
if (!(key in DEFAULT_OPTIONS)) {
throw new Error('No option with key "' + key + '"');
}
if (CONSTRUCTOR_ONLY_OPTIONS.indexOf(key) !== -1) {
if (CONSTRUCTOR_ONLY_OPTIONS.includes(key)) {
throw new Error(`Option "${key}" can only be set in the constructor`);
}
if (this.options[key] === value) {
Expand Down Expand Up @@ -123,7 +123,7 @@ export class OptionsService implements IOptionsService {
// already valid numeric value
break;
}
value = FONT_WEIGHT_OPTIONS.indexOf(value) !== -1 ? value : DEFAULT_OPTIONS[key];
value = FONT_WEIGHT_OPTIONS.includes(value) ? value : DEFAULT_OPTIONS[key];
break;
case 'cursorWidth':
value = Math.floor(value);
Expand Down
3 changes: 2 additions & 1 deletion src/common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "../tsconfig-library-base",
"compilerOptions": {
"lib": [
"es2015"
"es2015",
"es2016.Array.Include"
],
"outDir": "../../out",
"types": [
Expand Down

0 comments on commit 38e81f0

Please sign in to comment.