Skip to content

Commit

Permalink
build: use prettier to format the code
Browse files Browse the repository at this point in the history
  • Loading branch information
bajtos committed Oct 4, 2017
1 parent 921eaa0 commit 18dd9e8
Show file tree
Hide file tree
Showing 39 changed files with 196 additions and 248 deletions.
3 changes: 3 additions & 0 deletions .prettierignore
@@ -0,0 +1,3 @@
packages/*/lib
packages/*/lib6
packages/*/api-docs
6 changes: 6 additions & 0 deletions .prettierrc
@@ -0,0 +1,6 @@
{
"bracketSpacing": false,
"singleQuote": true,
"printWidth": 80,
"trailingComma": "all"
}
6 changes: 2 additions & 4 deletions .vscode/settings.json
Expand Up @@ -3,6 +3,8 @@
"editor.tabCompletion": true,
"editor.tabSize": 2,
"editor.trimAutoWhitespace": true,
"editor.formatOnSave": true,

"files.exclude": {
"**/.DS_Store": true,
"**/.git": true,
Expand All @@ -19,10 +21,6 @@
"files.trimTrailingWhitespace": true,

"prettier.eslintIntegration": true,
"prettier.bracketSpacing": false,
"prettier.singleQuote": true,
"prettier.printWidth": 80,
"prettier.trailingComma": "all",

"tslint.ignoreDefinitionFiles": true,
"typescript.tsdk": "./node_modules/typescript/lib"
Expand Down
18 changes: 12 additions & 6 deletions package.json
Expand Up @@ -10,18 +10,19 @@
},
"license": "MIT",
"devDependencies": {
"@commitlint/cli": "^3.2.0",
"@commitlint/config-angular": "^3.1.1",
"@commitlint/config-lerna-scopes": "^3.1.1",
"@types/mocha": "^2.2.42",
"@types/node": "^8.0.27",
"@types/request": "^2.0.3",
"@types/request-promise": "^4.1.37",
"@commitlint/cli": "^3.2.0",
"@commitlint/config-angular": "^3.1.1",
"@commitlint/config-lerna-scopes": "^3.1.1",
"coveralls": "^2.13.1",
"lerna": "^2.1.2",
"cz-conventional-changelog": "^2.0.0",
"lerna": "^2.1.2",
"mocha": "^3.4.0",
"nyc": "^11.2.1",
"prettier": "^1.7.3",
"request": "^2.79.0",
"request-promise": "^4.1.1",
"strong-docs": "^1.4.0",
Expand All @@ -34,8 +35,13 @@
"coverage:ci": "nyc report --reporter=text-lcov | coveralls",
"precoverage": "npm test",
"coverage": "open coverage/index.html",
"lint": "tslint -c tslint.full.json --project tsconfig.json --type-check",
"lint:fix": "npm run lint -- --fix",
"lint": "npm run prettier:check && npm run tslint",
"lint:fix": "npm run prettier:fix && npm run tslint:fix",
"tslint": "tslint -c tslint.full.json --project tsconfig.json --type-check",
"tslint:fix": "npm run tslint -- --fix",
"prettier:cli": "prettier \"**/*.ts\"",
"prettier:check": "npm run prettier:cli -- -l",
"prettier:fix": "npm run prettier:cli -- --write",
"clean": "lerna run --loglevel=silent clean",
"build": "lerna run --loglevel=silent build",
"build:current": "lerna run --loglevel=silent build:current",
Expand Down
10 changes: 5 additions & 5 deletions packages/authentication/test/unit/authenticate-action.test.ts
Expand Up @@ -40,14 +40,14 @@ describe('AuthenticationProvider', () => {
const authenticate: AuthenticateFn = await Promise.resolve(
provider.value(),
);
const request = <ParsedRequest> {};
const request = <ParsedRequest>{};
const user = await authenticate(request);
expect(user).to.be.equal(mockUser);
});

it('updates current user', async () => {
const authenticate = await Promise.resolve(provider.value());
const request = <ParsedRequest> {};
const request = <ParsedRequest>{};
await authenticate(request);
expect(currentUser).to.equal(mockUser);
});
Expand All @@ -59,7 +59,7 @@ describe('AuthenticationProvider', () => {
context
.bind(AuthenticationBindings.AUTH_ACTION)
.toProvider(AuthenticationProvider);
const request = <ParsedRequest> {};
const request = <ParsedRequest>{};
const authenticate = await context.get(
AuthenticationBindings.AUTH_ACTION,
);
Expand All @@ -76,7 +76,7 @@ describe('AuthenticationProvider', () => {
const authenticate = await context.get(
AuthenticationBindings.AUTH_ACTION,
);
const request = <ParsedRequest> {};
const request = <ParsedRequest>{};
let error;
try {
await authenticate(request);
Expand All @@ -95,7 +95,7 @@ describe('AuthenticationProvider', () => {
const authenticate = await context.get(
AuthenticationBindings.AUTH_ACTION,
);
const request = <ParsedRequest> {};
const request = <ParsedRequest>{};
request.headers = {testState: 'fail'};
let error;
try {
Expand Down
Expand Up @@ -4,10 +4,7 @@
// License text available at https://opensource.org/licenses/MIT

import {expect} from '@loopback/testlab';
import {
authenticate,
getAuthenticateMetadata,
} from '../..';
import {authenticate, getAuthenticateMetadata} from '../..';

describe('Authentication', () => {
describe('@authenticate decorator', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/authentication/test/unit/strategy-adapter.test.ts
Expand Up @@ -25,7 +25,7 @@ describe('Strategy Adapter', () => {
}
const strategy = new Strategy();
const adapter = new StrategyAdapter(strategy);
const request = <ParsedRequest> {};
const request = <ParsedRequest>{};
await adapter.authenticate(request);
expect(calledFlag).to.be.true();
});
Expand All @@ -34,7 +34,7 @@ describe('Strategy Adapter', () => {
const strategy = new MockStrategy();
strategy.setMockUser(mockUser);
const adapter = new StrategyAdapter(strategy);
const request = <ParsedRequest> {};
const request = <ParsedRequest>{};
const user: Object = await adapter.authenticate(request);
expect(user).to.be.eql(mockUser);
});
Expand All @@ -43,7 +43,7 @@ describe('Strategy Adapter', () => {
const strategy = new MockStrategy();
strategy.setMockUser(mockUser);
const adapter = new StrategyAdapter(strategy);
const request = <ParsedRequest> {};
const request = <ParsedRequest>{};
request.headers = {testState: 'fail'};
let error;
try {
Expand All @@ -58,7 +58,7 @@ describe('Strategy Adapter', () => {
const strategy = new MockStrategy();
strategy.setMockUser(mockUser);
const adapter = new StrategyAdapter(strategy);
const request = <ParsedRequest> {};
const request = <ParsedRequest>{};
request.headers = {testState: 'error'};
let error;
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/context/src/binding.ts
Expand Up @@ -120,7 +120,7 @@ export class Binding {

return {
key: keyWithPath.substr(0, index).trim(),
path: keyWithPath.substr(index+1),
path: keyWithPath.substr(index + 1),
};
}

Expand Down
5 changes: 3 additions & 2 deletions packages/context/src/is-promise.ts
Expand Up @@ -9,8 +9,9 @@
*
* @param value The value to check.
*/
export function isPromise<T>(value: T | PromiseLike<T>):
value is PromiseLike<T> {
export function isPromise<T>(
value: T | PromiseLike<T>,
): value is PromiseLike<T> {
if (!value) return false;
if (typeof value !== 'object' && typeof value !== 'function') return false;
return typeof (value as PromiseLike<T>).then === 'function';
Expand Down
2 changes: 1 addition & 1 deletion packages/context/src/reflect.ts
Expand Up @@ -161,7 +161,7 @@ export class NamespacedReflect {
if (targetKey) {
return Reflect.decorate(decorators, target, targetKey, descriptor);
} else {
return Reflect.decorate(<ClassDecorator[]> decorators, <Function> target);
return Reflect.decorate(<ClassDecorator[]>decorators, <Function>target);
}
}

Expand Down
15 changes: 12 additions & 3 deletions packages/context/test/acceptance/child-context.ts
Expand Up @@ -32,9 +32,18 @@ describe('Context bindings - contexts inheritance', () => {
});

it('includes parent bindings when searching via findByTag()', () => {
parentCtx.bind('foo').to('parent:foo').tag('a-tag');
parentCtx.bind('bar').to('parent:bar').tag('a-tag');
childCtx.bind('foo').to('child:foo').tag('a-tag');
parentCtx
.bind('foo')
.to('parent:foo')
.tag('a-tag');
parentCtx
.bind('bar')
.to('parent:bar')
.tag('a-tag');
childCtx
.bind('foo')
.to('child:foo')
.tag('a-tag');

const found = childCtx.findByTag('a-tag').map(b => b.getValue(childCtx));
expect(found).to.deepEqual(['child:foo', 'parent:bar']);
Expand Down
15 changes: 3 additions & 12 deletions packages/context/test/acceptance/class-level-bindings.ts
Expand Up @@ -138,10 +138,7 @@ describe('Context bindings - Injecting dependencies of classes', () => {
ctx.bind('key').to('value');

class Store {
constructor(
@inject.getter('key')
public getter: Getter<string>,
) {}
constructor(@inject.getter('key') public getter: Getter<string>) {}
}

ctx.bind('store').toClass(Store);
Expand All @@ -157,10 +154,7 @@ describe('Context bindings - Injecting dependencies of classes', () => {

it('injects a setter function', async () => {
class Store {
constructor(
@inject.setter('key')
public setter: Setter<string>,
) {}
constructor(@inject.setter('key') public setter: Setter<string>) {}
}

ctx.bind('store').toClass(Store);
Expand All @@ -173,10 +167,7 @@ describe('Context bindings - Injecting dependencies of classes', () => {

it('injects a nested property', async () => {
class TestComponent {
constructor(
@inject('config#test')
public config: string,
) {}
constructor(@inject('config#test') public config: string) {}
}

ctx.bind('config').to({test: 'test-config'});
Expand Down
10 changes: 8 additions & 2 deletions packages/context/test/acceptance/finding-bindings.ts
Expand Up @@ -59,8 +59,14 @@ describe('Context bindings - Finding bindings', () => {

function createTaggedBindings() {
class Dog {}
ctx.bind('spot').to(new Dog()).tag('dog');
ctx.bind('fido').to(new Dog()).tag('dog');
ctx
.bind('spot')
.to(new Dog())
.tag('dog');
ctx
.bind('fido')
.to(new Dog())
.tag('dog');
}
});

Expand Down
4 changes: 1 addition & 3 deletions packages/context/test/acceptance/locking-bindings.ts
Expand Up @@ -39,9 +39,7 @@ describe('Context bindings - Locking bindings', () => {
const key = 'foo';
const operation = () => ctx.bind('foo');
expect(operation).to.throw(
new RegExp(
`Cannot rebind key "${key}" to a locked binding`,
),
new RegExp(`Cannot rebind key "${key}" to a locked binding`),
);
});
});
Expand Down
10 changes: 5 additions & 5 deletions packages/openapi-spec-builder/src/openapi-spec-builder.ts
Expand Up @@ -49,7 +49,8 @@ export class BuilderBase<T extends Extendable> {
withExtension(key: string, value: ExtensionValue): this {
assert(
key.startsWith('x-'),
`Invalid extension ${key}, extension keys must be prefixed with "x-"`);
`Invalid extension ${key}, extension keys must be prefixed with "x-"`,
);

this._spec[key] = value;
return this;
Expand Down Expand Up @@ -83,8 +84,8 @@ export class OpenApiSpecBuilder extends BuilderBase<OpenApiSpec> {
*/
withOperation(
verb: string,
path: string,
spec: OperationObject | OperationSpecBuilder,
path: string,
spec: OperationObject | OperationSpecBuilder,
): this {
if (spec instanceof OperationSpecBuilder) spec = spec.build();
if (!this._spec.paths[path]) this._spec.paths[path] = {};
Expand All @@ -106,8 +107,7 @@ export class OpenApiSpecBuilder extends BuilderBase<OpenApiSpec> {
operationName?: string,
): this {
const spec = anOperationSpec().withStringResponse(200);
if (operationName)
spec.withOperationName(operationName);
if (operationName) spec.withOperationName(operationName);

return this.withOperation(verb, path, spec);
}
Expand Down

0 comments on commit 18dd9e8

Please sign in to comment.