Skip to content

Commit

Permalink
fix eslint config & linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vquelque committed Jun 3, 2024
1 parent 238a367 commit 875813c
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 38 deletions.
8 changes: 8 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @ts-check
import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
);
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,23 @@
"watch": "tsc -watch -p ./",
"copy-files": "cp -r ./src/test/example ./out/test",
"pretest": "yarn run compile && yarn run lint && yarn run copy-files",
"lint": "eslint src --ext ts",
"lint": "eslint src",
"test": "node ./out/test/runTest.js",
"prettify": "prettier . --write"
},
"devDependencies": {
"@eslint/js": "^9.4.0",
"@types/eslint__js": "^8.42.3",
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.1",
"@types/node": "20.x",
"@types/vscode": "^1.76.0",
"@typescript-eslint/eslint-plugin": "^7.11.x",
"@typescript-eslint/parser": "^7.11.x",
"@vscode/test-electron": "^2.2.3",
"eslint": "^9.4.0",
"glob": "^8.1.0",
"mocha": "^10.2.0",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"typescript-eslint": "^7.11.0"
},
"repository": {
"type": "git",
Expand Down
28 changes: 14 additions & 14 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function activate(context: vscode.ExtensionContext) {
storage = context.workspaceState;
if (!storage) {
vscode.window.showInformationMessage(
"Please create a workspace to save the marked files"
"Please create a workspace to save the marked files",
);
}
//initialize output channel
Expand All @@ -20,37 +20,37 @@ export function activate(context: vscode.ExtensionContext) {
//register the decoration provider
provider = new DecorationProvider();
context.subscriptions.push(
vscode.window.registerFileDecorationProvider(provider)
vscode.window.registerFileDecorationProvider(provider),
);

context.subscriptions.push(
vscode.commands.registerCommand(
"markfiles.markUnmarkActiveFile",
async (contextUri: vscode.Uri) => {
async () => {
const uri = vscode.window.activeTextEditor?.document.uri;
if (uri) {
provider.markOrUnmarkFiles([uri]);
}
}
)
},
),
);

context.subscriptions.push(
vscode.commands.registerCommand(
"markfiles.writeMarkedFilesToDisk",
async () => {
await provider.exportMarkedFilesToFile();
}
)
},
),
);

context.subscriptions.push(
vscode.commands.registerCommand(
"markfiles.markUnmarkSelectedFile",
async (clickedFile: vscode.Uri, selectedFiles: vscode.Uri[]) => {
provider.markOrUnmarkFiles(selectedFiles);
}
)
},
),
);

context.subscriptions.push(
Expand All @@ -59,10 +59,10 @@ export function activate(context: vscode.ExtensionContext) {
async () => {
provider.loadFromScopeFile(true);
vscode.window.showInformationMessage(
"Loading marked files from scope file(s)"
"Loading marked files from scope file(s)",
);
}
)
},
),
);

context.subscriptions.push(
Expand All @@ -71,7 +71,7 @@ export function activate(context: vscode.ExtensionContext) {
if (e.affectsConfiguration("markfiles")) {
provider.configChanged();
}
})
}),
);

context.subscriptions.push(
Expand All @@ -83,7 +83,7 @@ export function activate(context: vscode.ExtensionContext) {
for (const file of rename.files) {
provider.handleFileRename(file.oldUri, file.newUri);
}
})
}),
);
return context;
}
Expand Down
29 changes: 17 additions & 12 deletions src/fileDecorationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export class DecorationProvider implements FileDecorationProvider {
}
}

provideFileDecoration(uri: Uri, token: CancellationToken): FileDecoration | undefined {
provideFileDecoration(
uri: Uri,
token: CancellationToken,
): FileDecoration | undefined {
if (token.isCancellationRequested) {
return;
}
Expand All @@ -56,13 +59,14 @@ export class DecorationProvider implements FileDecorationProvider {
uris.forEach(async (uri) => {
const stat = await workspace.fs.stat(uri);
switch (stat.type) {
case FileType.Directory:
case FileType.Directory: {
// recurse
const files = (await workspace.fs.readDirectory(uri)).map((tu) =>
Uri.parse(`${uri}/${tu[0]}`)
Uri.parse(`${uri}/${tu[0]}`),
);
return this.markOrUnmarkFiles(files);
case FileType.File:
}
case FileType.File: {
const fPath = uri.fsPath;
if (this.markedFiles.has(uri.fsPath)) {
this.markedFiles.delete(fPath);
Expand All @@ -73,6 +77,7 @@ export class DecorationProvider implements FileDecorationProvider {
}
this._onDidChangeFileDecorations.fire(uri);
return;
}
default:
return;
}
Expand All @@ -87,7 +92,7 @@ export class DecorationProvider implements FileDecorationProvider {
const confirm = await window.showInformationMessage(
"This operation will clear all marked files. Do you want to continue?",
"Yes",
"No"
"No",
);
if (confirm === "No") {
//abort
Expand All @@ -105,16 +110,16 @@ export class DecorationProvider implements FileDecorationProvider {

public async configChanged() {
this.markedFiles.forEach((markedFile) =>
this._onDidChangeFileDecorations.fire(Uri.file(markedFile))
this._onDidChangeFileDecorations.fire(Uri.file(markedFile)),
);
}

async loadMarkedFiles(scopeUri: string, projectRootUri: string) {
let patterns = (await asyncReadFile(scopeUri)) || [];
const patterns = (await asyncReadFile(scopeUri)) || [];
const ig = ignore().add(patterns);
// find files in all workspace folders, and filter them according to the specified gitignore patterns
// https://git-scm.com/docs/gitignore
let markedAbsPath = (await workspace.findFiles("**/*"))
const markedAbsPath = (await workspace.findFiles("**/*"))
.map((uri) => path.relative(projectRootUri, uri.fsPath))
.filter((relPath) => ig.ignores(relPath))
.map((relPath) => Uri.file(path.resolve(projectRootUri, relPath)));
Expand All @@ -135,7 +140,7 @@ export class DecorationProvider implements FileDecorationProvider {
}
const scopeFileUrisByFolder = this.getFileURIsByFolderForWS(
fileName,
"txt"
"txt",
);
if (!Object.keys(scopeFileUrisByFolder).length) {
printChannelOutput("No opened project - aborting");
Expand Down Expand Up @@ -166,7 +171,7 @@ export class DecorationProvider implements FileDecorationProvider {
const confirm = await window.showInformationMessage(
"This operation will overwrite the existing scope file. Do you want to continue?",
"Yes",
"No"
"No",
);
if (confirm === "No") {
//abort
Expand All @@ -179,7 +184,7 @@ export class DecorationProvider implements FileDecorationProvider {
writeFile(path, markedFiles, { flag: "w" }, (err) => {
if (err) {
console.error(
`markfiles: Failed to write scope file with path ${path}. Err: ${err}`
`markfiles: Failed to write scope file with path ${path}. Err: ${err}`,
);
}
});
Expand Down Expand Up @@ -226,7 +231,7 @@ export class DecorationProvider implements FileDecorationProvider {
const scopeFilesByProjectRootsURIs: { [scopeUri: string]: string } = {};
//iterate over all opened workspace folders
const rootFolders = workspace.workspaceFolders?.map(
(folder) => folder.uri.path
(folder) => folder.uri.path,
);
if (!rootFolders) {
return {};
Expand Down
8 changes: 4 additions & 4 deletions src/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import * as path from "path";
import * as fs from "fs";

const packageJSON = JSON.parse(
fs.readFileSync(path.join(__dirname, "../../package.json"), "utf-8")
fs.readFileSync(path.join(__dirname, "../../package.json"), "utf-8"),
) as { name: string; publisher: string };

export const extension = vscode.extensions.getExtension(
`${packageJSON.publisher}.${packageJSON.name}`
`${packageJSON.publisher}.${packageJSON.name}`,
)! as vscode.Extension<any>;

assert.ok(extension);

export async function createTestFile(
fileName: string,
content: string = ""
content: string = "",
): Promise<void> {
const filePath = path.join(
vscode.workspace.workspaceFolders![0].uri.fsPath,
fileName
fileName,
);
fs.writeFileSync(filePath, content);
const uri = vscode.Uri.file(filePath);
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function asyncReadFile(path: string) {
return arr;
} catch (err) {
console.error(
`markfiles: Failed to read file with path ${path} from disk. err: ${err}`
`markfiles: Failed to read file with path ${path} from disk. err: ${err}`,
);
}
}
40 changes: 37 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
minimatch "^3.1.2"
strip-json-comments "^3.1.1"

"@eslint/[email protected]":
"@eslint/[email protected]", "@eslint/js@^9.4.0":
version "9.4.0"
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-9.4.0.tgz#96a2edd37ec0551ce5f9540705be23951c008a0c"
integrity sha512-fdI7VJjP3Rvc70lC4xkFXHB0fiPeojiL1PxVG6t1ZvXQrarj893PweuBTujxDUFk0Fxj4R7PIIAZ/aiiyZPZcg==
Expand Down Expand Up @@ -79,6 +79,26 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@types/eslint@*":
version "8.56.10"
resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-8.56.10.tgz#eb2370a73bf04a901eeba8f22595c7ee0f7eb58d"
integrity sha512-Shavhk87gCtY2fhXDctcfS3e6FdxWkCx1iUZ9eEUbh7rTqlZT0/IzOkCOVt0fCjcFuZ9FPYfuezTBImfHCDBGQ==
dependencies:
"@types/estree" "*"
"@types/json-schema" "*"

"@types/eslint__js@^8.42.3":
version "8.42.3"
resolved "https://registry.yarnpkg.com/@types/eslint__js/-/eslint__js-8.42.3.tgz#d1fa13e5c1be63a10b4e3afe992779f81c1179a0"
integrity sha512-alfG737uhmPdnvkrLdZLcEKJ/B8s9Y4hrZ+YAdzUeoArBlSUERA2E87ROfOaS4jd/C45fzOoZzidLc1IPwLqOw==
dependencies:
"@types/eslint" "*"

"@types/estree@*":
version "1.0.5"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4"
integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==

"@types/glob@^8.1.0":
version "8.1.0"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-8.1.0.tgz#b63e70155391b0584dce44e7ea25190bbc38f2fc"
Expand All @@ -87,6 +107,11 @@
"@types/minimatch" "^5.1.2"
"@types/node" "*"

"@types/json-schema@*":
version "7.0.15"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841"
integrity sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==

"@types/minimatch@^5.1.2":
version "5.1.2"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-5.1.2.tgz#07508b45797cb81ec3f273011b054cd0755eddca"
Expand All @@ -109,7 +134,7 @@
resolved "https://registry.yarnpkg.com/@types/vscode/-/vscode-1.89.0.tgz#df0beb3f4ab9133ee8c5fcac8fc578e4623d8749"
integrity sha512-TMfGKLSVxfGfoO8JfIE/neZqv7QLwS4nwPwL/NwMvxtAY2230H2I4Z5xx6836pmJvMAzqooRQ4pmLm7RUicP3A==

"@typescript-eslint/eslint-plugin@^7.11.x":
"@typescript-eslint/[email protected].0":
version "7.11.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.11.0.tgz#f90f0914657ead08e1c75f66939c926edeab42dd"
integrity sha512-P+qEahbgeHW4JQ/87FuItjBj8O3MYv5gELDzr8QaQ7fsll1gSMTYb6j87MYyxwf3DtD7uGFB9ShwgmCJB5KmaQ==
Expand All @@ -124,7 +149,7 @@
natural-compare "^1.4.0"
ts-api-utils "^1.3.0"

"@typescript-eslint/parser@^7.11.x":
"@typescript-eslint/[email protected].0":
version "7.11.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-7.11.0.tgz#525ad8bee54a8f015f134edd241d91b84ab64839"
integrity sha512-yimw99teuaXVWsBcPO1Ais02kwJ1jmNA1KxE7ng0aT7ndr1pT1wqj0OJnsYVGKKlc4QJai86l/025L6z8CljOg==
Expand Down Expand Up @@ -1327,6 +1352,15 @@ type-check@^0.4.0, type-check@~0.4.0:
dependencies:
prelude-ls "^1.2.1"

typescript-eslint@^7.11.0:
version "7.11.0"
resolved "https://registry.yarnpkg.com/typescript-eslint/-/typescript-eslint-7.11.0.tgz#7a208fc1d178b3fed58e33ce37150ac6efecf1fb"
integrity sha512-ZKe3yHF/IS/kCUE4CGE3UgtK+Q7yRk1e9kwEI0rqm9XxMTd9P1eHe0LVVtrZ3oFuIQ2unJ9Xn0vTsLApzJ3aPw==
dependencies:
"@typescript-eslint/eslint-plugin" "7.11.0"
"@typescript-eslint/parser" "7.11.0"
"@typescript-eslint/utils" "7.11.0"

typescript@^5.4.5:
version "5.4.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611"
Expand Down

0 comments on commit 875813c

Please sign in to comment.