Skip to content

Commit

Permalink
Added VS Code Marketplace Keywords (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
ObliviousHarmony authored Apr 5, 2023
1 parent 78385fc commit da65343
Show file tree
Hide file tree
Showing 8 changed files with 2,147 additions and 12,496 deletions.
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/extension.js",
"${workspaceFolder}/extension.js.map",
Expand Down
14,518 changes: 2,078 additions & 12,440 deletions package-lock.json

Large diffs are not rendered by default.

45 changes: 25 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@
"Programming Languages",
"Linters"
],
"keywords": [
"php",
"linter",
"fixer",
"phpcs",
"phpcbf"
],
"engines": {
"vscode": "^1.53.0"
"vscode": "^1.77.0"
},
"main": "extension.js",
"extensionKind": [
Expand Down Expand Up @@ -124,27 +131,25 @@
]
},
"dependencies": {
"minimatch": "^3.0.4"
"minimatch": "^5.1.2"
},
"devDependencies": {
"@types/jest": "^26.0.23",
"@types/node": "^12.20.37",
"@types/vscode": "~1.53.0",
"@types/minimatch": "^3.0.4",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.1",
"file-loader": "^6.2.0",
"jest": "^26.6.3",
"prettier": "2.3.0",
"ts-jest": "^26.5.6",
"ts-loader": "^8.3.0",
"typescript": "^4.5.3",
"vsce": "^2.5.1",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1"
"@types/jest": "^29.5.0",
"@types/minimatch": "^5.1.2",
"@types/node": "^16.11.7",
"@types/vscode": "^1.77.0",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"eslint": "^8.37.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^29.5.0",
"prettier": "^2.8.7",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.2",
"typescript": "^5.0.3",
"webpack": "^5.78.0",
"webpack-cli": "^5.0.1"
},
"scripts": {
"vscode:prepublish": "npm run clean && webpack --mode production",
Expand Down
18 changes: 8 additions & 10 deletions src/phpcs-report/__tests__/worker-pool.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mocked } from 'ts-jest/utils';

import { Worker } from '../worker';
import { WorkerPool } from '../worker-pool';
import { MockCancellationToken } from '../../__mocks__/vscode';
Expand All @@ -19,24 +19,22 @@ jest.mock('../worker', () => {
});

describe('WorkerPool', () => {
const MockedWorker = mocked(Worker, true);

afterEach(() => {
MockedWorker.mockClear();
jest.mocked(Worker).mockClear();
});

it('should resolve instantly if worker is available', () => {
const pool = new WorkerPool(1);

return expect(pool.waitForAvailable('test')).resolves.toStrictEqual(
MockedWorker.mock.results[0].value
jest.mocked(Worker).mock.results[0].value
);
});

it('should resolve when worker becomes available', () => {
const pool = new WorkerPool(1);

const mockWorker = MockedWorker.mock.results[0].value;
const mockWorker = jest.mocked(Worker).mock.results[0].value;

// Mark the worker as active so that the request will be queued.
mockWorker.isActive = true;
Expand All @@ -48,14 +46,14 @@ describe('WorkerPool', () => {
mockWorker.onActiveChanged(mockWorker);

return expect(promise).resolves.toStrictEqual(
MockedWorker.mock.results[0].value
jest.mocked(Worker).mock.results[0].value
);
});

it('should support cancellation', () => {
const pool = new WorkerPool(1);

const mockWorker = MockedWorker.mock.results[0].value;
const mockWorker = jest.mocked(Worker).mock.results[0].value;

// Mark the worker as active so that the request will be queued.
mockWorker.isActive = true;
Expand All @@ -73,7 +71,7 @@ describe('WorkerPool', () => {
it('should support waiting after cancellation', async () => {
const pool = new WorkerPool(1);

const mockWorker = MockedWorker.mock.results[0].value;
const mockWorker = jest.mocked(Worker).mock.results[0].value;

// Mark the worker as active so that the request will be queued.
mockWorker.isActive = true;
Expand All @@ -98,7 +96,7 @@ describe('WorkerPool', () => {
promise = pool.waitForAvailable('test', cancellationToken);

return expect(promise).resolves.toStrictEqual(
MockedWorker.mock.results[0].value
jest.mocked(Worker).mock.results[0].value
);
});
});
27 changes: 13 additions & 14 deletions src/services/__tests__/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Uri,
} from '../../__mocks__/vscode';
import { TextEncoder } from 'util';
import { mocked } from 'ts-jest/utils';
import { Configuration, LintAction, StandardType } from '../configuration';

describe('Configuration', () => {
Expand All @@ -20,7 +19,7 @@ describe('Configuration', () => {

beforeAll(() => {
// Create a mock implementation that can create joined paths.
mocked(Uri.joinPath).mockImplementation(
jest.mocked(Uri.joinPath).mockImplementation(
(uri: vsCodeUri, ...pathSegments: string[]) => {
const uriSegments = uri.path.split('/');

Expand Down Expand Up @@ -53,13 +52,13 @@ describe('Configuration', () => {
});

afterEach(() => {
mocked(workspace.getConfiguration).mockClear();
mocked(workspace.getWorkspaceFolder).mockClear();
jest.mocked(workspace.getConfiguration).mockClear();
jest.mocked(workspace.getWorkspaceFolder).mockClear();
});

it('should read and cache configuration for document', async () => {
const mockConfiguration = { get: jest.fn() };
mocked(workspace).getConfiguration.mockReturnValue(
jest.mocked(workspace).getConfiguration.mockReturnValue(
mockConfiguration as never
);

Expand Down Expand Up @@ -108,19 +107,19 @@ describe('Configuration', () => {

it('should read filesystem for executable when enabled', async () => {
const mockConfiguration = { get: jest.fn() };
mocked(workspace).getConfiguration.mockReturnValue(
jest.mocked(workspace).getConfiguration.mockReturnValue(
mockConfiguration as never
);

const workspaceUri = new Uri();
workspaceUri.path = 'test';
workspaceUri.fsPath = 'test';
mocked(workspace).getWorkspaceFolder.mockReturnValue({
jest.mocked(workspace).getWorkspaceFolder.mockReturnValue({
uri: workspaceUri,
} as never);

// We will traverse from the file directory up.
mocked(workspace.fs.readFile).mockImplementation((uri) => {
jest.mocked(workspace.fs.readFile).mockImplementation((uri) => {
switch (uri.path) {
case 'test/file/composer.json':
return Promise.reject(new FileSystemError(uri));
Expand All @@ -138,7 +137,7 @@ describe('Configuration', () => {
throw new Error('Invalid path: ' + uri.path);
});

mocked(workspace.fs.stat).mockImplementation((uri) => {
jest.mocked(workspace.fs.stat).mockImplementation((uri) => {
switch (uri.path) {
case 'test/newvendor/bin/phpcs': {
const ret = new Uri();
Expand Down Expand Up @@ -198,19 +197,19 @@ describe('Configuration', () => {
const cancellationToken = new MockCancellationToken();

const mockConfiguration = { get: jest.fn() };
mocked(workspace).getConfiguration.mockReturnValue(
jest.mocked(workspace).getConfiguration.mockReturnValue(
mockConfiguration as never
);

const workspaceUri = new Uri();
workspaceUri.path = 'test';
workspaceUri.fsPath = 'test';
mocked(workspace).getWorkspaceFolder.mockReturnValue({
jest.mocked(workspace).getWorkspaceFolder.mockReturnValue({
uri: workspaceUri,
} as never);

// We will traverse from the file directory up.
mocked(workspace.fs.readFile).mockImplementation((uri) => {
jest.mocked(workspace.fs.readFile).mockImplementation((uri) => {
switch (uri.path) {
case 'test/file/composer.json':
return Promise.reject(new FileSystemError(uri));
Expand All @@ -228,7 +227,7 @@ describe('Configuration', () => {
throw new Error('Invalid path: ' + uri.path);
});

mocked(workspace.fs.stat).mockImplementation((uri) => {
jest.mocked(workspace.fs.stat).mockImplementation((uri) => {
switch (uri.path) {
case 'test/newvendor/bin/phpcs': {
const ret = new Uri();
Expand Down Expand Up @@ -275,7 +274,7 @@ describe('Configuration', () => {
describe('deprecated options', () => {
it('should handle "ignorePatterns" deprecation', async () => {
const mockConfiguration = { get: jest.fn() };
mocked(workspace).getConfiguration.mockReturnValue(
jest.mocked(workspace).getConfiguration.mockReturnValue(
mockConfiguration as never
);

Expand Down
19 changes: 9 additions & 10 deletions src/services/__tests__/diagnostic-updater.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
MockDiagnosticCollection,
MockTextDocument,
} from '../../__mocks__/vscode';
import { mocked } from 'ts-jest/utils';
import { PHPCSError, Worker } from '../../phpcs-report/worker';
import { ReportType, Response } from '../../phpcs-report/response';
import { Logger } from '../../services/logger';
Expand Down Expand Up @@ -81,25 +80,25 @@ describe('DiagnosticUpdater', () => {
);
});

it('should update diagnostics and code actions', async (done) => {
it('should update diagnostics and code actions', (done) => {
const document = new MockTextDocument();
document.fileName = 'test-document';

const mockWorker = new Worker();
mocked(mockWorkerPool).waitForAvailable.mockImplementation(
jest.mocked(mockWorkerPool).waitForAvailable.mockImplementation(
(workerKey) => {
expect(workerKey).toBe('diagnostic:test-document');
return Promise.resolve(mockWorker);
}
);
mocked(mockConfiguration).get.mockResolvedValue({
jest.mocked(mockConfiguration).get.mockResolvedValue({
workingDirectory: 'test-dir',
executable: 'phpcs-test',
exclude: [],
lintAction: LintAction.Change,
standard: StandardType.PSR12,
});
mocked(mockWorker).execute.mockImplementation((request) => {
jest.mocked(mockWorker).execute.mockImplementation((request) => {
expect(request).toMatchObject({
type: ReportType.Diagnostic,
options: {
Expand Down Expand Up @@ -143,20 +142,20 @@ describe('DiagnosticUpdater', () => {
document.fileName = 'test-document';

const mockWorker = new Worker();
mocked(mockWorkerPool).waitForAvailable.mockImplementation(
jest.mocked(mockWorkerPool).waitForAvailable.mockImplementation(
(workerKey) => {
expect(workerKey).toBe('diagnostic:test-document');
return Promise.resolve(mockWorker);
}
);
mocked(mockConfiguration).get.mockResolvedValue({
jest.mocked(mockConfiguration).get.mockResolvedValue({
workingDirectory: 'test-dir',
executable: 'phpcs-test',
exclude: [],
lintAction: LintAction.Change,
standard: StandardType.PSR12,
});
mocked(mockWorker).execute.mockImplementation((request) => {
jest.mocked(mockWorker).execute.mockImplementation((request) => {
expect(request).toMatchObject({
type: ReportType.Diagnostic,
options: {
Expand All @@ -182,7 +181,7 @@ describe('DiagnosticUpdater', () => {
const document = new MockTextDocument();
document.fileName = 'test-document';

mocked(mockConfiguration).get.mockResolvedValue({
jest.mocked(mockConfiguration).get.mockResolvedValue({
workingDirectory: 'test-dir',
executable: 'phpcs-test',
exclude: [new RegExp('.*/file/.*')],
Expand All @@ -197,7 +196,7 @@ describe('DiagnosticUpdater', () => {
const document = new MockTextDocument();
document.fileName = 'test-document';

mocked(mockConfiguration).get.mockResolvedValue({
jest.mocked(mockConfiguration).get.mockResolvedValue({
workingDirectory: 'test-dir',
executable: 'phpcs-test',
exclude: [],
Expand Down
13 changes: 12 additions & 1 deletion src/services/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,18 @@ export class Configuration {
'The extension has an invalid `phpCodeSniffer.exclude` configuration.'
);
}
const exclude = rawPatterns.map((v) => new Minimatch(v).makeRe());

// Parse the glob patterns into a format we can use.
const exclude: RegExp[] = [];
for (const pattern of rawPatterns) {
const match = new Minimatch(pattern);
const regex = match.makeRe();
if (!regex) {
continue;
}

exclude.push(regex);
}

// Support the deprecated `ignorePatterns` option.
rawPatterns = config.get<string[]>('ignorePatterns');
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const config = {
path: path.resolve(__dirname),
filename: 'extension.js',
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: "../[resource-path]",
devtoolModuleFilenameTemplate: "[resource-path]",
},
devtool: 'source-map',
externals: {
Expand Down

0 comments on commit da65343

Please sign in to comment.