Skip to content

Commit

Permalink
Trim code via eslint.
Browse files Browse the repository at this point in the history
  • Loading branch information
cweijan committed Mar 5, 2024
1 parent c996057 commit 478dfe7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
31 changes: 31 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const typeScriptExtensions = ['.ts'];
module.exports = {
parser: '@typescript-eslint/parser',
extends: ['plugin:@typescript-eslint/recommended'],
plugins: ['unused-imports','eslint-plugin-import'],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
},
settings: {
'import/extensions': typeScriptExtensions,
'import/external-module-folders': ['node_modules', 'node_modules/@types'],
'import/parsers': {
'@typescript-eslint/parser': typeScriptExtensions,
},
'import/resolver': {
node: {
extensions: typeScriptExtensions,
},
},
},
rules: {
"unused-imports/no-unused-imports": "error",
"@typescript-eslint/no-var-requires": "off",
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-this-alias': 'off',
"@typescript-eslint/quotes": 'off'
},
};
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@
},
"scripts": {
"dev": "rimraf out && node build.js",
"lint:fix": "eslint src/**/*.ts --fix",
"build": "rimraf out && cd packages/zip-viewer && npm run build && cd ../.. && node build.js --mode=production",
"package": "vsce package --no-dependencies",
"publish": "vsce publish --no-dependencies",
Expand All @@ -515,8 +516,13 @@
"@types/node": "^17.0.23",
"@types/node-fetch": "^2.5.7",
"@types/vscode": "^1.64.0",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"esbuild": "^0.14.54",
"esbuild-plugin-copy": "^1.3.0",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-unused-imports": "^3.1.0",
"rimraf": "^3.0.2"
},
"dependencies": {
Expand All @@ -539,4 +545,4 @@
"puppeteer-core": "^1.20.0",
"vscode-html-to-docx": "^1.1.2"
}
}
}
4 changes: 2 additions & 2 deletions src/common/fileUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function writeFile(path: string, buffer: Buffer) {
}

export function adjustImgPath(uri: vscode.Uri, withworkspace: boolean = false) {
let imgPath = Global.getConfig<string>("pasterImgPath")
const imgPath = Global.getConfig<string>("pasterImgPath")
.replace("${fileName}", parse(uri.fsPath).name.replace(/\s/g, ''))
.replace("${now}", new Date().getTime() + "")
return {
Expand All @@ -30,7 +30,7 @@ export function adjustImgPath(uri: vscode.Uri, withworkspace: boolean = false) {
export function getWorkspacePath(uri: vscode.Uri): string {
const folders = vscode.workspace.workspaceFolders;
if (!folders || folders.length == 0) return '';
let workspacePath = folders[0]?.uri?.fsPath;
const workspacePath = folders[0]?.uri?.fsPath;
if (folders.length > 1) {
for (const folder of folders) {
if (uri.fsPath.includes(folder.uri.fsPath)) {
Expand Down
2 changes: 1 addition & 1 deletion src/provider/markdownEditorProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class MarkdownEditorProvider implements vscode.CustomTextEditorProvider {

private getFolders(): vscode.Uri[] {
const data = [];
for (var i = 65; i <= 90; i++) {
for (let i = 65; i <= 90; i++) {
data.push(vscode.Uri.file(`${String.fromCharCode(i)}:/`))
}
return data;
Expand Down
3 changes: 0 additions & 3 deletions src/provider/officeViewerProvider.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { ZipService } from '@/service/zip/zipService';
import axios from 'axios';
import { spawn } from 'child_process';
import { existsSync, mkdirSync, readdirSync, readFileSync } from 'fs';
import { tmpdir } from 'os';
import { basename, extname, parse, resolve } from 'path';
import { TextEncoder } from 'util';
import * as vscode from 'vscode';
import { workspace } from 'vscode';
import { Handler } from '../common/handler';
import { Output } from '../common/Output';
import { Util } from '../common/util';
import { ViewManager } from '@/common/viewManager';
import { Global } from '@/common/global';

/**
* support view office files
Expand Down
17 changes: 9 additions & 8 deletions src/service/markdownService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export class MarkdownService {
}

const uri = document.uri;
let { relPath, fullPath } = adjustImgPath(uri)
const info = adjustImgPath(uri), { fullPath } = info;
let { relPath } = info;
const imagePath = isAbsolute(fullPath) ? fullPath : `${dirname(uri.fsPath)}/${relPath}`.replace(/\\/g, "/");
this.createImgDir(imagePath);
this.saveClipboardImageToFileAndGetPath(imagePath, async (savedImagePath) => {
Expand All @@ -121,7 +122,7 @@ export class MarkdownService {
}
if (editor) {
editor?.edit(edit => {
let current = editor.selection;
const current = editor.selection;
if (current.isEmpty) {
edit.insert(current.start, `![${imgName}](${relPath})`);
} else {
Expand Down Expand Up @@ -158,7 +159,7 @@ export class MarkdownService {

private saveClipboardImageToFileAndGetPath(imagePath: string, cb: (value: string) => void) {
if (!imagePath) return;
let platform = process.platform;
const platform = process.platform;
if (platform === 'win32') {
// Windows
const scriptPath = path.join(this.context.extensionPath, '/lib/pc.ps1');
Expand All @@ -179,22 +180,22 @@ export class MarkdownService {
});
} else if (platform === 'darwin') {
// Mac
let scriptPath = path.join(this.context.extensionPath, './lib/mac.applescript');
let ascript = spawn('osascript', [scriptPath, imagePath]);
const scriptPath = path.join(this.context.extensionPath, './lib/mac.applescript');
const ascript = spawn('osascript', [scriptPath, imagePath]);
ascript.on('exit', function (code, signal) {
});
ascript.stdout.on('data', function (data) {
cb(data.toString().trim());
});
} else {
// Linux
let scriptPath = path.join(this.context.extensionPath, './lib/linux.sh');
const scriptPath = path.join(this.context.extensionPath, './lib/linux.sh');

let ascript = spawn('sh', [scriptPath, imagePath]);
const ascript = spawn('sh', [scriptPath, imagePath]);
ascript.on('exit', function (code, signal) {
});
ascript.stdout.on('data', function (data) {
let result = data.toString().trim();
const result = data.toString().trim();
if (result == "no xclip") {
vscode.window.showInformationMessage('You need to install xclip command first.');
return;
Expand Down

0 comments on commit 478dfe7

Please sign in to comment.