From 9fb2b4f1945a32b84e9712fb3a3da35df718d00d Mon Sep 17 00:00:00 2001 From: Eric Mackrodt Date: Mon, 7 Jan 2019 14:55:46 +1100 Subject: [PATCH] Add tslint and prettier. --- .prettierrc | 5 + package.json | 10 +- .../src/__tests__/state-container.test.ts | 4 +- packages/core/src/__tests__/utils.test.ts | 34 +++---- packages/core/src/index.ts | 12 +-- packages/core/src/scoped-transformer.ts | 6 +- packages/core/src/staat.ts | 18 ++-- packages/core/src/time-travel.ts | 4 +- packages/core/src/types.ts | 4 +- packages/core/src/utils.ts | 24 ++--- .../src/calculator-state-definition.ts | 10 +- packages/example/src/calculator.tsx | 24 ++--- packages/example/src/index.tsx | 2 +- packages/example/src/state.ts | 4 +- packages/example/src/welcome-component.tsx | 6 +- .../example/src/welcome-state-definition.tsx | 2 +- packages/react/src/__tests__/react.test.tsx | 4 +- packages/react/src/connect.tsx | 4 +- packages/react/src/context.ts | 2 +- packages/react/src/index.tsx | 4 +- packages/react/src/provider.tsx | 2 +- packages/react/src/types.ts | 4 +- .../__tests__/time-travel-container.test.ts | 40 ++++---- .../src/__tests__/time-travel.test.ts | 4 +- packages/time-travel/src/index.ts | 26 ++--- .../time-travel/src/time-travel-container.ts | 8 +- tslint.json | 94 +++++++++++++++++++ yarn.lock | 76 ++++++++++++++- 28 files changed, 304 insertions(+), 133 deletions(-) create mode 100644 .prettierrc create mode 100644 tslint.json diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..e359dad --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "trailingComma": "all", + "singleQuote": true, + "jsxSingleQuote": true +} diff --git a/package.json b/package.json index 0358e13..2134fad 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,9 @@ "example": "yarn build && cd packages/example && yarn start", "bootstrap": "lerna bootstrap", "test": "jest --coverage", - "travis": "yarn test", - "coveralls": "yarn test && cat ./coverage/lcov.info | coveralls" + "lint": "tslint 'packages/**/*.{ts,tsx}' -c ./tslint.json -e \"**/node_modules/**\"", + "travis": "yarn lint && yarn test", + "coveralls": "yarn lint && yarn test && cat ./coverage/lcov.info | coveralls" }, "author": "", "license": "ISC", @@ -22,7 +23,12 @@ "coveralls": "^3.0.2", "jest": "^23.6.0", "lerna": "^3.8.5", + "prettier": "^1.15.3", "ts-jest": "^23.10.5", + "tslint": "^5.12.0", + "tslint-config-prettier": "^1.17.0", + "tslint-react": "^3.6.0", + "tslint-react-a11y": "^1.0.0", "typescript": "^3.2.2" }, "private": true, diff --git a/packages/core/src/__tests__/state-container.test.ts b/packages/core/src/__tests__/state-container.test.ts index 2e7d1c5..c2eeeb2 100644 --- a/packages/core/src/__tests__/state-container.test.ts +++ b/packages/core/src/__tests__/state-container.test.ts @@ -1,5 +1,5 @@ -describe("StateContainer", () => { - it("should test", () => { +describe('StateContainer', () => { + it('should test', () => { expect(true).toBe(true); }); }); diff --git a/packages/core/src/__tests__/utils.test.ts b/packages/core/src/__tests__/utils.test.ts index aef99f2..df72fed 100644 --- a/packages/core/src/__tests__/utils.test.ts +++ b/packages/core/src/__tests__/utils.test.ts @@ -1,39 +1,39 @@ -import { setScope } from "../utils"; +import { setScope } from '../utils'; -describe("utils", () => { - describe("setScope", () => { - it("should build correct object", () => { +describe('utils', () => { + describe('setScope', () => { + it('should build correct object', () => { const state = { level1: { - name: "Test" - } + name: 'Test', + }, }; - const result = setScope(state, { name: "Another" }, "level1"); + const result = setScope(state, { name: 'Another' }, 'level1'); expect(result).toEqual({ level1: { - name: "Another" - } + name: 'Another', + }, }); expect(result).not.toBe(state); }); - it("should build correct object with multiple levels", () => { + it('should build correct object with multiple levels', () => { const state = { level1: { level2: { - name: "Test" - } - } + name: 'Test', + }, + }, }; - const result = setScope(state, { name: "Another" }, "level1.level2"); + const result = setScope(state, { name: 'Another' }, 'level1.level2'); expect(result).toEqual({ level1: { level2: { - name: "Another" - } - } + name: 'Another', + }, + }, }); expect(result).not.toBe(state); }); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 7c07d50..813c68f 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,16 +1,16 @@ -import staat from "./staat"; -import { isPromise, getScope } from "./utils"; +import staat from './staat'; +import { isPromise, getScope } from './utils'; export { Transformers, Subscription, Staat, IType, - StateContainerType -} from "./types"; -export * from "./scoped-transformer"; + StateContainerType, +} from './types'; +export * from './scoped-transformer'; export const internals = { isPromise, - getScope + getScope, }; export default staat; diff --git a/packages/core/src/scoped-transformer.ts b/packages/core/src/scoped-transformer.ts index 38bf067..7e172ce 100644 --- a/packages/core/src/scoped-transformer.ts +++ b/packages/core/src/scoped-transformer.ts @@ -1,4 +1,4 @@ -import { isPromise, getScope, setScope } from "./utils"; +import { isPromise, getScope, setScope } from './utils'; export function scopedTransformer< TState extends Record, @@ -8,14 +8,14 @@ export function scopedTransformer< definition: ( currentScope: TScope, ...args: TArgs - ) => TScope | Promise + ) => TScope | Promise, ) { return function(currentState: TState, ...args: TArgs) { const s = getScope(currentState, scope); const result = definition(s, ...args); if (isPromise(result)) { return result.then(promiseResult => - setScope({ ...currentState }, promiseResult, scope) + setScope({ ...currentState }, promiseResult, scope), ); } return setScope({ ...currentState }, result, scope); diff --git a/packages/core/src/staat.ts b/packages/core/src/staat.ts index 04ed014..39d3bcb 100644 --- a/packages/core/src/staat.ts +++ b/packages/core/src/staat.ts @@ -8,34 +8,34 @@ function addTransformers< >( obj: Record, transformers: TTransformers, - container: StateContainer + container: StateContainer, ) { - return Object.keys(transformers).reduce((obj, key) => { + return Object.keys(transformers).reduce((acc, key) => { const current = transformers[key]; if (isTransformer(current)) { - obj[key] = function(...args: any[]) { + acc[key] = function(...args: any[]) { const state = container.getState(); const result = current(state, ...args); if (isPromise(result)) { - return result.then(state => container.setState(state)); + return result.then(s => container.setState(s)); } return container.setState(result); }; } else { - obj[key] = addTransformers({}, current, container); + acc[key] = addTransformers({}, current, container); } - return obj; + return acc; }, obj); } function initializeObject( - container: StateContainer + container: StateContainer, ): StateContainerType { const obj: Partial> = {}; Object.defineProperty(obj, 'currentState', { - get: () => container.getState() + get: () => container.getState(), }); obj.subscribe = container.subscribe.bind(container); obj.unsubscribe = container.unsubscribe.bind(container); @@ -44,7 +44,7 @@ function initializeObject( export default function staat( transformers: TTransformers, - initialState: TState + initialState: TState, ): Staat { const container = new StateContainer(initialState); const obj = initializeObject(container); diff --git a/packages/core/src/time-travel.ts b/packages/core/src/time-travel.ts index 5d47ae1..37a22ab 100644 --- a/packages/core/src/time-travel.ts +++ b/packages/core/src/time-travel.ts @@ -1,5 +1,5 @@ -import { applyChange, diff } from "deep-diff"; -import { StateContainer } from "./state-container"; +import { applyChange, diff } from 'deep-diff'; +import { StateContainer } from './state-container'; export class TimeTravelContainer extends StateContainer { private pastDiffs: deepDiff.IDiff[][]; diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 13e8714..95a9756 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -1,6 +1,4 @@ -export interface IType extends Function { - new (...args: any[]): T; -} +export type IType = new (...args: any[]) => T; export type Transformers = { [TKey in keyof TTransformers]: TTransformers[TKey] extends ( diff --git a/packages/core/src/utils.ts b/packages/core/src/utils.ts index 9f8dfb8..4bda8e5 100644 --- a/packages/core/src/utils.ts +++ b/packages/core/src/utils.ts @@ -1,24 +1,24 @@ -import { TransformerOrObject, TransformerSignature } from "./types"; +import { TransformerOrObject, TransformerSignature } from './types'; export function isPromise(obj: T | Promise): obj is Promise { return ( !!obj && - (typeof obj === "object" || typeof obj === "function") && - typeof (obj as Promise).then === "function" && - typeof (obj as Promise).catch === "function" + (typeof obj === 'object' || typeof obj === 'function') && + typeof (obj as Promise).then === 'function' && + typeof (obj as Promise).catch === 'function' ); } export function isTransformer( - input: TransformerOrObject + input: TransformerOrObject, ): input is TransformerSignature { - return typeof input === "function"; + return typeof input === 'function'; } export function setProperty>( state: TState, path: string[], - value: TScope + value: TScope, ): TState { const key = path.shift(); if (!key || !state[key!]) { @@ -42,15 +42,15 @@ export function setProperty>( export function setScope>( state: TState, scope: TScope, - path: string + path: string, ): TState { - const parts = path.split("."); + const parts = path.split('.'); return setProperty(state, parts, scope); } export function getProperty>( state: TState, - path: string[] + path: string[], ): TScope { const key = path.shift(); if (path.length === 0) { @@ -61,8 +61,8 @@ export function getProperty>( export function getScope, TScope>( state: TState, - path: string + path: string, ): TScope { - const parts = path.split("."); + const parts = path.split('.'); return getProperty(state, parts); } diff --git a/packages/example/src/calculator-state-definition.ts b/packages/example/src/calculator-state-definition.ts index e422347..fe2310e 100644 --- a/packages/example/src/calculator-state-definition.ts +++ b/packages/example/src/calculator-state-definition.ts @@ -4,23 +4,23 @@ import { CalculatorState, AppState } from './types'; const transformer = scopedTransformer('calculator'); export const initialState: CalculatorState = { - count: 0 + count: 0, }; export const add = transformer( (currentState: CalculatorState, val: number): CalculatorState => { return { ...currentState, - count: currentState.count + val + count: currentState.count + val, }; - } + }, ); export const subtract = transformer( (currentState: CalculatorState, val: number): CalculatorState => { return { ...currentState, - count: currentState.count - val + count: currentState.count - val, }; - } + }, ); diff --git a/packages/example/src/calculator.tsx b/packages/example/src/calculator.tsx index 6d198b2..4f9ebb5 100644 --- a/packages/example/src/calculator.tsx +++ b/packages/example/src/calculator.tsx @@ -1,5 +1,5 @@ -import * as React from "react"; -import { calculator, connect } from "./state"; +import * as React from 'react'; +import { calculator as calculatorTransformers, connect } from './state'; const Calculator: React.StatelessComponent = props => { return ( @@ -19,10 +19,10 @@ type StateProps = { }; type TransformerProps = { - add: typeof calculator.add; - subtract: typeof calculator.subtract; - undo: typeof calculator.undo; - redo: typeof calculator.redo; + add: typeof calculatorTransformers.add; + subtract: typeof calculatorTransformers.subtract; + undo: typeof calculatorTransformers.undo; + redo: typeof calculatorTransformers.redo; }; type OwnProps = {}; @@ -32,15 +32,15 @@ type CalculatorProps = TransformerProps & StateProps & OwnProps; export default connect( ({ calculator }) => { return { - count: calculator.count + count: calculator.count, }; }, () => { return { - add: calculator.add, - subtract: calculator.subtract, - undo: calculator.undo, - redo: calculator.redo + add: calculatorTransformers.add, + subtract: calculatorTransformers.subtract, + undo: calculatorTransformers.undo, + redo: calculatorTransformers.redo, }; - } + }, )(Calculator); diff --git a/packages/example/src/index.tsx b/packages/example/src/index.tsx index 0ef93b0..20b4a36 100644 --- a/packages/example/src/index.tsx +++ b/packages/example/src/index.tsx @@ -9,5 +9,5 @@ ReactDOM.render( , - document.getElementById('entry') + document.getElementById('entry'), ); diff --git a/packages/example/src/state.ts b/packages/example/src/state.ts index c82785f..e70a3b8 100644 --- a/packages/example/src/state.ts +++ b/packages/example/src/state.ts @@ -16,12 +16,12 @@ const { const initialState = { calculator: calcInitialState, - welcome: welcomeInitialState + welcome: welcomeInitialState, }; const transformers = { calculator: timeTravel(calcTransformers, 'calculator'), - welcome: welcomeTransformers + welcome: welcomeTransformers, }; export const appState = staat(transformers, initialState); diff --git a/packages/example/src/welcome-component.tsx b/packages/example/src/welcome-component.tsx index 00df065..972a33b 100644 --- a/packages/example/src/welcome-component.tsx +++ b/packages/example/src/welcome-component.tsx @@ -29,14 +29,14 @@ type WelcomeProps = StateProps & TrasformerProps & OwnProps; export default connect( state => { return { - name: state.welcome.name + name: state.welcome.name, }; }, () => { return { - setName: welcome.setName + setName: welcome.setName, // undo: welcome.undo.bind(welcomeState), // redo: welcomeState.redo.bind(welcomeState) }; - } + }, )(Welcome); diff --git a/packages/example/src/welcome-state-definition.tsx b/packages/example/src/welcome-state-definition.tsx index 0cf8332..b14371f 100644 --- a/packages/example/src/welcome-state-definition.tsx +++ b/packages/example/src/welcome-state-definition.tsx @@ -8,5 +8,5 @@ const transformer = scopedTransformer('welcome'); export const setName = transformer( (currentState: WelcomeState, name: string) => { return { ...currentState, name }; - } + }, ); diff --git a/packages/react/src/__tests__/react.test.tsx b/packages/react/src/__tests__/react.test.tsx index 121900a..dbf243d 100644 --- a/packages/react/src/__tests__/react.test.tsx +++ b/packages/react/src/__tests__/react.test.tsx @@ -1,5 +1,5 @@ -describe("React", () => { - it("should test", () => { +describe('React', () => { + it('should test', () => { expect(true).toBe(true); }); }); diff --git a/packages/react/src/connect.tsx b/packages/react/src/connect.tsx index 294da6f..1245d01 100644 --- a/packages/react/src/connect.tsx +++ b/packages/react/src/connect.tsx @@ -4,12 +4,12 @@ import { Consumer } from './context'; export default function makeConnect() { return function connect( mapStateToProps: (states: TState, ownProps: TOwnProps) => TStateProps, - mapTransformersToProps?: () => TTransformerProps + mapTransformersToProps?: () => TTransformerProps, ) { return ( WrappedComponent: React.ComponentType< TOwnProps & TTransformerProps & TStateProps - > + >, ): React.ComponentType => { return class StaatConnect extends React.Component { private getStateProps = (state: TState) => { diff --git a/packages/react/src/context.ts b/packages/react/src/context.ts index 8117478..0d0fcff 100644 --- a/packages/react/src/context.ts +++ b/packages/react/src/context.ts @@ -1,4 +1,4 @@ -import createReactContext from "create-react-context"; +import createReactContext from 'create-react-context'; const { Provider, Consumer } = createReactContext(null); diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx index d93fdd0..c23fab6 100644 --- a/packages/react/src/index.tsx +++ b/packages/react/src/index.tsx @@ -6,11 +6,11 @@ import makeProvider from './provider'; export * from 'staat'; function reactStaat( - staat: Staat + staat: Staat, ): ReactStaat { return { Provider: makeProvider(staat), - connect: makeConnect() + connect: makeConnect(), }; } diff --git a/packages/react/src/provider.tsx b/packages/react/src/provider.tsx index 67ba0b7..b720a53 100644 --- a/packages/react/src/provider.tsx +++ b/packages/react/src/provider.tsx @@ -3,7 +3,7 @@ import { Staat } from 'staat'; import { Provider } from './context'; export default function makeProvider( - staat: Staat + staat: Staat, ): React.ComponentType { return class StaatProvider extends React.Component { private _mounted: boolean; diff --git a/packages/react/src/types.ts b/packages/react/src/types.ts index 27b7eeb..339bc0a 100644 --- a/packages/react/src/types.ts +++ b/packages/react/src/types.ts @@ -6,10 +6,10 @@ export type ReactStaat = { Provider: React.ComponentType; connect( mapStateToProps: (state: TState, ownProps: TOwnProps) => TStateProps, - mapTransformersToProps?: () => TTransformerProps + mapTransformersToProps?: () => TTransformerProps, ): ( WrappedComponent: React.ComponentType< TOwnProps & TTransformerProps & TStateProps - > + >, ) => React.ComponentType; }; diff --git a/packages/time-travel/src/__tests__/time-travel-container.test.ts b/packages/time-travel/src/__tests__/time-travel-container.test.ts index 4c97a1d..cf4aba2 100644 --- a/packages/time-travel/src/__tests__/time-travel-container.test.ts +++ b/packages/time-travel/src/__tests__/time-travel-container.test.ts @@ -1,19 +1,19 @@ -import { TimeTravelContainer } from "../time-travel-container"; +import { TimeTravelContainer } from '../time-travel-container'; type TestState = { count: number; }; const state: TestState = { - count: 0 + count: 0, }; -describe("TimeTravelContainer", () => { - describe("setPresent", () => { - it("sets canUndo and canRedo", () => { +describe('TimeTravelContainer', () => { + describe('setPresent', () => { + it('sets canUndo and canRedo', () => { const sut = new TimeTravelContainer(); const result = sut.setPresent(state, { - count: 1 + count: 1, }); expect(result).toEqual({ count: 1 }); expect(sut.canUndo).toBe(true); @@ -21,24 +21,24 @@ describe("TimeTravelContainer", () => { }); }); - describe("undo", () => { + describe('undo', () => { let sut: TimeTravelContainer; let currentState: TestState; beforeEach(() => { sut = new TimeTravelContainer(); currentState = sut.setPresent(state, { - count: 1 + count: 1, }); currentState = sut.setPresent(currentState, { - count: 2 + count: 2, }); currentState = sut.setPresent(currentState, { - count: 3 + count: 3, }); }); - it("returns previous state", () => { + it('returns previous state', () => { currentState = sut.undo(currentState); expect(currentState).toEqual({ count: 2 }); currentState = sut.undo(currentState); @@ -47,7 +47,7 @@ describe("TimeTravelContainer", () => { expect(currentState).toEqual({ count: 0 }); }); - it("sets canUndo and canRedo", () => { + it('sets canUndo and canRedo', () => { expect(sut.canUndo).toBe(true); expect(sut.canRedo).toBe(false); currentState = sut.undo(currentState); @@ -61,7 +61,7 @@ describe("TimeTravelContainer", () => { expect(sut.canRedo).toBe(true); }); - it("returns the same state if cannot undo", () => { + it('returns the same state if cannot undo', () => { currentState = sut.undo(currentState); currentState = sut.undo(currentState); currentState = sut.undo(currentState); @@ -70,27 +70,27 @@ describe("TimeTravelContainer", () => { }); }); - describe("redo", () => { + describe('redo', () => { let sut: TimeTravelContainer; let currentState: TestState; beforeEach(() => { sut = new TimeTravelContainer(); currentState = sut.setPresent(state, { - count: 1 + count: 1, }); currentState = sut.setPresent(currentState, { - count: 2 + count: 2, }); currentState = sut.setPresent(currentState, { - count: 3 + count: 3, }); currentState = sut.undo(currentState); currentState = sut.undo(currentState); currentState = sut.undo(currentState); }); - it("returns next state", () => { + it('returns next state', () => { currentState = sut.redo(currentState); expect(currentState).toEqual({ count: 1 }); currentState = sut.redo(currentState); @@ -99,7 +99,7 @@ describe("TimeTravelContainer", () => { expect(currentState).toEqual({ count: 3 }); }); - it("sets canUndo and canRedo", () => { + it('sets canUndo and canRedo', () => { expect(sut.canUndo).toBe(false); expect(sut.canRedo).toBe(true); currentState = sut.redo(currentState); @@ -113,7 +113,7 @@ describe("TimeTravelContainer", () => { expect(sut.canRedo).toBe(false); }); - it("returns the same state if cannot redo", () => { + it('returns the same state if cannot redo', () => { currentState = sut.redo(currentState); currentState = sut.redo(currentState); currentState = sut.redo(currentState); diff --git a/packages/time-travel/src/__tests__/time-travel.test.ts b/packages/time-travel/src/__tests__/time-travel.test.ts index 258bde9..9bfac08 100644 --- a/packages/time-travel/src/__tests__/time-travel.test.ts +++ b/packages/time-travel/src/__tests__/time-travel.test.ts @@ -1,5 +1,5 @@ -describe("TimeTravel", () => { - it("does", () => { +describe('TimeTravel', () => { + it('does', () => { expect(true).toBe(true); }); }); diff --git a/packages/time-travel/src/index.ts b/packages/time-travel/src/index.ts index 5dfdc06..bbfc3c2 100644 --- a/packages/time-travel/src/index.ts +++ b/packages/time-travel/src/index.ts @@ -1,21 +1,21 @@ -import { internals, scopedTransformer } from "staat"; -import { TimeTravelContainer } from "./time-travel-container"; -import { TimeTravelTransformers, Transformer } from "./types"; +import { internals, scopedTransformer } from 'staat'; +import { TimeTravelContainer } from './time-travel-container'; +import { TimeTravelTransformers, Transformer } from './types'; -const getKeys = (obj: TObj): (keyof TObj)[] => - Object.keys(obj) as (keyof TObj)[]; +const getKeys = (obj: TObj): Array => + Object.keys(obj) as Array; function udpateHistory( currentState: TState, newState: TState, container: TimeTravelContainer, - scope?: string + scope?: string, ): TState { if (scope) { const newScope = internals.getScope(newState, scope); const currentScope = internals.getScope( currentState, - scope + scope, ); container.setPresent(currentScope, newScope); } else { @@ -28,13 +28,13 @@ function udpateHistory( function createTimeTravelTransformer( transformer: Transformer, container: TimeTravelContainer, - scope?: string + scope?: string, ) { return (currentState: TState, ...args: TArgs) => { const result = transformer(currentState, ...args); if (internals.isPromise(result)) { return result.then(state => - udpateHistory(currentState, state, container, scope) + udpateHistory(currentState, state, container, scope), ); } return udpateHistory(currentState, result, container, scope); @@ -59,7 +59,7 @@ export function timeTravelTransformers< >( transformers: TTransformers, container: TimeTravelContainer, - scope?: string + scope?: string, ): TimeTravelTransformers { const newTransformers: TimeTravelTransformers< TState, @@ -70,12 +70,12 @@ export function timeTravelTransformers< obj[key] = createTimeTravelTransformer( current, container, - scope + scope, ); return obj; }, - {} as Record> + {} as Record>, ) as TimeTravelTransformers; const scoped = scope ? scopedTransformer(scope) : undefined; @@ -95,7 +95,7 @@ export function timeTravel< TTransformers extends Record> >( transformers: TTransformers, - scope?: string + scope?: string, ): TimeTravelTransformers { const container = new TimeTravelContainer(); return timeTravelTransformers(transformers, container, scope); diff --git a/packages/time-travel/src/time-travel-container.ts b/packages/time-travel/src/time-travel-container.ts index 5aa11cb..543fef8 100644 --- a/packages/time-travel/src/time-travel-container.ts +++ b/packages/time-travel/src/time-travel-container.ts @@ -1,4 +1,4 @@ -import { applyChange, diff } from "deep-diff"; +import { applyChange, diff } from 'deep-diff'; export class TimeTravelContainer { private pastDiffs: deepDiff.IDiff[][]; @@ -14,7 +14,7 @@ export class TimeTravelContainer { const newDiffs = diff(current, state); return { newDiffs, - current + current, }; } @@ -44,7 +44,7 @@ export class TimeTravelContainer { this.futureDiffs = [newDiffs, ...this.futureDiffs]; return { ...state, - ...current + ...current, }; } @@ -58,7 +58,7 @@ export class TimeTravelContainer { this.pastDiffs = [...this.pastDiffs, newDiffs]; return { ...state, - ...current + ...current, }; } } diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..420e29f --- /dev/null +++ b/tslint.json @@ -0,0 +1,94 @@ +{ + "extends": [ + "tslint:latest", + "tslint-react", + "tslint-react-a11y", + "tslint-config-prettier" + ], + "defaultSeverity": "error", + "rules": { + "ban": { + "options": [ + ["_", "extend", "use object spread: { ...a, ...b }"], + ["_", "isNull", "use plain JS: == null"], + ["_", "isDefined", "use plain JS: != null"], + ["Object", "assign", "use object spread: { ...a, ...b }"], + ["Object", "getOwnPropertyNames", "use Object.keys()"], + ["describe", "only", "should not be committed to repo"], + ["it", "only", "should not be committed to repo"], + ["test", "only", "should not be committed to repo"] + ] + }, + "no-object-literal-type-assertion": false, + "ordered-imports": [ + true, + { + "import-sources-order": "any", + "named-imports-order": "any" + } + ], + "interface-over-type-literal": false, + "linebreak-style": { + "options": ["LF"] + }, + "quotemark": [true, "single"], + "jsx-boolean-value": ["never"], + "member-access": [true], + "no-console": { + "options": ["log", "time", "timeEnd", "trace"] + }, + "no-implicit-dependencies": false, + "no-invalid-this": { + "options": ["check-function-in-method"] + }, + "interface-name": false, + "max-classes-per-file": false, + "jsx-no-lambda": false, + "no-trailing-whitespace": true, + "only-arrow-functions": false, + "no-this-assignment": [ + true, + { + "allow-destructuring": true + } + ], + "no-unnecessary-callback-wrapper": false, + "no-unnecessary-initializer": true, + "object-literal-sort-keys": false, + "prefer-conditional-expression": false, + "variable-name": { + "options": [ + "allow-leading-underscore", + "allow-pascal-case", + "ban-keywords", + "check-format" + ] + }, + "member-ordering": [ + true, + "private-before-public", + "static-before-instance", + "variables-before-functions" + ], + "trailing-comma": [ + true, + { + "multiline": "always", + "singleline": "never", + "esSpecCompliant": true + } + ] + }, + "jsRules": { + "object-literal-sort-keys": false + }, + "linterOptions": { + "exclude": [ + "/**/packages/newrelic-webpack-plugin/embedded.js", + "/**/coverage/**/*", + "/**/*.json", + "/**/build/**/*" + ] + }, + "no-submodule-imports": [true] +} diff --git a/yarn.lock b/yarn.lock index 17dfa85..7128596 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1033,7 +1033,7 @@ aws4@^1.8.0: version "1.8.0" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f" -babel-code-frame@^6.26.0: +babel-code-frame@^6.22.0, babel-code-frame@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" dependencies: @@ -1399,7 +1399,7 @@ buffer@^4.3.0: ieee754 "^1.1.4" isarray "^1.0.0" -builtin-modules@^1.0.0: +builtin-modules@^1.0.0, builtin-modules@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f" @@ -1693,6 +1693,11 @@ commander@2.17.x, commander@~2.17.1: version "2.17.1" resolved "https://registry.yarnpkg.com/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf" +commander@^2.12.1: + version "2.19.0" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a" + integrity sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg== + commondir@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" @@ -5576,6 +5581,11 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" +prettier@^1.15.3: + version "1.15.3" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.15.3.tgz#1feaac5bdd181237b54dbe65d874e02a1472786a" + integrity sha512-gAU9AGAPMaKb3NNSUUuhhFAS7SCO4ALTN4nRIn6PJ075Qd28Yn2Ig2ahEJWdJwJmlEBTUfC7mMUSFy8MwsOCfg== + pretty-error@^2.0.2: version "2.1.1" resolved "https://registry.yarnpkg.com/pretty-error/-/pretty-error-2.1.1.tgz#5f4f87c8f91e5ae3f3ba87ab4cf5e03b1a17f1a3" @@ -6049,7 +6059,7 @@ resolve@1.1.7: version "1.1.7" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" -resolve@1.x: +resolve@1.x, resolve@^1.3.2: version "1.9.0" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.9.0.tgz#a14c6fdfa8f92a7df1d996cb7105fa744658ea06" dependencies: @@ -6851,10 +6861,68 @@ ts-loader@5.3.2: micromatch "^3.1.4" semver "^5.0.1" -tslib@^1.9.0: +tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0: version "1.9.3" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286" +tslint-config-prettier@^1.17.0: + version "1.17.0" + resolved "https://registry.yarnpkg.com/tslint-config-prettier/-/tslint-config-prettier-1.17.0.tgz#946ed6117f98f3659a65848279156d87628c33dc" + integrity sha512-NKWNkThwqE4Snn4Cm6SZB7lV5RMDDFsBwz6fWUkTxOKGjMx8ycOHnjIbhn7dZd5XmssW3CwqUjlANR6EhP9YQw== + +tslint-microsoft-contrib@^5.0.3: + version "5.2.1" + resolved "https://registry.yarnpkg.com/tslint-microsoft-contrib/-/tslint-microsoft-contrib-5.2.1.tgz#a6286839f800e2591d041ea2800c77487844ad81" + integrity sha512-PDYjvpo0gN9IfMULwKk0KpVOPMhU6cNoT9VwCOLeDl/QS8v8W2yspRpFFuUS7/c5EIH/n8ApMi8TxJAz1tfFUA== + dependencies: + tsutils "^2.27.2 <2.29.0" + +tslint-react-a11y@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/tslint-react-a11y/-/tslint-react-a11y-1.0.0.tgz#001a71747a25b8ccd3df240131d66aef02411fe8" + integrity sha512-F6BeD5OWkossIOcgdIbm6C/V+Y+EodpgSHy64QF2kpiem72SI4yZ8Z3G7dZQSle0nyKqWGYnAqXsnRpoqCpWGA== + dependencies: + tslint-microsoft-contrib "^5.0.3" + +tslint-react@^3.6.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/tslint-react/-/tslint-react-3.6.0.tgz#7f462c95c4a0afaae82507f06517ff02942196a1" + integrity sha512-AIv1QcsSnj7e9pFir6cJ6vIncTqxfqeFF3Lzh8SuuBljueYzEAtByuB6zMaD27BL0xhMEqsZ9s5eHuCONydjBw== + dependencies: + tsutils "^2.13.1" + +tslint@^5.12.0: + version "5.12.0" + resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.12.0.tgz#47f2dba291ed3d580752d109866fb640768fca36" + integrity sha512-CKEcH1MHUBhoV43SA/Jmy1l24HJJgI0eyLbBNSRyFlsQvb9v6Zdq+Nz2vEOH00nC5SUx4SneJ59PZUS/ARcokQ== + dependencies: + babel-code-frame "^6.22.0" + builtin-modules "^1.1.1" + chalk "^2.3.0" + commander "^2.12.1" + diff "^3.2.0" + glob "^7.1.1" + js-yaml "^3.7.0" + minimatch "^3.0.4" + resolve "^1.3.2" + semver "^5.3.0" + tslib "^1.8.0" + tsutils "^2.27.2" + +tsutils@^2.13.1, tsutils@^2.27.2: + version "2.29.0" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.29.0.tgz#32b488501467acbedd4b85498673a0812aca0b99" + integrity sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA== + dependencies: + tslib "^1.8.1" + +"tsutils@^2.27.2 <2.29.0": + version "2.28.0" + resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.28.0.tgz#6bd71e160828f9d019b6f4e844742228f85169a1" + integrity sha512-bh5nAtW0tuhvOJnx1GLRn5ScraRLICGyJV5wJhtRWOLsxW70Kk5tZtpK3O/hW6LDnqKS9mlUMPZj9fEMJ0gxqA== + dependencies: + tslib "^1.8.1" + tty-browserify@0.0.0: version "0.0.0" resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"