Skip to content

Commit

Permalink
Add tsfmt rule to add space before parentheses of anonymous functions
Browse files Browse the repository at this point in the history
Theia and VSCode format anonymous functions differently:

Theia:

    function()

VSCode:

    function ()

As people use both tools to edit the Theia code, we constantly get
spurious diffs where these are changed back and forth.  This patch adds
a tsfmt.json (picked up by the typescript language server) to align the
Theia behavior on what VSCode does.  It also adds a tslint rule and fixes
all problematic occurences.

Change-Id: I6f1b99a8b53095597e8db2eadb056fa272b5af66
Signed-off-by: Simon Marchi <[email protected]>
  • Loading branch information
Simon Marchi authored and paul-marechal committed Dec 6, 2018
1 parent c7b8840 commit 08c2317
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 18 deletions.
6 changes: 6 additions & 0 deletions configs/errors.tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
"always",
"ignore-interfaces"
],
"space-before-function-paren": [
true,
{
"anonymous": "always"
}
],
"trailing-comma": false,
"triple-equals": [
true,
Expand Down
6 changes: 3 additions & 3 deletions examples/browser/test/cpp/cpp-change-build-config.ui-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int main() {}
*/
function hasClangd() {
try {
const out = cp.execSync('clangd -version', {encoding: 'utf8'});
const out = cp.execSync('clangd -version', { encoding: 'utf8' });
// Match 'clangd version' at the start of
// 'clangd version 8.0.0 (trunk 341484) (llvm/trunk 341481)'.
return out.indexOf('clangd version') === 0;
Expand All @@ -124,8 +124,8 @@ function changeBuildConfig(name: string, driver: WebdriverIO.Client<void>) {
driver.pause(300);
}

describe('cpp extension', function() {
it('should be able to change build config', function() {
describe('cpp extension', function () {
it('should be able to change build config', function () {
if (!hasClangd()) {
this.skip();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import { createPreferenceProxy } from './preference-proxy';
import { MockPreferenceService } from './test/mock-preference-service';
import { expect } from 'chai';

describe('preference proxy', function() {
describe('preference proxy', function () {
/** Verify the return type of the ready property. */
it('.ready should return a promise', function() {
it('.ready should return a promise', function () {

const proxy = createPreferenceProxy(new MockPreferenceService(), {
properties: {}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/node/console-logger-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ beforeEach(() => {
server = container.get<ConsoleLoggerServer>(ConsoleLoggerServer);
});

describe('ConsoleLoggerServer', function() {
it('should respect log level config', async function() {
describe('ConsoleLoggerServer', function () {
it('should respect log level config', async function () {
expect(await server.getLogLevel('test-logger')).eq(LogLevel.DEBUG);
await server.child('test-logger');
expect(await server.getLogLevel('test-logger')).eq(LogLevel.DEBUG);
Expand Down
14 changes: 7 additions & 7 deletions packages/cpp/src/browser/cpp-build-configurations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { MockPreferenceService } from '@theia/core/lib/browser/preferences/test/

let container: Container;

beforeEach(function() {
beforeEach(function () {
const m = new ContainerModule(bind => {
bind(CppBuildConfigurationManager).to(CppBuildConfigurationManagerImpl).inSingletonScope();
bind(StorageService).to(MockStorageService).inSingletonScope();
Expand Down Expand Up @@ -76,8 +76,8 @@ async function initializeTest(buildConfigurations: CppBuildConfiguration[] | und
return configs;
}

describe('build-configurations', function() {
it('should work with no preferences', async function() {
describe('build-configurations', function () {
it('should work with no preferences', async function () {
const cppBuildConfigurations = await initializeTest(undefined, undefined);

const configs = cppBuildConfigurations.getConfigs();
Expand All @@ -87,7 +87,7 @@ describe('build-configurations', function() {
expect(configs).lengthOf(0);
});

it('should work with an empty list of builds', async function() {
it('should work with an empty list of builds', async function () {
const cppBuildConfigurations = await initializeTest([], undefined);

const configs = cppBuildConfigurations.getConfigs();
Expand All @@ -97,7 +97,7 @@ describe('build-configurations', function() {
expect(configs).lengthOf(0);
});

it('should work with a simple list of builds', async function() {
it('should work with a simple list of builds', async function () {
const builds = [{
name: 'Release',
directory: '/tmp/builds/release',
Expand All @@ -115,7 +115,7 @@ describe('build-configurations', function() {
expect(configs).to.have.deep.members(builds);
});

it('should work with a simple list of builds and an active config', async function() {
it('should work with a simple list of builds and an active config', async function () {
const builds = [{
name: 'Release',
directory: '/tmp/builds/release',
Expand All @@ -133,7 +133,7 @@ describe('build-configurations', function() {
expect(configs).to.have.deep.members(builds);
});

it("should ignore an active config that doesn't exist", async function() {
it("should ignore an active config that doesn't exist", async function () {
const builds = [{
name: 'Release',
directory: '/tmp/builds/release',
Expand Down
6 changes: 3 additions & 3 deletions packages/cpp/src/browser/cpp-task-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class MockCppBuildConfigurationManager implements CppBuildConfigurationManager {
ready: Promise<void> = Promise.resolve();
}

beforeEach(function() {
beforeEach(function () {
const container: Container = new Container();
container.bind(CppTaskProvider).toSelf().inSingletonScope();
container.bind(TaskResolverRegistry).toSelf().inSingletonScope();
Expand All @@ -80,8 +80,8 @@ beforeEach(function() {
});
});

describe('CppTaskProvider', function() {
it('provide a task for each build config with a build command', async function() {
describe('CppTaskProvider', function () {
it('provide a task for each build config with a build command', async function () {
const tasks = await taskProvider.provideTasks();
expect(tasks).length(1);
expect(tasks[0].config.name === 'Build 1');
Expand Down
2 changes: 1 addition & 1 deletion packages/workspace/src/browser/workspace-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe('WorkspaceService', () => {
expect((<sinon.SinonStub>mockILogger.error).called).to.be.true;
});

it('should use the workspace path in the URL fragment, if available', async function() {
it('should use the workspace path in the URL fragment, if available', async function () {
const workspacePath = '/home/somewhere';
window.location.hash = '#' + workspacePath;
const stat = <FileStat>{
Expand Down
3 changes: 3 additions & 0 deletions tsfmt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": true
}

0 comments on commit 08c2317

Please sign in to comment.