Skip to content

Commit

Permalink
👍 add linter, formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeliwo committed Jul 10, 2018
1 parent da7be95 commit c5e383a
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all",
"semi": false
}
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@
"bootstrap": "lerna bootstrap",
"test": "lerna run test",
"prepare": "lerna run prepare",
"clean": "rimraf packages/**/lib"
"clean": "rimraf packages/**/lib",
"lint": "tslint 'packages/**/src/**/*.ts{,x}'",
"format": "tslint --fix 'packages/**/src/**/*.ts{,x}'"
},
"dependencies": {},
"devDependencies": {
"@types/react": "^16.4.6",
"lerna": "^2.11.0",
"prettier": "^1.13.7",
"react": "^16.4.1",
"rimraf": "^2.6.2"
"rimraf": "^2.6.2",
"tslint": "^5.10.0",
"tslint-config-prettier": "^1.13.0",
"tslint-plugin-prettier": "^1.3.0",
"tslint-react": "^3.6.0"
},
"sideEffects": false,
"engines": {
Expand Down
27 changes: 15 additions & 12 deletions packages/smarthr-ui/src/helper/objectAssign.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const getTypeOf = (input: any):string => {
const getTypeOf = (input: any): string => {
if (input === null) {
return 'null'
} else if (typeof input === 'undefined') {
Expand All @@ -10,7 +10,7 @@ const getTypeOf = (input: any):string => {
return typeof input
}

const cloneValue = (value: any): Array<any> | {} => {
const cloneValue = (value: any): any[] | {} => {
if (getTypeOf(value) === 'object') {
return quickCloneObject(value)
} else if (getTypeOf(value) === 'array') {
Expand All @@ -20,7 +20,7 @@ const cloneValue = (value: any): Array<any> | {} => {
return value
}

const quickCloneArray = (input: Array<any>) => input.map(cloneValue)
const quickCloneArray = (input: any[]) => input.map(cloneValue)

const quickCloneObject = (input: any) => {
const output = {}
Expand All @@ -30,26 +30,28 @@ const quickCloneObject = (input: any) => {
continue
}

(output as any)[key] = cloneValue(input[key])
;(output as any)[key] = cloneValue(input[key])
}

return output
}

const executeDeepMerge = (target: {}, _objects: any[] = [], _options: any = {}) => {
const executeDeepMerge = (
target: {},
tmpObjects: any[] = [],
tmpOtions: any = {},
) => {
const options = {
arrayBehaviour: _options.arrayBehaviour || 'replace',
arrayBehaviour: tmpOtions.arrayBehaviour || 'replace',
}

const objects = _objects.map(object => object || {})
const objects = tmpObjects.map(object => object || {})
const output: any = target || {}

for (let oindex = 0; oindex < objects.length; oindex++) {
const object = objects[oindex]
for (const object of objects) {
const keys = Object.keys(object)

for (let kindex = 0; kindex < keys.length; kindex++) {
const key = keys[kindex]
for (const key of keys) {
const value = (object as any)[key]
const type = getTypeOf(value)
const existingValueType = getTypeOf(output[key])
Expand Down Expand Up @@ -85,6 +87,7 @@ const executeDeepMerge = (target: {}, _objects: any[] = [], _options: any = {})
return output
}

const objectAssign = (target: {}, ...objects: any[]) => executeDeepMerge(target, objects)
const objectAssign = (target: {}, ...objects: any[]) =>
executeDeepMerge(target, objects)

export default objectAssign
1 change: 0 additions & 1 deletion packages/smarthr-ui/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { default as Alert } from './components/Alert/'
export { default as Test } from './components/Test/'

15 changes: 15 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"defaultSeverity": "error",
"rulesDirectory": ["tslint-plugin-prettier"],
"extends": [
"tslint:recommended",
"tslint-config-prettier",
"tslint-react"
],
"rules": {
"prettier": true,
"ordered-imports": false,
"object-literal-sort-keys": false,
"interface-name": false
}
}
Loading

0 comments on commit c5e383a

Please sign in to comment.