Browse Source

update linters (#358)

pull/362/head
Cian Butler 3 years ago
committed by GitHub
parent
commit
eb0e7cab23
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      .eslintrc.json
  2. 22
      package.json
  3. 4
      src/buffer.ts
  4. 4
      src/client/dev.ts
  5. 12
      src/client/wetty/download.ts
  6. 5
      src/client/wetty/shared/type.ts
  7. 37
      src/client/wetty/term.ts
  8. 6
      src/client/wetty/term/confiruragtion.ts
  9. 4
      src/client/wetty/term/confiruragtion/editor.ts
  10. 2
      src/client/wetty/term/confiruragtion/load.ts
  11. 4
      src/main.ts
  12. 8
      src/server/socketServer/html.ts
  13. 2
      src/server/spawn.ts
  14. 2
      tsconfig.json
  15. 1177
      yarn.lock

3
.eslintrc.json

@ -10,8 +10,7 @@
"extends": [
"airbnb-base",
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint"
"prettier"
],
"rules": {
"linebreak-style": ["error", "unix"],

22
package.json

@ -60,7 +60,7 @@
]
},
"snowpack": {
"installOptions": {
"packageOptions": {
"sourceMap": true,
"installTypes": true
},
@ -100,6 +100,7 @@
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^1.2.25",
"@fortawesome/free-solid-svg-icons": "^5.11.2",
"@snowpack/plugin-run-script": "^2.3.0",
"compression": "^1.7.4",
"etag": "^1.8.1",
"express": "^4.17.1",
@ -140,17 +141,18 @@
"@types/sinon": "^7.5.1",
"@types/socket.io": "^2.1.11",
"@types/socket.io-client": "^1.4.33",
"@types/toastify-js": "^1.9.2",
"@types/winston": "^2.4.4",
"@types/yargs": "^15.0.5",
"@typescript-eslint/eslint-plugin": "^2.5.0",
"@typescript-eslint/parser": "^4.3.0",
"@typescript-eslint/eslint-plugin": "^4.29.3",
"@typescript-eslint/parser": "^4.29.3",
"all-contributors-cli": "^6.17.2",
"chai": "^4.2.0",
"concurrently": "^5.2.0",
"eslint": "^7.8.1",
"eslint-config-airbnb-base": "^14.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-import-resolver-typescript": "^2.3.0",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-mocha": "^8.0.0",
"eslint-plugin-prettier": "^3.1.4",
@ -160,11 +162,11 @@
"lint-staged": "^10.2.13",
"mocha": "^8.1.3",
"nodemon": "^2.0.4",
"prettier": "^2.1.1",
"prettier": "^2.3.2",
"sinon": "^7.5.0",
"snowpack": "^2.10.1",
"snowpack": "^3.8.7",
"ts-node": "^9.0.0",
"typescript": "^4.0.3"
"typescript": "^4.3.5"
},
"contributors": [
"Krishna Srinivas <krishna.srinivas@gmail.com>",

4
src/buffer.ts

@ -7,8 +7,8 @@ function ask(question: string): Promise<string> {
input: process.stdin,
output: process.stdout,
});
return new Promise((resolve) => {
rlp.question(`${question}: `, (answer) => {
return new Promise(resolve => {
rlp.question(`${question}: `, answer => {
rlp.close();
resolve(answer);
});

4
src/client/dev.ts

@ -1,5 +1,5 @@
caches.keys().then((cacheNames) => {
cacheNames.forEach((cacheName) => {
caches.keys().then(cacheNames => {
cacheNames.forEach(cacheName => {
caches.delete(cacheName);
});
});

12
src/client/wetty/download.ts

@ -1,10 +1,11 @@
// @ts-ignore
import Toastify from 'toastify-js';
import fileType from 'file-type';
const DEFAULT_FILE_BEGIN = '\u001b[5i';
const DEFAULT_FILE_END = '\u001b[4i';
type OnCompleteFile = (bufferCharacters: string) => void;
function onCompleteFile(bufferCharacters: string): void {
let fileCharacters = bufferCharacters;
// Try to decode it as base64, if it fails we assume it's not base64
@ -61,10 +62,10 @@ export class FileDownloader {
fileBegin: string;
fileEnd: string;
partialFileBegin: string;
onCompleteFileCallback: Function;
onCompleteFileCallback: OnCompleteFile;
constructor(
onCompleteFileCallback: Function = onCompleteFile,
onCompleteFileCallback: OnCompleteFile = onCompleteFile,
fileBegin: string = DEFAULT_FILE_BEGIN,
fileEnd: string = DEFAULT_FILE_END,
) {
@ -92,9 +93,8 @@ export class FileDownloader {
}
// We're currently in the state of buffering a beginner marker...
const nextExpectedCharacter = this.fileBegin[
this.partialFileBegin.length
];
const nextExpectedCharacter =
this.fileBegin[this.partialFileBegin.length];
// If the next character *is* the next character in the fileBegin sequence.
if (character === nextExpectedCharacter) {
this.partialFileBegin += character;

5
src/client/wetty/shared/type.ts

@ -1,5 +0,0 @@
import { Terminal } from 'xterm';
export class Term extends Terminal {
resizeTerm(): void {}
}

37
src/client/wetty/term.ts

@ -1,29 +1,36 @@
import type { Socket } from 'socket.io-client';
import _ from 'lodash';
import { WebLinksAddon } from 'xterm-addon-web-links';
import { FitAddon } from 'xterm-addon-fit';
import { Terminal } from 'xterm';
import type { Term } from './shared/type';
import { Terminal } from 'xterm';
import { FitAddon } from 'xterm-addon-fit';
import { WebLinksAddon } from 'xterm-addon-web-links';
import { configureTerm, shouldFitTerm } from './term/confiruragtion.js';
import { terminal as termElement } from '../shared/elements.js';
export class Term extends Terminal {
socket: typeof Socket;
fitAddon: FitAddon;
constructor(socket: typeof Socket) {
super();
this.socket = socket;
this.fitAddon = new FitAddon();
this.loadAddon(this.fitAddon);
this.loadAddon(new WebLinksAddon());
}
resizeTerm(): void {
this.refresh(0, this.rows - 1);
if (shouldFitTerm()) this.fitAddon.fit();
this.socket.emit('resize', { cols: this.cols, rows: this.rows });
}
}
export function terminal(socket: typeof Socket): Term | undefined {
const term = new Terminal() as Term;
const term = new Term(socket) as Term;
if (_.isNull(termElement)) return undefined;
const webLinksAddon = new WebLinksAddon();
term.loadAddon(webLinksAddon);
const fitAddon = new FitAddon();
term.loadAddon(fitAddon);
term.open(termElement);
term.resizeTerm = () => {
term.refresh(0, term.rows - 1);
if (shouldFitTerm()) fitAddon.fit();
socket.emit('resize', { cols: term.cols, rows: term.rows });
};
configureTerm(term);
window.onresize = term.resizeTerm;
(window as any).wetty_term = term;
return term;
}

6
src/client/wetty/term/confiruragtion.ts

@ -1,6 +1,4 @@
import _ from 'lodash';
import type { Term } from '../shared/type';
import type { Term } from '../term';
import { copySelected, copyShortcut } from './confiruragtion/clipboard';
import { onInput, setOptions } from './confiruragtion/editor';
import { editor } from '../../shared/elements';
@ -37,7 +35,7 @@ export function configureTerm(term: Term): void {
editorOnLoad();
editor.addEventListener('load', editorOnLoad);
toggle.addEventListener('click', (e) => {
toggle.addEventListener('click', e => {
(editor.contentWindow as any).loadOptions(loadOptions());
optionsElem.classList.toggle('opened');
e.preventDefault();

4
src/client/wetty/term/confiruragtion/editor.ts

@ -1,4 +1,4 @@
import type { Term } from '../../shared/type';
import type { Term } from '../../term';
import { editor } from '../../../shared/elements';
export const onInput = (term: Term, updated: any) => {
@ -23,7 +23,7 @@ export const onInput = (term: Term, updated: any) => {
};
export function setOptions(term: Term, options: any) {
Object.keys(options.xterm).forEach((key) => {
Object.keys(options.xterm).forEach(key => {
if (key === 'cols' || key === 'rows') return;
const value = options.xterm[key];
term.setOption(key, value);

2
src/client/wetty/term/confiruragtion/load.ts

@ -1,6 +1,6 @@
import _ from 'lodash';
export function loadOptions(): object {
export function loadOptions(): Record<string, unknown> {
const defaultOptions = { xterm: { fontSize: 14 } };
try {
return _.isUndefined(localStorage.options)

4
src/main.ts

@ -101,8 +101,8 @@ const opts = yargs
if (!opts.help) {
loadConfigFile(opts.conf)
.then((config) => mergeCliConf(opts, config))
.then((conf) =>
.then(config => mergeCliConf(opts, config))
.then(conf =>
start(conf.ssh, conf.server, conf.command, conf.forceSSH, conf.ssl),
)
.catch((err: Error) => {

8
src/server/socketServer/html.ts

@ -18,7 +18,7 @@ const render = (
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<link rel="icon" type="image/x-icon" href="${favicon}">
<title>${title}</title>
${css.map((file) => `<link rel="stylesheet" href="${file}" />`).join('\n')}
${css.map(file => `<link rel="stylesheet" href="${file}" />`).join('\n')}
</head>
<body>
<div id="overlay">
@ -36,7 +36,7 @@ const render = (
</div>
<div id="terminal"></div>
${js
.map((file) => `<script type="module" src="${file}"></script>`)
.map(file => `<script type="module" src="${file}"></script>`)
.join('\n')}
</body>
</html>`;
@ -49,8 +49,8 @@ export const html = (base: string, title: string): RequestHandler => (
render(
title,
`${base}/favicon.ico`,
cssFiles.map((css) => `${base}/assets/css/${css}.css`),
jsFiles.map((js) => `${base}/client/${js}.js`),
cssFiles.map(css => `${base}/assets/css/${css}.css`),
jsFiles.map(js => `${base}/client/${js}.js`),
`${base}/assets/xterm_config/index.html`,
),
);

2
src/server/spawn.ts

@ -30,7 +30,7 @@ export function spawn(socket: SocketIO.Socket, args: string[]): void {
.on('resize', ({ cols, rows }) => {
term.resize(cols, rows);
})
.on('input', (input) => {
.on('input', input => {
if (!isUndefined(term)) term.write(input);
})
.on('disconnect', () => {

2
tsconfig.json

@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "esnext",
"module": "es2020",
"target": "es2019",
"moduleResolution": "node",
"declaration": true,

1177
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save