Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions .eslintrc.json

This file was deleted.

1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ src/**
**/*.map
.gitignore
tsconfig.json
eslint.config.mjs
vsc-extension-quickstart.md
53 changes: 53 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';

export default defineConfig([
{
ignores: ['out/**', 'node_modules/**', '.vscode-test/**'],
},
{
files: ['**/*.ts'],
languageOptions: {
parser: tseslint.parser,
ecmaVersion: 2019,
sourceType: 'module',
},
plugins: {
'@typescript-eslint': tseslint.plugin,
},
rules: {
'curly': 'error',
'default-case': 'error',
'eqeqeq': ['error', 'always', { 'null': 'ignore' }],
'guard-for-in': 'error',
'max-len': ['warn', { 'code': 140 }],
'no-bitwise': 'error',
'no-caller': 'error',
'no-cond-assign': 'error',
'no-console': ['warn', { 'allow': ['warn', 'error'] }],
'no-debugger': 'error',
'no-empty': 'error',
'no-eval': 'error',
'no-fallthrough': 'error',
'no-multiple-empty-lines': ['error', { 'max': 1 }],
'no-new-wrappers': 'error',
'no-redeclare': 'off',
'no-trailing-spaces': 'error',
'no-var': 'error',
'quotes': ['error', 'single', { 'avoidEscape': true }],
'radix': 'error',
'semi': ['error', 'always'],
'@typescript-eslint/no-redeclare': 'error',
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-unused-expressions': 'warn',
'@typescript-eslint/no-use-before-define': 'error',
},
},
{
files: ['test/**/*.ts'],
rules: {
'@typescript-eslint/no-unused-expressions': 'off',
},
},
]);
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@
"@types/chai": "^4.3.0",
"@types/mocha": "^10.0.0",
"@types/node": "^22.0.0",
"@types/proxyquire": "^1.3.31",
"@types/sinon": "^17.0.0",
"@types/vscode": "^1.32.0",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"@vscode/test-cli": "^0.0.15",
"@vscode/test-electron": "^3.1.0",
"chai": "^4.4.0",
"eslint": "^8.57.0",
"eslint": "^10.11.0",
"proxyquire": "^2.1.3",
"sinon": "^19.0.0",
"typescript": "^5.0.0"
"typescript": "~6.0.3",
"typescript-eslint": "^8.71.0"
},
"resolutions": {
"serialize-javascript": "^7.0.5"
Expand Down
7 changes: 5 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ export function activate(context: vscode.ExtensionContext): void {

const packwerk = new Packwerk(diag);
const disposable = vscode.commands.registerCommand('ruby.packwerk', () => {
const document = vscode.window.activeTextEditor.document;
packwerk.execute(document);
const editor = vscode.window.activeTextEditor;
if (!editor) {
return;
}
packwerk.execute(editor.document);
});

context.subscriptions.push(disposable);
Expand Down
2 changes: 1 addition & 1 deletion src/outputParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function parseOutput(str: string): PackwerkOutput {
} catch {
const files = new Map<string, PackwerkFile>();

let arr: RegExpExecArray;
let arr: RegExpExecArray | null;
while ((arr = regex.exec(str)) !== null) {
// eslint-disable-next-line no-console
console.log('[DEBUG] Parsed regular expression', arr);
Expand Down
16 changes: 8 additions & 8 deletions src/packwerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Packwerk {
let currentPath = getCurrentPath(fileName);
let relativeFileName = fileName.replace(currentPath + '/', '');

let onDidExec = (error: Error, stdout: string, stderr: string) => {
let onDidExec = (error: Error | null, stdout: string, stderr: string) => {
// eslint-disable-next-line no-console
console.debug('[DEBUG] Finished running command, in onDidExec');
// eslint-disable-next-line no-console
Expand All @@ -64,7 +64,7 @@ export class Packwerk {

let entries: [vscode.Uri, vscode.Diagnostic[]][] = [];
packwerk.files.forEach((file: PackwerkFile) => {
let diagnostics = [];
let diagnostics: vscode.Diagnostic[] = [];
file.violations.forEach((offence: PackwerkViolation) => {
const loc = offence.location;
const range = new vscode.Range(
Expand Down Expand Up @@ -131,21 +131,21 @@ export class Packwerk {
private executePackwerkCheck(
fileName: string,
fileContents: string,
options: cp.ExecOptions,
cb: (err: Error, stdout: string, stderr: string) => void
options: cp.ExecOptionsWithStringEncoding,
cb: (err: Error | null, stdout: string, stderr: string) => void
): cp.ChildProcess {
let command = `${this.config.executable} ${fileName}`;
// eslint-disable-next-line no-console
console.debug(`[DEBUG] Running command ${command}`);

let child = cp.exec(command, options, cb);
child.stdin.write(fileContents); // why do we need this?
child.stdin.end();
child.stdin!.write(fileContents); // why do we need this?
child.stdin!.end();
return child;
}

private parse(output: string): PackwerkOutput | null {
let packwerk: PackwerkOutput;
let packwerk: PackwerkOutput | null = null;
if (output.length < 1) {
// eslint-disable-next-line no-console
console.debug(`[DEBUG] Output is ${output}`);
Expand Down Expand Up @@ -175,7 +175,7 @@ export class Packwerk {
return packwerk;
}

private reportError(error: Error, stderr: string): boolean {
private reportError(error: Error | null, stderr: string): boolean {
let errorOutput = stderr.toString();
if (error && (<any>error).code === 'ENOENT') {
vscode.window.showWarningMessage(
Expand Down
4 changes: 2 additions & 2 deletions src/taskQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Task {

public run(): Promise<void> {
if (this.isCanceled) {
return;
return Promise.resolve();
}
let task = this;
return new Promise<void>((resolve, reject) => {
Expand Down Expand Up @@ -117,7 +117,7 @@ export class TaskQueue {
try {
await task.run();
} catch (e) {
console.error('Error while running packwerk: ', e.message, e.stack);
console.error('Error while running packwerk: ', e);
}
this.tasks.shift();
}
Expand Down
10 changes: 5 additions & 5 deletions test/configuration.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';
import * as cp from 'child_process';
import * as pq from 'proxyquire';
import pq from 'proxyquire';
import * as vsStub from 'vscode';

// override vs.workspace.getConfiguration to return default values for each of the extension's
Expand All @@ -9,19 +9,19 @@ const { getConfiguration: _getConfiguration } = vsStub.workspace;

vsStub.workspace.getConfiguration = (
section?: string,
resource?: vsStub.Uri | null
scope?: vsStub.ConfigurationScope | null
): any => {
if (section !== 'ruby.packwerk') {
return _getConfiguration(section, resource);
return _getConfiguration(section, scope);
}

const defaultConfig = {
const defaultConfig: Record<string, unknown> = {
onSave: true,
};

return {
get: <T>(key: string, defaultValue: T): T =>
defaultConfig[key] || defaultValue,
(defaultConfig[key] as T) || defaultValue,
};
};

Expand Down
2 changes: 1 addition & 1 deletion test/taskQueue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as vscode from 'vscode';
class TestTaskWrapper {
public readonly url: vscode.Uri;
public readonly task: Task;
public token?: TaskToken;
public token!: TaskToken;
public isBodyCalled: boolean = false;
public isCancelCallbackCalled: boolean = false;

Expand Down
7 changes: 6 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
"es6"
],
"sourceMap": true,
"rootDir": "."
"rootDir": ".",
"strict": true,
"types": [
"node",
"mocha"
]
},
"exclude": [
"node_modules",
Expand Down
Loading
Loading