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: 47 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"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",
"@typescript-eslint/no-var-requires": "error"
},
"overrides": [
{
"files": ["test/**/*.ts"],
"rules": {
"@typescript-eslint/no-unused-expressions": "off"
}
}
],
"ignorePatterns": ["out/**", "node_modules/**", ".vscode-test/**"]
}
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
branches: [main]
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: '22'
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Lint
run: yarn lint

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: '22'
cache: 'yarn'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Compile TypeScript
run: yarn run vscode:prepublish
- name: Run tests
run: xvfb-run -a yarn test
28 changes: 16 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"vscode:prepublish": "tsc -p ./",
"format": "tsfmt -r src/*",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "node ./node_modules/vscode/bin/test"
"lint": "eslint 'src/**/*.ts' 'test/**/*.ts'",
"test": "node ./out/test/runTests"
},
"contributes": {
"languages": [
Expand Down Expand Up @@ -72,15 +72,19 @@
}
},
"devDependencies": {
"@types/chai": "^4.2.9",
"@types/mocha": "^5.2.6",
"@types/node": "^13.7.7",
"chai": "^4.2.0",
"mocha": "^6.0.2",
"proxyquire": "^2.1.0",
"sinon": "^7.3.0",
"tslint": "^5.1.0",
"typescript": "^3.8.3",
"vscode": "^1.1.0"
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^10.0.0",
"@types/node": "^22.0.0",
"@types/sinon": "^17.0.0",
"@types/vscode": "^1.32.0",
"@vscode/test-electron": "^2.0.0",
"chai": "^4.4.0",
"eslint": "^8.57.0",
"mocha": "^10.0.0",
"proxyquire": "^2.1.3",
"sinon": "^19.0.0",
"typescript": "^5.0.0"
}
}
3 changes: 2 additions & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export const getConfig: () => PackwerkConfig = () => {
const conf = vs.workspace.getConfiguration('ruby.packwerk');
let executable = conf.get('executable', 'bin/packwerk check');

console.debug(`[DEBUG] Parsing config, found executable '${executable}'`)
// eslint-disable-next-line no-console
console.debug(`[DEBUG] Parsing config, found executable '${executable}'`);

return {
executable,
Expand Down
5 changes: 3 additions & 2 deletions src/outputParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ export function parseOutput(str: string): PackwerkOutput {

let arr: RegExpExecArray;
while ((arr = regex.exec(str)) !== null) {
console.log("[DEBUG] Parsed regular expression", arr)
// eslint-disable-next-line no-console
console.log('[DEBUG] Parsed regular expression', arr);
const file = arr[1];
const line = Number(arr[2]);
const column = Number(arr[3]);
const message = arr[4].trim();
const symbol = arr[5];

if (!files.has(file)) files.set(file, { path: file, violations: [] });
if (!files.has(file)) { files.set(file, { path: file, violations: [] }); }

files.get(file)!.violations.push({
message,
Expand Down
33 changes: 22 additions & 11 deletions src/packwerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@ export class Packwerk {
const fileName = document.fileName;
const uri = document.uri;
let currentPath = getCurrentPath(fileName);
let relativeFileName = fileName.replace(currentPath + '/', '')
let relativeFileName = fileName.replace(currentPath + '/', '');

let onDidExec = (error: Error, stdout: string, stderr: string) => {
console.debug(`[DEBUG] Finished running command, in onDidExec`)
console.debug(`[DEBUG] Error, stderr`, error, stderr)
// eslint-disable-next-line no-console
console.debug('[DEBUG] Finished running command, in onDidExec');
// eslint-disable-next-line no-console
console.debug('[DEBUG] Error, stderr', error, stderr);
this.reportError(error, stderr);
let packwerk = this.parse(stdout);
if (packwerk === undefined || packwerk === null) {
console.debug(`[DEBUG] packwerk is undefined or null, returning from onDidExec`)
// eslint-disable-next-line no-console
console.debug('[DEBUG] packwerk is undefined or null, returning from onDidExec');
return;
}

Expand All @@ -76,7 +79,8 @@ export class Packwerk {
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');

const message = decolorizedMessage;
console.debug(`[DEBUG] Adding vscode.Diagnostic:`, { range, message })
// eslint-disable-next-line no-console
console.debug('[DEBUG] Adding vscode.Diagnostic:', { range, message });
const diagnostic = new vscode.Diagnostic(
range,
message,
Expand Down Expand Up @@ -130,8 +134,9 @@ export class Packwerk {
options: cp.ExecOptions,
cb: (err: Error, stdout: string, stderr: string) => void
): cp.ChildProcess {
let command = `${this.config.executable} ${fileName}`
console.debug(`[DEBUG] Running command ${command}`)
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?
Expand All @@ -142,9 +147,11 @@ export class Packwerk {
private parse(output: string): PackwerkOutput | null {
let packwerk: PackwerkOutput;
if (output.length < 1) {
console.debug(`[DEBUG] Output is ${output}`)
// eslint-disable-next-line no-console
console.debug(`[DEBUG] Output is ${output}`);
let message = `command ${this.config.executable} returns empty output! please check configuration.`;
console.debug(`[DEBUG] ${message}`)
// eslint-disable-next-line no-console
console.debug(`[DEBUG] ${message}`);
// For now, we do not show this error message. There are lots of reasons why this could fail, so
// we turn it off so as to not bother the user
// vscode.window.showWarningMessage(message);
Expand Down Expand Up @@ -176,11 +183,15 @@ export class Packwerk {
);
return true;
} else if (error && (<any>error).code === 127 && this.config.showWarnings) {
console.debug('[DEBUG] Showing error with code 127', stderr)
// TODO: likely redundant; the same stderr is already surfaced via showWarningMessage below
// eslint-disable-next-line no-console
console.debug('[DEBUG] Showing error with code 127', stderr);
vscode.window.showWarningMessage(stderr);
return true;
} else if (errorOutput.length > 0 && this.config.showWarnings) {
console.debug('[DEBUG] Showing error with errorOutput.length > 0', stderr)
// TODO: likely redundant; the same stderr is already surfaced via showWarningMessage below
// eslint-disable-next-line no-console
console.debug('[DEBUG] Showing error with errorOutput.length > 0', stderr);
vscode.window.showWarningMessage(stderr);
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/taskQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export class TaskQueue {
let uriString = uri.toString(true);
this.tasks.forEach((task) => {
if (task.uri.toString(true) === uriString) {
console.debug(`[DEBUG] Canceling existing task for ${task.uri}`)
// eslint-disable-next-line no-console
console.debug(`[DEBUG] Canceling existing task for ${task.uri}`);
task.cancel();
}
});
Expand Down
4 changes: 2 additions & 2 deletions test/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ vsStub.workspace.getConfiguration = (
};

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

Expand Down
37 changes: 29 additions & 8 deletions test/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
import * as testRunner from 'vscode/lib/testrunner';
import * as fs from 'fs';
import * as Mocha from 'mocha';
import * as path from 'path';

// see https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
testRunner.configure({
reporter: 'spec',
ui: 'bdd',
useColors: true,
});
export function run(): Promise<void> {
const mocha = new Mocha({
color: true,
ui: 'bdd',
});

module.exports = testRunner;
const testsRoot = path.resolve(__dirname, '.');
const files = fs
.readdirSync(testsRoot)
.filter((f) => f.endsWith('.js') && f !== 'index.js' && f !== 'runTests.js');

files.forEach((f) => mocha.addFile(path.resolve(testsRoot, f)));

return new Promise((resolve, reject) => {
try {
mocha.run((failures) => {
if (failures > 0) {
reject(new Error(`${failures} tests failed.`));
} else {
resolve();
}
});
} catch (err) {
reject(err);
}
});
}
14 changes: 14 additions & 0 deletions test/runTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as path from 'path';
import { runTests } from '@vscode/test-electron';

async function main(): Promise<void> {
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
const extensionTestsPath = path.resolve(__dirname, './index');

await runTests({ extensionDevelopmentPath, extensionTestsPath });
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
6 changes: 0 additions & 6 deletions test/tslint.json

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"target": "ES2019",
"outDir": "out",
"lib": [
"es6"
Expand Down
Loading