Skip to content

Commit 88a7fd7

Browse files
chore: adjust linter
1 parent 0088357 commit 88a7fd7

20 files changed

+708
-699
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
root = true
22

33
[{src,tests}/**.{ts,json,js}]
4-
end_of_line = crlf
4+
end_of_line = lf
55
charset = utf-8
66
trim_trailing_whitespace = true
77
insert_final_newline = true

.eslintrc.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
project: ['./tsconfig.eslint.json'],
5+
sourceType: 'module',
6+
},
7+
root: true,
8+
env: {
9+
jest: true,
10+
node: true,
11+
browser: true
12+
},
13+
plugins: ['@typescript-eslint/eslint-plugin'],
14+
extends: [
15+
'eslint:recommended',
16+
'plugin:@typescript-eslint/recommended',
17+
'plugin:prettier/recommended'
18+
],
19+
rules: {
20+
'semi': 'off',
21+
'@typescript-eslint/no-explicit-any': 'off',
22+
'no-multiple-empty-lines': ["error", { "max": 1, "maxEOF": 0 }]
23+
}
24+
}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ node_modules
22
yarn.lock
33
dist
44
dist-esm
5+
package-lock.json

.prettierrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
semi: false,
3+
trailingComma: "all",
4+
singleQuote: true,
5+
printWidth: 120,
6+
tabWidth: 2
7+
};

package.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"scripts": {
99
"test": "jest",
1010
"build": "tsc",
11-
"lint": "tslint src/**/*.ts tests/*.ts"
11+
"lint": "eslint '*/**/*.ts'"
1212
},
1313
"jest": {
1414
"transform": {
@@ -22,12 +22,14 @@
2222
},
2323
"devDependencies": {
2424
"@types/jest": "^25.2.1",
25+
"@typescript-eslint/eslint-plugin": "^5.16.0",
26+
"@typescript-eslint/parser": "^5.16.0",
27+
"eslint-config-prettier": "^8.5.0",
28+
"eslint-plugin-prettier": "^4.0.0",
2529
"jest": "^25.2.7",
30+
"prettier": "2.6.1",
2631
"ts-jest": "^25.3.1",
2732
"ts-node": "^8.8.2",
28-
"tslint": "^6.1.1",
29-
"tslint-config-prettier": "^1.18.0",
30-
"tslint-microsoft-contrib": "^6.2.0",
3133
"typescript": "^3.8.3"
3234
},
3335
"repository": {

src/Context.ts

+43-43
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
import Tranformer from './Transformer'
2-
import Options from './Options'
3-
import JsonApiResponse from './JsonApiResponse'
4-
5-
export default class Context {
6-
input: any = null;
7-
transformer: Tranformer = null;
8-
included: boolean = false;
9-
options: any = null;
10-
render: (c: Context) => JsonApiResponse;
11-
12-
constructor (render) {
13-
this.render = render;
14-
}
15-
16-
withInput (input) {
17-
this.input = input;
18-
19-
return this;
20-
}
21-
22-
withTransformer (transformer: Tranformer) {
23-
this.transformer = transformer;
24-
25-
return this;
26-
}
27-
28-
withIncluded (included) {
29-
this.included = included;
30-
31-
return this;
32-
}
33-
34-
withOptions (options: Options) {
35-
this.options = options
36-
37-
return this;
38-
}
39-
40-
serialize (): JsonApiResponse {
41-
return this.render(this);
42-
}
43-
}
1+
import Tranformer from './Transformer'
2+
import Options from './Options'
3+
import JsonApiResponse from './JsonApiResponse'
4+
5+
export default class Context {
6+
input: any = null
7+
transformer: Tranformer = null
8+
included = false
9+
options: any = null
10+
render: (c: Context) => JsonApiResponse
11+
12+
constructor(render) {
13+
this.render = render
14+
}
15+
16+
withInput(input) {
17+
this.input = input
18+
19+
return this
20+
}
21+
22+
withTransformer(transformer: Tranformer) {
23+
this.transformer = transformer
24+
25+
return this
26+
}
27+
28+
withIncluded(included) {
29+
this.included = included
30+
31+
return this
32+
}
33+
34+
withOptions(options: Options) {
35+
this.options = options
36+
37+
return this
38+
}
39+
40+
serialize(): JsonApiResponse {
41+
return this.render(this)
42+
}
43+
}

src/DefaultTransformer.ts

+32-32
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
import Transformer from './Transformer'
2-
import Options from './Options'
3-
4-
export default class DefaultTransformer extends Transformer {
5-
type: string = 'entities';
6-
7-
constructor (type, relationships = []) {
8-
super()
9-
this.type = type
10-
this.relationships = relationships || []
11-
12-
for (const rel of this.relationships) {
13-
this[rel] = (entity) => {
14-
return {
15-
input: entity[rel],
16-
transformer: new DefaultTransformer(rel),
17-
included: false
18-
}
19-
}
20-
}
21-
}
22-
23-
transform (entity: any, options: Options) {
24-
const attributes = { ... entity }
25-
26-
for (const rel of this.relationships) {
27-
delete attributes[rel]
28-
}
29-
30-
return attributes
31-
}
32-
}
1+
import Transformer from './Transformer'
2+
import Options from './Options'
3+
4+
export default class DefaultTransformer extends Transformer {
5+
type = 'entities'
6+
7+
constructor(type, relationships = []) {
8+
super()
9+
this.type = type
10+
this.relationships = relationships || []
11+
12+
for (const rel of this.relationships) {
13+
this[rel] = (entity) => {
14+
return {
15+
input: entity[rel],
16+
transformer: new DefaultTransformer(rel),
17+
included: false,
18+
}
19+
}
20+
}
21+
}
22+
23+
transform(entity: any, options: Options) {
24+
const attributes = { ...entity }
25+
26+
for (const rel of this.relationships) {
27+
delete attributes[rel]
28+
}
29+
30+
return attributes
31+
}
32+
}

src/JsonApiResponse.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
export default interface JsonApiResponse {
2-
data: any;
3-
meta?: any;
4-
included?: any[];
5-
}
1+
export default interface JsonApiResponse {
2+
data: any
3+
meta?: any
4+
included?: any[]
5+
}

src/Options.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export default interface Options {
2-
idKey?: string,
3-
fields?: any,
4-
changeCase?: string,
5-
6-
// custom properties
7-
[key: string]: any
8-
}
1+
export default interface Options {
2+
idKey?: string
3+
fields?: any
4+
changeCase?: string
5+
6+
// custom properties
7+
[key: string]: any
8+
}

src/Transformer.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import Options from './Options'
2-
3-
export default abstract class Transformer {
4-
type: string = 'entities';
5-
relationships: string[] = [];
6-
7-
abstract transform (entity: any, options: Options): any;
8-
}
1+
import Options from './Options'
2+
3+
export default abstract class Transformer {
4+
type = 'entities'
5+
relationships: string[] = []
6+
7+
abstract transform(entity: any, options: Options): any
8+
}

0 commit comments

Comments
 (0)