Skip to content

Commit

Permalink
add tslint
Browse files Browse the repository at this point in the history
  • Loading branch information
steelsojka committed Apr 28, 2017
1 parent 7513543 commit a7b2f97
Show file tree
Hide file tree
Showing 47 changed files with 245 additions and 199 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ buildDocs
.gitignore
tsconfig*
mocha.opts
.vscode
.vscode
tslint.json
.editorconfig
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test": "mocha --opts mocha.opts",
"test:clean": "del test",
"posttest": "npm run test:clean",
"prebuild": "npm run build:clean",
"prebuild": "npm run lint && npm run build:clean",
"prebuild:test": "npm run test:clean",
"prebuild:docs": "npm run build:docs:clean",
"build:clean": "del '*.js' '*.js.map' '*.d.ts' applicators factory utils",
Expand All @@ -26,7 +26,9 @@
"docs:serve": "http-server ./docs",
"docs:publish": "git subtree push --prefix docs origin gh-pages",
"readme": "doctoc ./README.md",
"release": "npm run build && npm run docs && npm run readme"
"release": "npm run build && npm run docs && npm run readme",
"lint": "tslint src/**",
"lint:fix": "tslint src/** --fix"
},
"main": "index.js",
"keywords": [
Expand Down Expand Up @@ -58,6 +60,8 @@
"mocha": "^3.3.0",
"sinon": "~1.14.1",
"ts-node": "^3.0.2",
"tslint": "^5.1.0",
"tslint-language-service": "^0.9.2",
"typescript": "^2.2.2"
},
"peerDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions src/after.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('after', () => {

@After(3)
fn() {
calls++;
calls++;
}
}

Expand All @@ -37,8 +37,8 @@ describe('after', () => {

expect(calls, 'multiple class').to.equal(4);

myClass.prop = 50
myClass.prop = 100
myClass.prop = 50;
myClass.prop = 100;

expect(myClass.props.length, 'setter length').to.equal(1);
expect(myClass.props[0], 'setter value').to.equal(100);
Expand Down
6 changes: 3 additions & 3 deletions src/after.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import { PostValueApplicator } from './applicators';
* The opposite of Before. This method creates a function that invokes once it's called n or more times.
* @param {number} n The number of calls before the function is invoked.
* @example
*
*
* class MyClass {
* @After(2)
* fn() {
* return 10;
* }
* }
*
*
* const myClass = new MyClass();
*
*
* myClass.fn(); // => undefined
* myClass.fn(); // => 10
*/
Expand Down
2 changes: 1 addition & 1 deletion src/afterAll.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('afterAll', () => {
class MyClass {
@AfterAll(3)
fn() {
calls++;
calls++;
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/afterAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ import { PostValueApplicator } from './applicators';
* This spans across all instances of the class instead of the instance.
* @param {number} n The number of calls before the function is invoked.
* @example
*
*
* class MyClass {
* @AfterAll(2)
* fn() {
* return 10;
* }
* }
*
*
* const myClass = new MyClass();
* const myClass2 = new MyClass();
*
*
* myClass.fn(); // => undefined
* myClass.fn(); // => 10
*
* myClass2.fn(); // => 10
* myClass2.fn(); // => 10
*/
export const AfterAll: (n: number) => LodashDecorator = DecoratorFactory.createDecorator(
new DecoratorConfig(after, new PostValueApplicator(), { setter: true })
);
export { AfterAll as afterAll };
export default AfterAll;
export default AfterAll;
2 changes: 1 addition & 1 deletion src/ary.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('ary', () => {
class MyClass {
@Ary(2)
fn(...args: any[]) {
expect(args.length).to.equal(2)
expect(args.length).to.equal(2);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/ary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import { ary } from 'lodash';
import { DecoratorConfig, DecoratorFactory, LodashMethodDecorator } from './factory';
import { PreValueApplicator } from './applicators';
/**
* Creates a function that invokes func, with up to n arguments, ignoring any additional arguments.
* Creates a function that invokes func, with up to n arguments, ignoring any additional arguments.
* @param {number} n The arity cap.
* @example
*
*
* class MyClass {
* @Ary(1)
* fn(...args) {
* return args;
* }
* }
*
*
* const myClass = new MyClass();
*
*
* myClass.fn(1, 2, 3, 4); // => [ 1 ]
*/
export const Ary: (n: number) => LodashMethodDecorator = DecoratorFactory.createDecorator(
new DecoratorConfig(ary, new PreValueApplicator())
);
export { Ary as ary };
export default Ary;
export default Ary;
12 changes: 6 additions & 6 deletions src/attempt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ import { attempt, partial } from 'lodash';
import { DecoratorConfig, DecoratorFactory, LodashMethodDecorator } from './factory';
import { PreValueApplicator } from './applicators';

const _attempt = (fn: Function) => partial(attempt, fn);
const attemptFn = (fn: () => void) => partial(attempt, fn);
/**
* Attempts to invoke func, returning either the result or the caught error object. Any additional arguments are provided to func when it's invoked.
* @param {...*} [args] The arguments to invoke func with.
* @example
*
*
* class MyClass {
* @Attempt()
* fn(value) {
* if (typeof value === 'number') {
* return value
* }
*
*
* throw new Error();
* }
* }
*
*
* const myClass = new MyClass();
*
*
* myClass.fn(10); // => 10;
* myClass.fn(null); // => Error
*/
export const Attempt: (...partials: any[]) => LodashMethodDecorator = DecoratorFactory.createDecorator(
new DecoratorConfig(_attempt, new PreValueApplicator())
new DecoratorConfig(attemptFn, new PreValueApplicator())
);
export { Attempt as attempt };
export default Attempt;
2 changes: 1 addition & 1 deletion src/before.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('before', () => {
class MyClass {
@Before(3)
fn() {
calls++;
calls++;
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/before.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ import { before } from 'lodash';
import { DecoratorConfig, DecoratorFactory, LodashDecorator } from './factory';
import { PostValueApplicator } from './applicators';
/**
* Creates a function that invokes func, with the this binding and arguments of the created function, while it's called less than n times.
* Creates a function that invokes func, with the this binding and arguments of the created function, while it's called less than n times.
* Subsequent calls to the created function return the result of the last func invocation.
* @param {number} n The number of calls at whichc func is no longer invoked.
* @example
*
*
* let calls = 0;
*
*
* class MyClass {
* @Before(3)
* fn() {
* calls++;
* }
* }
*
*
* const myClass = new MyClass();
*
*
* myClass.fn();
* myClass.fn();
* myClass.fn();
* myClass.fn();
*
*
* calls === 2; // => true
*/
export const Before: (n: number) => LodashDecorator = DecoratorFactory.createInstanceDecorator(
Expand Down
2 changes: 1 addition & 1 deletion src/beforeAll.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('beforeAll', () => {
class MyClass {
@BeforeAll(3)
fn() {
calls++;
calls++;
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/beforeAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@ import { before } from 'lodash';
import { DecoratorConfig, DecoratorFactory, LodashDecorator } from './factory';
import { PostValueApplicator } from './applicators';
/**
* Creates a function that invokes func, with the this binding and arguments of the created function, while it's called less than n times.
* Creates a function that invokes func, with the this binding and arguments of the created function, while it's called less than n times.
* Subsequent calls to the created function return the result of the last func invocation.
* @param {number} n The number of calls at whichc func is no longer invoked.
* @example
*
*
* let calls = 0;
*
*
* class MyClass {
* @BeforeAll(3)
* fn() {
* calls++;
* }
* }
*
*
* const myClass = new MyClass();
* const myClass2 = new MyClass();
*
*
* myClass.fn();
* myClass.fn();
* myClass.fn();
* myClass.fn();
*
* myClass2.fn();
*
*
* calls === 3; // => true
*/
export const BeforeAll: (n: number) => LodashDecorator = DecoratorFactory.createDecorator(
new DecoratorConfig(before, new PostValueApplicator(), { setter: true })
);
export { BeforeAll as beforeAll };
export default BeforeAll;
export default BeforeAll;
14 changes: 7 additions & 7 deletions src/bind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import { DecoratorConfig, DecoratorFactory, LodashMethodDecorator } from './fact
import { BindApplicator } from './applicators';
/**
* Creates a function that invokes func with the this binding of thisArg and partials prepended to the arguments it receives.
*
*
* The _.bind.placeholder value, which defaults to _ in monolithic builds, may be used as a placeholder for partially applied arguments.
*
* Note: Unlike native Function#bind, this method doesn't set the "length" property of bound functions.
* Note: Unlike native Function#bind, this method doesn't set the "length" property of bound functions.
* @param {...*} [partials] The argument to be partially applied.
* @example
*
*
* class MyClass {
* @Bind()
* bound() {
* return this;
* }
*
*
* unbound() {
* return this;
* }
* }
* }
*
*
* const myClass = new MyClass();
*
*
* myClass.bound.call(null); // => myClass {}
* myClass.unbound.call(null); // => null
*/
Expand Down
Loading

0 comments on commit a7b2f97

Please sign in to comment.